This RFC solves impossibility to combine @effector/reflect and effector-factorio, as well as adding protocol to integrate other dynamic bindings in a future
How does it look?
It looks like this:
import { reflect, take } from '@effector/reflect'
const SomeInput = reflect({
view: Input,
bind: {
value: take(something, key)
}
})
take returns the following structure:
{
/** Telling `reflect` how to extract the dynamic source of units */
useSource: props => something.useSource(props),
/** `key` that takes unit from source */
key: key
}
In effector-factorio we will add this alias:
factory.useSource = factory.useModel // Takes model instance from React.Context
And then we will be able to combine them:
const factory = modelFactory(() => {
return {
$value: createStore("")
}
})
const SomeInput = reflect({
view: Input,
bind: {
value: take(factory, "$value")
}
})
Also
- We should also support
(source, props) => key variant for key in order to support dynamic factories (they're not welcome but technically possible)
- We could also add
fromProps(key) === take({ useSource: props => props, key) shorthand that allows to take store from just props
Why this API? Why not bind: props => ({ ... })?
- No breaking changes
- We still statically get all non-dynamic bindings
- This API is not limited/specific for
effector-factorio only, it doesn't even have its mention
- Adds only 10 lines of code in
@effector/reflect and 1 alias in effector-factorio
This RFC solves impossibility to combine
@effector/reflectandeffector-factorio, as well as adding protocol to integrate other dynamic bindings in a futureHow does it look?
It looks like this:
takereturns the following structure:In
effector-factoriowe will add this alias:And then we will be able to combine them:
Also
(source, props) => keyvariant forkeyin order to support dynamic factories (they're not welcome but technically possible)fromProps(key) === take({ useSource: props => props, key)shorthand that allows to take store from just propsWhy this API? Why not
bind: props => ({ ... })?effector-factorioonly, it doesn't even have its mention@effector/reflectand 1 alias ineffector-factorio