thoughtbot/fishery

onBuild function

davetapley opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

I use MobX-state-tree which has its own (synchronous) create function to lift a JS object in to a 'model', see here.

Describe the solution you'd like

An onBuild function in fishery which I could use to tell the factory about Mobx-state-tree's create function,
so I get back a Mobx-state-tree model and not a vanilla JS object.

Describe alternatives you've considered

My current workaround is to use factory to create object, then separately call create:

s1_ = precipSensorFactory.build({ site: "Test site"})
s1 = PrecipSensor.create(s1_)

Additional context

factory-girl has this:
https://github.com/simonexmachina/factory-girl#afterbuild-functionmodel-attrs-buildoptions

Hi, I'm not very familiar with Mobx but wanted to point you toward this comment and see if it helps with your needs. Basically, your factory can return a complex class; it doesn't have to be an object literal.

I'm going to close this for now, but if you're still facing an issue, feel free to open a new issue with a simplified, reproducible example of what you're trying to do that doesn't require knowledge of an external tool. That will help me assist more easily.