Skip to content
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

Improve inheritance model #12

Open
julien-f opened this issue Oct 9, 2018 · 2 comments
Open

Improve inheritance model #12

julien-f opened this issue Oct 9, 2018 · 2 comments

Comments

@julien-f
Copy link
Collaborator

julien-f commented Oct 9, 2018

Issue with current API:

  • implicit state/effects dependencies
  • a component placed between two components sharing state/effects will shadow them
  • cumbersome local use: provideState(injectState(Component))

I think we should consider departing completely from the implicit inheritance API and favor a local (with explicit inheritance) API.

@julien-f
Copy link
Collaborator Author

julien-f commented Oct 25, 2018

Maybe we should remove the ability to decorate any component, simply accept a render function:

const Parent = withStore(
  {
    initialState: () => ({ value: '' }),
    effects: {
      onChange: event => ({ value: event.target.value }),
    }
  },
  (store, props) => (
    <input onChange={store.effects.onChange} value={store.state.value} />
  )
)

const Child = Parent.injectStore(
  (parentStore, props) => (
    <div>{parentStore.state.value}</div>
  )
)

And provide a nice syntax to use multiple stores:

import App from '../../'
import Form from '../'

const MyComponent = App.injectStore(
  Form.injectStore(
    (formStore, appStore, props) => (
      <div />
    )
  )
)

@JsCommunity JsCommunity deleted a comment from GHEMID-Mohamed Oct 26, 2018
@julien-f julien-f mentioned this issue Oct 26, 2018
5 tasks
@JsCommunity JsCommunity deleted a comment from GHEMID-Mohamed Oct 26, 2018
@julien-f
Copy link
Collaborator Author

Maybe Reaclette should not provide inheritance and let users use React features like useContext().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant