blob: e7e13b37fd251fd1c6eb9f396a472129bb7ff5b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
import {
computed,
action,
observable,
} from 'mobx';
import localStorage from 'mobx-localstorage';
import { todoActions } from './actions';
import { FeatureStore } from '../utils/FeatureStore';
import { createReactions } from '../../stores/lib/Reaction';
import { createActionBindings } from '../utils/ActionBinding';
import { DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH } from '.';
const debug = require('debug')('Franz:feature:todos:store');
export default class TodoStore extends FeatureStore {
@observable isFeatureEnabled = false;
@observable isFeatureActive = false;
@computed get width() {
const width = this.settings.width || DEFAULT_TODOS_WIDTH;
return width < TODOS_MIN_WIDTH ? TODOS_MIN_WIDTH : width;
}
@computed get settings() {
return localStorage.getItem('todos') || {};
}
// ========== PUBLIC API ========= //
@action start(stores, actions) {
debug('TodoStore::start');
this.stores = stores;
this.actions = actions;
// ACTIONS
this._registerActions(createActionBindings([
[todoActions.resize, this._resize],
]));
// REACTIONS
this._allReactions = createReactions([
this._setFeatureEnabledReaction,
]);
this._registerReactions(this._allReactions);
this.isFeatureActive = true;
}
@action stop() {
super.stop();
debug('TodoStore::stop');
this.reset();
this.isFeatureActive = false;
}
// ========== PRIVATE METHODS ========= //
_updateSettings = (changes) => {
localStorage.setItem('todos', {
...this.settings,
...changes,
});
};
// Actions
@action _resize = ({ width }) => {
this._updateSettings({
width,
});
};
// Reactions
_setFeatureEnabledReaction = () => {
const { isTodosEnabled } = this.stores.features.features;
this.isFeatureEnabled = isTodosEnabled;
};
}
|