hippodrome 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b5036e5c66a8704fd400c621f9c369e0ed3d4d4
4
- data.tar.gz: e5c3b2aabd0e7b4adefce19d8c1c8d84032e7393
3
+ metadata.gz: 2c68318dc3daa63974b6da46be215c8cb0deb986
4
+ data.tar.gz: faa05a1abd41d279f1dfce251c96c70a5808236d
5
5
  SHA512:
6
- metadata.gz: 45584434b782e936b87a02eaa2666d153a428afc9c578b087770f72055fa3e55635a426e3416eeabf53d5b7cfa3768c03dea8b097d624985e61e6881ee5cbeaf
7
- data.tar.gz: 38ae906af22d94d0a11311c297cfc051e4ed8b1d39e9bd38834c92a922f0ca40ae52f14e6de49859c45e539ebfedf8fda509ba452ffca6aea2e5658cfff7207d
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, Store, assert, bindToContextIfFunction, isNode, lastId, nextId, prefix, _,
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 = name;
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.hippoName = name;
61
+ actionFn.displayName = name;
62
+ actionFn.id = id;
50
63
  actionFn.toString = function() {
51
- return name;
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.callbacksByAction = {};
60
- this.isStarted = {};
61
- this.isFinished = {};
62
- this.isDispatching = false;
63
- return this.payload = null;
72
+ this._callbacksByAction = {};
73
+ this._isStarted = {};
74
+ this._isFinished = {};
75
+ this._isDispatching = false;
76
+ return this._payload = null;
64
77
  };
65
78
 
66
- prefix = 'Dispatcher_ID_';
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.callbacksByAction)[action] == null) {
88
+ if ((_base = this._callbacksByAction)[action] == null) {
82
89
  _base[action] = {};
83
90
  }
84
- id = nextId();
85
- this.callbacksByAction[action][id] = {
91
+ id = dispatcherIds.next();
92
+ this._callbacksByAction[action][id] = {
86
93
  callback: callback,
87
94
  prerequisites: _.map(prereqStores, function(ps) {
88
- return ps.storeImpl.dispatcherIdsByAction[action];
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.callbacksByAction[action][id], 'Dispatcher.unregister(%s, %s) does not map to a registered callback.', action, id);
97
- return this.callbacks[action][id] = null;
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.isDispatching, 'Dispatcher.waitFor must be invoked while dispatching.');
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.isStarted[id]) {
105
- assert(_this.isFinished[id], 'Dispatcher.waitFor encountered circular dependency while ' + 'waiting for `%s` during %s.', id, action);
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.callbacksByAction[action][id], 'Dispatcher.waitFor `%s` is not a registered callback for %s.', id, action);
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.isDispatching, 'Dispatch.dispatch cannot be called during dispatch.');
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.callbacksByAction[action], (function(_this) {
127
+ return _.forEach(this._callbacksByAction[action], (function(_this) {
121
128
  return function(callback, id) {
122
- if (_this.isStarted[id]) {
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.isStarted[id] = true;
136
- _ref = this.callbacksByAction[action][id], callback = _ref.callback, prerequisites = _ref.prerequisites;
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.payload);
139
- return this.isFinished[id] = true;
145
+ callback(this._payload);
146
+ return this._isFinished[id] = true;
140
147
  };
141
148
 
142
149
  Dispatcher.prototype.startDispatching = function(payload) {
143
- this.isStarted = {};
144
- this.isFinished = {};
145
- this.payload = payload;
146
- return this.isDispatching = true;
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.payload = null;
151
- return this.isDispatching = false;
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.hippoName, [], task);
166
- this.dispatcherIdsByAction = {};
167
- this.dispatcherIdsByAction[action.hippoName] = id;
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.storeImpl = {};
185
- this.storeImpl.dispatcherIdsByAction = {};
186
- this.storeImpl.callbacks = [];
187
- _.assign(this.storeImpl, _.omit(options, 'initialize', 'dispatches', 'public'), bindToContextIfFunction(this.storeImpl));
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.storeImpl));
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.storeImpl);
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.storeImpl.dispatcherIdsByAction[action.hippoName], 'Each store can only register one callback for each action.');
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.storeImpl[callback];
209
+ callback = _this._storeImpl[callback];
202
210
  }
203
- callback = callback.bind(_this.storeImpl);
204
- id = Hippodrome.Dispatcher.register(_this, action.hippoName, after, callback);
205
- return _this.storeImpl.dispatcherIdsByAction[action.hippoName] = id;
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.storeImpl.callbacks.push(callback);
221
+ return this._storeImpl.callbacks.push(callback);
214
222
  };
215
223
 
216
224
  Store.prototype.unregister = function(callback) {
217
- return this.storeImpl.callbacks = _.reject(this.storeImpl.callbacks, function(cb) {
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.storeImpl.callbacks, function(callback) {
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.18
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-24 00:00:00.000000000 Z
12
+ date: 2014-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler