Last active
March 14, 2019 10:45
-
-
Save arturovt/4ee172ca76b020ff2bbeeb624da16b4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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