salsita / prism

React / Redux action composition made simple http://salsita.github.io/prism/
496 stars 24 forks source link

Provide a wrapper compatible with the library-provided unwrapper #83

Open amakhrov opened 7 years ago

amakhrov commented 7 years ago

The library provides the standard unwrapper (https://github.com/salsita/prism/blob/master/packages/prism-redux/src/unwrappers/buildUnwrapper.ts). This unwrapper assumes a particular format of a wrapped action.

However, there is no standard wrapper compatible with this unwrapper. One has to write it themselves every time. And if the standard unwrapper changes in future versions, the existing code will break.

A possible approach would be to expose a standard action wrapper:

// buildWrapper.js - a part of the prism library
export default (prefix: string) => (action: string) => `${prefix}.${action}`;

// usage in a component
<InstantiableConnectedCounter
    selector={state => state.topCounter}
    wrapper=buildWrapper('TopCounter')
/>