diff options
author | 2021-09-14 10:34:04 +0200 | |
---|---|---|
committer | 2021-09-14 10:34:04 +0200 | |
commit | 979ec02c9a1019152be08705986337e470eabb57 (patch) | |
tree | 6021179ad8649112717a499780f475275af487f2 /src/actions/lib | |
parent | refactor: defensive programming to avoid javascript error for unread badges (diff) | |
download | ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.gz ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.zst ferdium-app-979ec02c9a1019152be08705986337e470eabb57.zip |
chore: codebase improvements (#1930)
Diffstat (limited to 'src/actions/lib')
-rw-r--r-- | src/actions/lib/actions.ts (renamed from src/actions/lib/actions.js) | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/actions/lib/actions.js b/src/actions/lib/actions.ts index 7be40f1cf..ed42eabc0 100644 --- a/src/actions/lib/actions.js +++ b/src/actions/lib/actions.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | export const createActionsFromDefinitions = (actionDefinitions, validate) => { | 1 | export const createActionsFromDefinitions = (actionDefinitions, validate) => { |
2 | const actions = {}; | 2 | const actions = {}; |
3 | Object.keys(actionDefinitions).forEach((actionName) => { | 3 | Object.keys(actionDefinitions).forEach(actionName => { |
4 | const action = (params = {}) => { | 4 | const action = (params = {}) => { |
5 | const schema = actionDefinitions[actionName]; | 5 | const schema = actionDefinitions[actionName]; |
6 | validate(schema, params, actionName); | 6 | validate(schema, params, actionName); |
@@ -8,20 +8,24 @@ export const createActionsFromDefinitions = (actionDefinitions, validate) => { | |||
8 | }; | 8 | }; |
9 | actions[actionName] = action; | 9 | actions[actionName] = action; |
10 | action.listeners = []; | 10 | action.listeners = []; |
11 | action.listen = (listener) => action.listeners.push(listener); | 11 | action.listen = listener => action.listeners.push(listener); |
12 | action.off = (listener) => { | 12 | action.off = listener => { |
13 | const { listeners } = action; | 13 | const { listeners } = action; |
14 | listeners.splice(listeners.indexOf(listener), 1); | 14 | listeners.splice(listeners.indexOf(listener), 1); |
15 | }; | 15 | }; |
16 | action.notify = (params) => action.listeners.forEach((listener) => listener(params)); | 16 | action.notify = params => |
17 | action.listeners.forEach(listener => listener(params)); | ||
17 | }); | 18 | }); |
18 | return actions; | 19 | return actions; |
19 | }; | 20 | }; |
20 | 21 | ||
21 | export default (definitions, validate) => { | 22 | export default (definitions, validate) => { |
22 | const newActions = {}; | 23 | const newActions = {}; |
23 | Object.keys(definitions).forEach((scopeName) => { | 24 | Object.keys(definitions).forEach(scopeName => { |
24 | newActions[scopeName] = createActionsFromDefinitions(definitions[scopeName], validate); | 25 | newActions[scopeName] = createActionsFromDefinitions( |
26 | definitions[scopeName], | ||
27 | validate, | ||
28 | ); | ||
25 | }); | 29 | }); |
26 | return newActions; | 30 | return newActions; |
27 | }; | 31 | }; |