hippodrome 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/hippodrome.js +65 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c68318dc3daa63974b6da46be215c8cb0deb986
|
4
|
+
data.tar.gz: faa05a1abd41d279f1dfce251c96c70a5808236d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e24c6a346401db5a0107e224f14246497962327bb12160ad7ae048dda8e0379ba9ac37db551021359663488f6f7c1d40a9f88310efe894f8d3afc903c6f5030
|
7
|
+
data.tar.gz: fc0d6bb27e559e9321e6c57e26cae414b1321c8201a9bcf910894f20bb45ba0fabeb3649251d3f95945e7a7ccc14a1e484a54d4e6fccf37d7224ed014af46822
|
@@ -1,7 +1,7 @@
|
|
1
1
|
//= require lodash
|
2
2
|
|
3
3
|
(function() {
|
4
|
-
var Action, DeferredTask, Dispatcher, Hippodrome,
|
4
|
+
var Action, DeferredTask, Dispatcher, Hippodrome, IdFactory, Store, actionIds, assert, bindToContextIfFunction, dispatcherIds, isNode, _,
|
5
5
|
__slice = [].slice;
|
6
6
|
|
7
7
|
isNode = typeof window === 'undefined';
|
@@ -28,12 +28,24 @@
|
|
28
28
|
return condition;
|
29
29
|
};
|
30
30
|
|
31
|
+
IdFactory = function(prefix) {
|
32
|
+
this._lastId = 1;
|
33
|
+
return this._prefix = prefix;
|
34
|
+
};
|
35
|
+
|
36
|
+
IdFactory.prototype.next = function() {
|
37
|
+
return "" + this._prefix + "_" + (this._lastId++);
|
38
|
+
};
|
39
|
+
|
40
|
+
actionIds = new IdFactory('Action_ID');
|
41
|
+
|
31
42
|
Action = function(name, ctor) {
|
32
|
-
var actionFn, buildPayload, send;
|
43
|
+
var actionFn, buildPayload, id, send;
|
44
|
+
id = "" + (actionIds.next()) + "_" + name;
|
33
45
|
buildPayload = function() {
|
34
46
|
var payload;
|
35
47
|
payload = ctor.apply(null, arguments);
|
36
|
-
payload.action =
|
48
|
+
payload.action = id;
|
37
49
|
return payload;
|
38
50
|
};
|
39
51
|
send = function(payload) {
|
@@ -46,9 +58,10 @@
|
|
46
58
|
};
|
47
59
|
actionFn.buildPayload = buildPayload;
|
48
60
|
actionFn.send = send;
|
49
|
-
actionFn.
|
61
|
+
actionFn.displayName = name;
|
62
|
+
actionFn.id = id;
|
50
63
|
actionFn.toString = function() {
|
51
|
-
return
|
64
|
+
return id;
|
52
65
|
};
|
53
66
|
return actionFn;
|
54
67
|
};
|
@@ -56,20 +69,14 @@
|
|
56
69
|
Hippodrome.Action = Action;
|
57
70
|
|
58
71
|
Dispatcher = function() {
|
59
|
-
this.
|
60
|
-
this.
|
61
|
-
this.
|
62
|
-
this.
|
63
|
-
return this.
|
72
|
+
this._callbacksByAction = {};
|
73
|
+
this._isStarted = {};
|
74
|
+
this._isFinished = {};
|
75
|
+
this._isDispatching = false;
|
76
|
+
return this._payload = null;
|
64
77
|
};
|
65
78
|
|
66
|
-
|
67
|
-
|
68
|
-
lastId = 1;
|
69
|
-
|
70
|
-
nextId = function() {
|
71
|
-
return prefix + lastId++;
|
72
|
-
};
|
79
|
+
dispatcherIds = new IdFactory('Dispatcher_ID');
|
73
80
|
|
74
81
|
Dispatcher.prototype.register = function() {
|
75
82
|
var action, args, callback, id, prereqStores, store, _base;
|
@@ -78,14 +85,14 @@
|
|
78
85
|
return this.register(args[0], args[1], [], args[2]);
|
79
86
|
} else {
|
80
87
|
store = args[0], action = args[1], prereqStores = args[2], callback = args[3];
|
81
|
-
if ((_base = this.
|
88
|
+
if ((_base = this._callbacksByAction)[action] == null) {
|
82
89
|
_base[action] = {};
|
83
90
|
}
|
84
|
-
id =
|
85
|
-
this.
|
91
|
+
id = dispatcherIds.next();
|
92
|
+
this._callbacksByAction[action][id] = {
|
86
93
|
callback: callback,
|
87
94
|
prerequisites: _.map(prereqStores, function(ps) {
|
88
|
-
return ps.
|
95
|
+
return ps._storeImpl.dispatcherIdsByAction[action];
|
89
96
|
})
|
90
97
|
};
|
91
98
|
return id;
|
@@ -93,19 +100,19 @@
|
|
93
100
|
};
|
94
101
|
|
95
102
|
Dispatcher.prototype.unregister = function(action, id) {
|
96
|
-
assert(this.
|
97
|
-
return this.
|
103
|
+
assert(this._callbacksByAction[action][id], 'Dispatcher.unregister(%s, %s) does not map to a registered callback.', action.displayName, id);
|
104
|
+
return this._callbacksByAction[action][id] = null;
|
98
105
|
};
|
99
106
|
|
100
107
|
Dispatcher.prototype.waitFor = function(action, ids) {
|
101
|
-
assert(this.
|
108
|
+
assert(this._isDispatching, 'Dispatcher.waitFor must be invoked while dispatching.');
|
102
109
|
return _.forEach(ids, (function(_this) {
|
103
110
|
return function(id) {
|
104
|
-
if (_this.
|
105
|
-
assert(_this.
|
111
|
+
if (_this._isStarted[id]) {
|
112
|
+
assert(_this._isFinished[id], 'Dispatcher.waitFor encountered circular dependency while ' + 'waiting for `%s` during %s.', id, action.displayName);
|
106
113
|
return;
|
107
114
|
}
|
108
|
-
assert(_this.
|
115
|
+
assert(_this._callbacksByAction[action][id], 'Dispatcher.waitFor `%s` is not a registered callback for %s.', id, action.displayName);
|
109
116
|
return _this.invokeCallback(action, id);
|
110
117
|
};
|
111
118
|
})(this));
|
@@ -113,13 +120,13 @@
|
|
113
120
|
|
114
121
|
Dispatcher.prototype.dispatch = function(payload) {
|
115
122
|
var action;
|
116
|
-
assert(!this.
|
123
|
+
assert(!this._isDispatching, 'Dispatch.dispatch cannot be called during dispatch.');
|
117
124
|
this.startDispatching(payload);
|
118
125
|
try {
|
119
126
|
action = payload.action;
|
120
|
-
return _.forEach(this.
|
127
|
+
return _.forEach(this._callbacksByAction[action], (function(_this) {
|
121
128
|
return function(callback, id) {
|
122
|
-
if (_this.
|
129
|
+
if (_this._isStarted[id]) {
|
123
130
|
return;
|
124
131
|
}
|
125
132
|
return _this.invokeCallback(action, id);
|
@@ -132,23 +139,23 @@
|
|
132
139
|
|
133
140
|
Dispatcher.prototype.invokeCallback = function(action, id) {
|
134
141
|
var callback, prerequisites, _ref;
|
135
|
-
this.
|
136
|
-
_ref = this.
|
142
|
+
this._isStarted[id] = true;
|
143
|
+
_ref = this._callbacksByAction[action][id], callback = _ref.callback, prerequisites = _ref.prerequisites;
|
137
144
|
this.waitFor(action, prerequisites);
|
138
|
-
callback(this.
|
139
|
-
return this.
|
145
|
+
callback(this._payload);
|
146
|
+
return this._isFinished[id] = true;
|
140
147
|
};
|
141
148
|
|
142
149
|
Dispatcher.prototype.startDispatching = function(payload) {
|
143
|
-
this.
|
144
|
-
this.
|
145
|
-
this.
|
146
|
-
return this.
|
150
|
+
this._isStarted = {};
|
151
|
+
this._isFinished = {};
|
152
|
+
this._payload = payload;
|
153
|
+
return this._isDispatching = true;
|
147
154
|
};
|
148
155
|
|
149
156
|
Dispatcher.prototype.stopDispatching = function() {
|
150
|
-
this.
|
151
|
-
return this.
|
157
|
+
this._payload = null;
|
158
|
+
return this._isDispatching = false;
|
152
159
|
};
|
153
160
|
|
154
161
|
Hippodrome.Dispatcher = new Dispatcher();
|
@@ -162,9 +169,9 @@
|
|
162
169
|
task = this[task];
|
163
170
|
}
|
164
171
|
task = _.defer.bind(this, task);
|
165
|
-
id = Hippodrome.Dispatcher.register(this, action.
|
166
|
-
this.
|
167
|
-
this.
|
172
|
+
id = Hippodrome.Dispatcher.register(this, action.id, [], task);
|
173
|
+
this._dispatcherIdsByAction = {};
|
174
|
+
this._dispatcherIdsByAction[action.id] = id;
|
168
175
|
return this;
|
169
176
|
};
|
170
177
|
|
@@ -181,28 +188,29 @@
|
|
181
188
|
};
|
182
189
|
|
183
190
|
Store = function(options) {
|
184
|
-
this.
|
185
|
-
this.
|
186
|
-
this.
|
187
|
-
_.assign(this.
|
191
|
+
this._storeImpl = {};
|
192
|
+
this._storeImpl.dispatcherIdsByAction = {};
|
193
|
+
this._storeImpl.callbacks = [];
|
194
|
+
_.assign(this._storeImpl, _.omit(options, 'initialize', 'dispatches', 'public'), bindToContextIfFunction(this._storeImpl));
|
188
195
|
if (options["public"]) {
|
189
|
-
_.assign(this, options["public"], bindToContextIfFunction(this.
|
196
|
+
_.assign(this, options["public"], bindToContextIfFunction(this._storeImpl));
|
190
197
|
}
|
198
|
+
this.displayName = options.displayName;
|
191
199
|
if (options.initialize) {
|
192
|
-
options.initialize.call(this.
|
200
|
+
options.initialize.call(this._storeImpl);
|
193
201
|
}
|
194
202
|
if (options.dispatches) {
|
195
203
|
_.forEach(options.dispatches, (function(_this) {
|
196
204
|
return function(dispatch) {
|
197
205
|
var action, after, callback, id;
|
198
206
|
action = dispatch.action, after = dispatch.after, callback = dispatch.callback;
|
199
|
-
assert(!_this.
|
207
|
+
assert(!_this._storeImpl.dispatcherIdsByAction[action.id], "Store " + _this.displayName + " registered two callbacks for action " + action.displayName);
|
200
208
|
if (typeof callback === 'string') {
|
201
|
-
callback = _this.
|
209
|
+
callback = _this._storeImpl[callback];
|
202
210
|
}
|
203
|
-
callback = callback.bind(_this.
|
204
|
-
id = Hippodrome.Dispatcher.register(_this, action.
|
205
|
-
return _this.
|
211
|
+
callback = callback.bind(_this._storeImpl);
|
212
|
+
id = Hippodrome.Dispatcher.register(_this, action.id, after, callback);
|
213
|
+
return _this._storeImpl.dispatcherIdsByAction[action.id] = id;
|
206
214
|
};
|
207
215
|
})(this));
|
208
216
|
}
|
@@ -210,11 +218,11 @@
|
|
210
218
|
};
|
211
219
|
|
212
220
|
Store.prototype.register = function(callback) {
|
213
|
-
return this.
|
221
|
+
return this._storeImpl.callbacks.push(callback);
|
214
222
|
};
|
215
223
|
|
216
224
|
Store.prototype.unregister = function(callback) {
|
217
|
-
return this.
|
225
|
+
return this._storeImpl.callbacks = _.reject(this._storeImpl.callbacks, function(cb) {
|
218
226
|
return cb === callback;
|
219
227
|
});
|
220
228
|
};
|
@@ -233,7 +241,7 @@
|
|
233
241
|
};
|
234
242
|
|
235
243
|
Store.prototype.trigger = function() {
|
236
|
-
return _.forEach(this.
|
244
|
+
return _.forEach(this._storeImpl.callbacks, function(callback) {
|
237
245
|
return callback();
|
238
246
|
});
|
239
247
|
};
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hippodrome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Kermes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|