Skip to content

Dynamic bind API #43

@Kelin2025

Description

@Kelin2025

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions