diff options
author | 2019-03-01 14:25:44 +0100 | |
---|---|---|
committer | 2019-03-01 14:25:44 +0100 | |
commit | 739ef2e8a2dec94c3e10c3d26d797fe759fac7aa (patch) | |
tree | 4a2e066bf8627249f803eee16ba8e73268127fbd /src/actions/lib | |
parent | fixes merge conflicts with latest develop (diff) | |
download | ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.gz ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.zst ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.zip |
finish workspaces mvp
Diffstat (limited to 'src/actions/lib')
-rw-r--r-- | src/actions/lib/actions.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/actions/lib/actions.js b/src/actions/lib/actions.js index 499018d70..6571e9441 100644 --- a/src/actions/lib/actions.js +++ b/src/actions/lib/actions.js | |||
@@ -1,18 +1,23 @@ | |||
1 | export const createActionsFromDefinitions = (actionDefinitions, validate) => { | ||
2 | const actions = {}; | ||
3 | Object.keys(actionDefinitions).forEach((actionName) => { | ||
4 | const action = (params) => { | ||
5 | const schema = actionDefinitions[actionName]; | ||
6 | validate(schema, params, actionName); | ||
7 | action.notify(params); | ||
8 | }; | ||
9 | actions[actionName] = action; | ||
10 | action.listeners = []; | ||
11 | action.listen = listener => action.listeners.push(listener); | ||
12 | action.notify = params => action.listeners.forEach(listener => listener(params)); | ||
13 | }); | ||
14 | return actions; | ||
15 | }; | ||
16 | |||
1 | export default (definitions, validate) => { | 17 | export default (definitions, validate) => { |
2 | const newActions = {}; | 18 | const newActions = {}; |
3 | Object.keys(definitions).forEach((scopeName) => { | 19 | Object.keys(definitions).forEach((scopeName) => { |
4 | newActions[scopeName] = {}; | 20 | newActions[scopeName] = createActionsFromDefinitions(definitions[scopeName], validate); |
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 | }); | 21 | }); |
17 | return newActions; | 22 | return newActions; |
18 | }; | 23 | }; |