-
-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce faker.clone and derive #1499
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## next #1499 +/- ##
==========================================
- Coverage 99.57% 99.56% -0.01%
==========================================
Files 2807 2807
Lines 250526 250652 +126
Branches 1153 1161 +8
==========================================
+ Hits 249464 249574 +110
- Misses 1034 1078 +44
+ Partials 28 0 -28
|
9364008
Blocked by #2284 |
This would solve the problem of copycat: https://github.com/snaplet/copycat#the-problem |
I would recommend using a custom This will also (potentially) get much more easier with v9's independent methods that can be called just like this |
cb4992f
to
aefd4f0
Compare
aefd4f0
to
93dd407
Compare
Closing as obsolete |
Fixes #627
Required for:
See also:
This PR introduces two new methods for faker.
faker.clone()
faker.derive()
clone()
Can be used to generate repeated values or to allow generating the "last" value again.
This method does not consume seed values.
Example
last()
was originally requested in #627derive()
Can be used to write methods that don't affect the rest of the generated data when changed.
This method consumes a single seed value in order to initialize the seed of the derived instance.
Example
I evolved the
fork()
method intoderive()
while thinking about #1491 as it is incredible hard for our users to write extensible methods while retaining their original data. It basically makesgeneratePerson
or any similar method an atomic operation regardless how many data are generated.It can also be used to with nesting.
Alternatives
Add a
context
option toclone()
, that mutates the seed (current seed + context -> new seed).However, I think the consumption of a seed value is actually expected, so that partner/marriage certificate 1 and 2 are different.
Add a
seed
option toclone
and use it likefaker.fork({seed: faker.datatype.number()})
.However that would just be a a more verbose version of the current
derive
method.Food for thoughts: We could use the derive method in our code/methods to ensure each faker method call consumes only a single seed value. However this would probably (slightly) decrease performance.