Skip to content

Make falso instantiable #347

@slioxo

Description

@slioxo

Description

Picture this:

function createPerson() {
  seed('person-seed');
  return {
     name: randFullName(),
     company: createCompany(),
     job: randJobTitle()
  };
}

function createCompany() {
  seed('company-seed');
  return {
    name: randCompanyName(),
    city: randCity()
  };
}

In this example, randJobTitle() is called with company-seed instead of person-seed, because the createCompany() that's called before it has changed the seed globally.

Proposed solution

In such cases it would be great if we were able to instantiate falso, like so

function createPerson() {
  const falso = new Falso();
  falso.seed('person-seed');
  return {
     name: falso.randFullName(),
     company: createCompany(),
     job: falso.randJobTitle()
  };
}

function createCompany() {
  const falso = new Falso();
  falso.seed('company-seed');
  return {
    name: falso.randCompanyName(),
    city: falso.randCity()
  };
}

This would isolate and prevent unexpected side effects like in the example above, where changing the seed somewhere affects the whole application after it.

Alternatives considered

No response

Do you want to create a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions