Git Product home page Git Product logo

Comments (5)

willryan avatar willryan commented on June 16, 2024 1

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.

willryan avatar willryan commented on June 16, 2024

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.

ahahn95 avatar ahahn95 commented on June 16, 2024

@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.

willryan avatar willryan commented on June 16, 2024

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.

dayinji avatar dayinji commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.