GithubHelp home page GithubHelp logo

reffects-store's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

reffects-store's Issues

Replace injectedProps by mapDispatchToProps

Since we use dipatch in most cases when we are using injectedProps, we have think that would be nice to replace injectedProprs with a function with dispatch as a parameter.

This would provide dipsatch function without importing it in the component and would be self-contained in a subscribed component.

This would be an easy to solve breaking change.

Example:

Now:

import { dispatch } from 'reffects-store':
...
subscribe(Component, (state) => { ... }, { onDoSomething: dispatch('EVENT_ID') });

Then:

subscribe(Component, (state) => { ... }, (dispatch) => { onDoSomething: dispatch('EVENT_ID') });

Avoid run all the subscription flow for components not passing mapStateToProps as argument

In some edge cases we are using subscribe function only to inject props, yet not for subscribing it to the state. In those cases we aren't passing by mapStateToProps.

Despite we consider it an anti-pattern, because we could simply compose the component in order to achieve that, it will be a improvement to not execute all the subscription flow if no mapStateToProps is passed by in the subscribe function.

Now we are passing by an empty fucntion:

subscribe(Component, () => {}, { myInjectedPropr: 'Hi there' });

This should allow to do this:

subscribe(Component, null, { myInjectedPropr: 'Hi there' }`);

Components subscription to state using hooks

Today we have one way to subscribe our React components suing the method subscribe() and it works good for us now.

This is not an issue to change the way we use subscribe, but it can be interesting to study another option to subscribe the React components taking advantage of React hooks (https://reactjs.org/docs/hooks-intro.html) and see if it fits to us.

It can provide a simpler and cleaner API to subscribe our components to the state. Example:

  • Current subscribe high order component:
function Component({ prop }) {
  return <span>{value}</span>
}

export default subscribe(Component, function(state) {
    return { prop: state.prop };
})
  • With useSubscribe hook:
export default function Component() {
  const prop = useSubscribe(state => state.prop /* or propSelector(state) */);
  return <span>{prop}</span>
}

* useSubscribe name is provisional just for the example

Resources:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.