diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 15:51:57 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 15:52:55 +0200 |
commit | 76bf7b840ea7d607a21b0294d10be01b26ad0607 (patch) | |
tree | 05b15350fa8cf00972ae8caab812868b9fa9dfe0 /src/features/utils/ActionBinding.js | |
parent | align announcement and spotlight (diff) | |
download | ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.gz ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.zst ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.zip |
merge-in latest develop
Diffstat (limited to 'src/features/utils/ActionBinding.js')
-rw-r--r-- | src/features/utils/ActionBinding.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/features/utils/ActionBinding.js b/src/features/utils/ActionBinding.js new file mode 100644 index 000000000..497aa071b --- /dev/null +++ b/src/features/utils/ActionBinding.js | |||
@@ -0,0 +1,29 @@ | |||
1 | export default class ActionBinding { | ||
2 | action; | ||
3 | |||
4 | isActive = false; | ||
5 | |||
6 | constructor(action) { | ||
7 | this.action = action; | ||
8 | } | ||
9 | |||
10 | start() { | ||
11 | if (!this.isActive) { | ||
12 | const { action } = this; | ||
13 | action[0].listen(action[1]); | ||
14 | this.isActive = true; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | stop() { | ||
19 | if (this.isActive) { | ||
20 | const { action } = this; | ||
21 | action[0].off(action[1]); | ||
22 | this.isActive = false; | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||
27 | export const createActionBindings = actions => ( | ||
28 | actions.map(a => new ActionBinding(a)) | ||
29 | ); | ||