Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active March 14, 2019 10:45
Show Gist options
  • Save arturovt/4ee172ca76b020ff2bbeeb624da16b4f to your computer and use it in GitHub Desktop.
Save arturovt/4ee172ca76b020ff2bbeeb624da16b4f to your computer and use it in GitHub Desktop.
function Action(actions, options) {
return function(target, name, descriptor) {
const meta = ensureStoreMetadata(target.constructor);
if (!Array.isArray(actions)) {
actions = [actions];
}
for (const action of actions) {
const type = action.type;
if (!action.type) {
throw new Error(
`Action ${action.name} is missing a static "type" property`
);
}
if (!meta.actions[type]) {
meta.actions[type] = [];
}
meta.actions[type].push({
fn: name,
options: options || {},
type
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment