Comments (5)
ok, yeah, that needs to look like:
const testFactory = Factory.makeFactory<myInterface>({
randNumber: Sync.each(() => faker.random.number())
})
const results = testFactory.buildList(5);
Without the each()
call (imported from the same place as Factory
), the value will not be generated on each invocation of build(). each()
returns a special Generator object that factory.ts knows means it has to run on each invocation. If a factory is constructed with a value that is not a generator, it just returns that value each time (unless overridden by build()
).
from factory.ts.
can you show me how myFactory
is defined? I ran a quick test and buildList generates a new value each time for me.
Without seeing your code for the factory, my first inclination would be to make sure you are using Sync.each(n => generateValue())
and not just generateValue()
, and if you are then to figure out if you want/need to use the sequence number to affect the output value.
from factory.ts.
@willryan My factory looks something like this (doesn't match the above example, but you get the idea)
const testFactory = Factory.makeFactory<myInterface>({
randNumber: faker.random.number()
})
const results = testFactory.buildList(5);
from factory.ts.
on a semi-related note, the callback argument for Sync.each() provides a sequence number which you can use to adjust the output if you want. This can allow for seemingly-random-but-predictable sequences, if need be.
from factory.ts.
on a semi-related note, the callback argument for Sync.each() provides a sequence number which you can use to adjust the output if you want. This can allow for seemingly-random-but-predictable sequences, if need be.
I encounter this question, and when I use each() function, a new question was triggered by typescript, which said 'Type 'Generator' is not assignable to type 'number'.'.
How can I deal with it ? Thanks
from factory.ts.
Related Issues (20)
- Getting type error with typescript 3.4.1 (and later) using combine HOT 4
- [Feature request]: makeFactory accepts function parameter HOT 3
- [feature proposal] Allow to specify factory as field default value of another factory HOT 1
- Use value from another field HOT 5
- Current state of the library HOT 2
- Node version bump causes install to fail HOT 2
- Can't use Factory.each to custimize value of build HOT 1
- Derivation using the existing value HOT 2
- Feature request: `create` and `createList`
- Feature request: `resetAllSequenceNumbers`
- Feature request: pass to makeFactory function that returns Builder instead object Builder HOT 1
- This repo does not seem maintained anymore HOT 2
- Combine factories with optional field HOT 3
- Pipelines as generators HOT 1
- Question: How to create a factory outputs tuples? HOT 1
- Failed to parse source maps HOT 1
- How to randomise nested object key in `buildList` HOT 1
- Default merging of objects within factories?
- Possible to allow "transient" values? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factory.ts.