diff options
author | 2017-10-13 12:29:40 +0200 | |
---|---|---|
committer | 2017-10-13 12:29:40 +0200 | |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/actions/lib | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/actions/lib')
-rw-r--r-- | src/actions/lib/actions.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/actions/lib/actions.js b/src/actions/lib/actions.js new file mode 100644 index 000000000..499018d70 --- /dev/null +++ b/src/actions/lib/actions.js | |||
@@ -0,0 +1,18 @@ | |||
1 | export default (definitions, validate) => { | ||
2 | const newActions = {}; | ||
3 | Object.keys(definitions).forEach((scopeName) => { | ||
4 | newActions[scopeName] = {}; | ||
5 | Object.keys(definitions[scopeName]).forEach((actionName) => { | ||
6 | const action = (params) => { | ||
7 | const schema = definitions[scopeName][actionName]; | ||
8 | validate(schema, params, actionName); | ||
9 | action.notify(params); | ||
10 | }; | ||
11 | newActions[scopeName][actionName] = action; | ||
12 | action.listeners = []; | ||
13 | action.listen = listener => action.listeners.push(listener); | ||
14 | action.notify = params => action.listeners.forEach(listener => listener(params)); | ||
15 | }); | ||
16 | }); | ||
17 | return newActions; | ||
18 | }; | ||