Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    William C. Johnson
    @wcjohnson
    Hello, @ me with any questions.
    Martin Bayly
    @mdgbayly_twitter
    Thinking about dipping my toes into redux components to refactor a project where our redux state is currently very messy. Your docs look good but wondering if you have any simple example applications built using redux components.
    Martin Bayly
    @mdgbayly_twitter

    @wcjohnson did some initial playing around with redux-components using the redux todos example. I converted the todos reducer/actions into a redux component. Took me a little while to get my head around the difference between the todos component and the todos state. I believe I'm right in saying that you need to come up with a way to pass the redux component to interested things in the view code because it's no longer sufficient to just import actions. You need to call the actions methods on the associated component. So for my experiment I passed the redux component in as a prop to the App and the App component passed it on to the AddTodo and the VisibleTodoList. Does that sound like the right approach?

    I guess maybe when you fully embrace the component model, your connected view components stop interacting with the redux store state object directly, and instead get all the state from the redux components they interact with?

    William C. Johnson
    @wcjohnson
    @mdgbayly_twitter Yes, correct. Instead of receiving the whole redux state object, your view components receive references to the components they're interested in. In my own code, state tends to be made out of singletons (that are composed into a tree by createComponent) and the singletons can be separately required by the views that need them.
    This has a number of advantages: for instance, if you decide to change the shape or structure of your state, your view code is much less brittle
    Redux-components does provide one internal mechanism for assisting in binding to non-state application code: https://wcjohnson.github.io/redux-components/docs/#observable-selectors
    so in your redux component, you'd write a selector that plucks what your view needs to render, then in your view, you'd observe the Observable resulting form that selector
    I actually have a bunch of code that uses this technique, but at the moment it's considered proprietary by my company. You're definitely right to ask for more examples, it's a weak area right now
    William C. Johnson
    @wcjohnson
    I primarily use recompose to build React components, and I have a higher order helper function withReduxComponents that basically takes an object describing the binding you want with state code and makes it happen. I will ask the higher ups about open sourcing it this week, I'm fairly sure they will allow it