Skip to content

Instantly share code, notes, and snippets.

@stenin-nikita
Last active April 1, 2020 18:51
Show Gist options
  • Save stenin-nikita/2d34d1ba8518dce73bca04d7be71197e to your computer and use it in GitHub Desktop.
Save stenin-nikita/2d34d1ba8518dce73bca04d7be71197e to your computer and use it in GitHub Desktop.
const EFFECT = Symbol('@@Reatom/EFFECT');
function createActionCreatorWithEffect(type, effect) {
return (payload) => ({
type,
payload,
[EFFECT]: (store) => effect(payload, store),
})
}
store.subscribe(action => {
if (typeof action[EFFECT] === 'function') {
action[EFFECT](store);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment