-
-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
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
MarioJuniorPro, gerardolima, LucasRodrigues, shabbyrobe, dilame and 1 more
Metadata
Metadata
Assignees
Labels
No labels