-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstate-manager.js
34 lines (30 loc) · 894 Bytes
/
state-manager.js
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
var StateManager = function (options) {
this.channelGrid = options.channelGrid;
this.stateRefs = options.stateRefs;
};
StateManager.prototype.create = function (state) {
var stateCellIndex = this.channelGrid.getCellIndex(state);
var stateRef = {
id: state.id,
tcid: stateCellIndex, // Target cell index.
type: state.type,
create: state
};
if (state.swid != null) {
stateRef.swid = state.swid;
}
this.stateRefs[state.id] = stateRef;
return stateRef;
};
// You can only update through operations which must be interpreted
// by your cell controllers (cell.js).
StateManager.prototype.update = function (stateRef, operation) {
var ref = this.stateRefs[stateRef.id];
if (ref) {
ref.op = operation;
}
};
StateManager.prototype.delete = function (stateRef) {
this.stateRefs[stateRef.id].delete = 1;
};
module.exports.StateManager = StateManager;