effector / effector/reflect

Dynamic `bind` API

Open
#43 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
90
Forks
12
PR merge metrics
No merged PRs in 30d

Description

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:
```tsx
import { reflect, take } from '@effector/reflect'

const SomeInput = reflect({
view: Input,
bind: {
value: take(something, key)
}
})
```
`take` returns the following structure:
```tsx
{
/** 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:
```tsx
factory.useSource = factory.useModel // Takes model instance from React.Context
```

And then we will be able to combine them:

```tsx
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`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.