developit / unistore

🌶 350b / 650b state container with component actions for Preact & React
https://npm.im/unistore
2.86k stars 139 forks source link

Questions about this lib #168

Closed vko-online closed 5 years ago

vko-online commented 5 years ago

Isn't this library coupling logic with component? (Which we try to avoid, and use redux) Also its not testable? (As actions are reducers, which are coupled to component)

krzepah commented 5 years ago

Hello, You can write your actions and your components separately and use connect to do the coupling,

import { connect } from 'unistore/preact';

const YourBaseElement = ({ storeparams, yourAction }) => <div>...</div>

const YourElement = connect(
  (state) => ({
    // you can deconstruct what parameters are passed to your element
    // or just pass state to do the deconstruction in the component prototype
  }),
  (state, props) => ({
    yourAction: yourActionFunc
  })
)(YourBaseElement);

You can then test your action as any functions,

I hope I've properly answered to your question :)