hippodrome 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 978fbc039b45352d86b23dfe98e7625418cf316a
4
- data.tar.gz: 0939c65848ef70ef1d84cdb0c9bf5374d3459e6f
3
+ metadata.gz: 4bede62bfabff37412be8a2a77b34c462cf39129
4
+ data.tar.gz: 0851339e619a727f6dc56bbd7fb117445f52dd40
5
5
  SHA512:
6
- metadata.gz: 462d65c404dc55118ce3eb795fae3089327919177766edd9783142fbb7d1ce1a1dcf373022101f0d8db0ea75f829afc9e53036d713ba5f91e27fda12aac692b6
7
- data.tar.gz: 8297b6ce39ca69904bfc76e07c678a4c8f7a33f36b2780085d5fd347127c09b3cd713cf1d1b65d7aca8c455eb9b23e776f7ac453872bd139cc56c569bbea44b4
6
+ metadata.gz: 385c75fe65a11dce8e13075d9d15d5feebc894baab26c51869af3934ce8bc7fed2a5d7e888ca35d3bdbc008106779f1b75ad870948df52f440e0a44cbc17e77e
7
+ data.tar.gz: 888d384c1a98f3daad65e477fa2d89b833c8c0b6949d297b2ab46fda0283fc05f17ec36b15bb3b9e2554ebf22b54f3b66ea12c8401fc984ca623672e28b9cf2a
data/README.md CHANGED
@@ -13,11 +13,13 @@ Hippodrome is an implementation of Facebook's
13
13
  [Flux](http://facebook.github.io/flux/docs/overview.html)
14
14
  architecture. It adds some more structure (especially to Stores) to the ideas
15
15
  beyond what [Facebook's Flux](https://github.com/facebook/flux) has and
16
- includes Side Effects, objects that can respond to Actions (like Stores) but
16
+ includes Deferred Tasks, objects that can respond to Actions (like Stores) but
17
17
  instead of exposing data to views, do additional asynchronous work like
18
18
  making a network request and possibly dispatching more actions based on the
19
19
  response.
20
20
 
21
+ For a more in-depth explanation, [read this](./docs/hippodrome.md).
22
+
21
23
  ## Installation
22
24
 
23
25
  ### Rails
@@ -50,13 +52,27 @@ In your javascript manifest file:
50
52
 
51
53
  Hippodrome = require('hippodrome')
52
54
 
55
+ ## Contributing
53
56
 
54
- TODO: Explain how all the bits work.
57
+ The actual project code is in `src/`. `js/` and `app/` are where the compiled
58
+ assets go to get picked up by npm and bundler, respectively.
55
59
 
56
- ## Contributing
60
+ In order to build the code, install [node](http://nodejs.org/) and
61
+ [gulp](http://gulpjs.com/), install the dev dependencies with `npm install` and
62
+ then build with `gulp build`. This will deposit the compiled javascript to
63
+ `js/` and `app/assets/javascripts/` and build a .gem file in `pkg/`.
64
+
65
+ `test/hippodrome-test` is both a rails app and a node project that can run the
66
+ tests in
67
+ `test/hippodrome-test/specs/javascripts/hippodrome/hippodrome_spec.coffee`.
68
+
69
+ To run the tests under rails, first `gulp build` in the project root, then
70
+ `bundle` in the test project to install the gem, the either
71
+ `rake spec:javascript` to run the tests in the console or `rails s` to start a
72
+ WEBrick server and see the tests at
73
+ [http://localhost:3000/specs](http://localhost:300/specs).
57
74
 
58
- 1. Fork it ( http://github.com/structural/hippodrome/fork )
59
- 2. Create your feature branch (`git checkout -b my-new-feature`)
60
- 3. Commit your changes (`git commit -am 'Add some feature'`)
61
- 4. Push to the branch (`git push origin my-new-feature`)
62
- 5. Create new Pull Request
75
+ To run the tests under node, first `gulp build` in the project root, then
76
+ `npm install` in the test directory (you may need to `rm -r node_modules/*` if
77
+ you want to install the package again without bumping the version number), then
78
+ `npm run test`.
@@ -1,7 +1,7 @@
1
1
  //= require lodash
2
2
 
3
3
  (function() {
4
- var Action, DeferredTask, Dispatcher, Hippodrome, IdFactory, Store, actionIds, assert, bindToContextIfFunction, dispatcherIds, isNode, _,
4
+ var Action, DeferredTask, Dispatcher, Hippodrome, IdFactory, Store, actionIds, assert, bindToContextIfFunction, dispatcherIds, isNode, makeDeferredFunction, _,
5
5
  __slice = [].slice;
6
6
 
7
7
  isNode = typeof window === 'undefined';
@@ -160,18 +160,39 @@
160
160
 
161
161
  Hippodrome.Dispatcher = new Dispatcher();
162
162
 
163
+ makeDeferredFunction = function(context, fn) {
164
+ if (typeof fn === 'string') {
165
+ fn = context[fn];
166
+ }
167
+ fn = _.defer.bind(context, fn);
168
+ return fn;
169
+ };
170
+
163
171
  DeferredTask = function(options) {
164
172
  var action, id, task;
165
- assert(options.action, 'DeferredTask must register for exactly one action.');
166
- assert(options.task, 'DeferredTask must supply exactly one task to run');
167
- action = options.action, task = options.task;
168
- if (typeof task === 'string') {
169
- task = this[task];
170
- }
171
- task = _.defer.bind(this, task);
172
- id = Hippodrome.Dispatcher.register(this, action.id, [], task);
173
+ this.displayName = options.displayName;
174
+ assert(options.action || options.dispatches, "Deferred Task " + this.displayName + " must include either an action key or dispatches list.");
175
+ assert(!options.action || options.task, "Deferred Task " + this.displayName + " declared an action, it must declare a task.");
176
+ _.assign(this, _.omit(options, 'dispatches', 'action', 'task'), bindToContextIfFunction(this));
173
177
  this._dispatcherIdsByAction = {};
174
- this._dispatcherIdsByAction[action.id] = id;
178
+ if (options.action && options.task) {
179
+ action = options.action, task = options.task;
180
+ task = makeDeferredFunction(this, task);
181
+ id = Hippodrome.Dispatcher.register(this, action.id, [], task);
182
+ this._dispatcherIdsByAction[action.id] = id;
183
+ }
184
+ if (options.dispatches) {
185
+ _.forEach(options.dispatches, (function(_this) {
186
+ return function(dispatch) {
187
+ var callback;
188
+ action = dispatch.action, callback = dispatch.callback;
189
+ assert(!_this._dispatcherIdsByAction[action.id], "Deferred Task " + _this.displayName + " registered two callbacks for the action " + action.displayName + ".");
190
+ callback = makeDeferredFunction(_this, callback);
191
+ id = Hippodrome.Dispatcher.register(_this, action.id, [], callback);
192
+ return _this._dispatcherIdsByAction[action.id] = id;
193
+ };
194
+ })(this));
195
+ }
175
196
  return this;
176
197
  };
177
198
 
@@ -1,3 +1,3 @@
1
1
  //= require lodash
2
2
 
3
- (function(){var t,i,s,r,n,e,a,o,c,l,p,u,h=[].slice;p="undefined"==typeof window,u=p?require("lodash"):this._,r={},o=function(){var t,i,s,r,n;if(s=arguments[0],n=arguments[1],i=3<=arguments.length?h.call(arguments,2):[],!s)throw t=0,r=new Error("Assertion Failed: "+n.replace(/%s/g,function(){return i[t++]})),r.framesToPop=1,r;return s},n=function(t){return this._lastId=1,this._prefix=t},n.prototype.next=function(){return""+this._prefix+"_"+this._lastId++},a=new n("Action_ID"),t=function(t,i){var s,n,e,o;return e=""+a.next()+"_"+t,n=function(){var t;return t=i.apply(null,arguments),t.action=e,t},o=function(t){return r.Dispatcher.dispatch(t)},s=function(){var t;return t=n.apply(null,arguments),o(t)},s.buildPayload=n,s.send=o,s.displayName=t,s.id=e,s.toString=function(){return e},s},r.Action=t,s=function(){return this._callbacksByAction={},this._isStarted={},this._isFinished={},this._isDispatching=!1,this._payload=null},l=new n("Dispatcher_ID"),s.prototype.register=function(){var t,i,s,r,n,e,a;return i=u.compact(arguments),3===i.length?this.register(i[0],i[1],[],i[2]):(e=i[0],t=i[1],n=i[2],s=i[3],null==(a=this._callbacksByAction)[t]&&(a[t]={}),r=l.next(),this._callbacksByAction[t][r]={callback:s,prerequisites:u.map(n,function(i){return i._storeImpl.dispatcherIdsByAction[t]})},r)},s.prototype.unregister=function(t,i){return o(this._callbacksByAction[t][i],"Dispatcher.unregister(%s, %s) does not map to a registered callback.",t.displayName,i),this._callbacksByAction[t][i]=null},s.prototype.waitFor=function(t,i){return o(this._isDispatching,"Dispatcher.waitFor must be invoked while dispatching."),u.forEach(i,function(i){return function(s){return i._isStarted[s]?void o(i._isFinished[s],"Dispatcher.waitFor encountered circular dependency while waiting for `%s` during %s.",s,t.displayName):(o(i._callbacksByAction[t][s],"Dispatcher.waitFor `%s` is not a registered callback for %s.",s,t.displayName),i.invokeCallback(t,s))}}(this))},s.prototype.dispatch=function(t){var i;o(!this._isDispatching,"Dispatch.dispatch cannot be called during dispatch."),this.startDispatching(t);try{return i=t.action,u.forEach(this._callbacksByAction[i],function(t){return function(s,r){return t._isStarted[r]?void 0:t.invokeCallback(i,r)}}(this))}finally{this.stopDispatching()}},s.prototype.invokeCallback=function(t,i){var s,r,n;return this._isStarted[i]=!0,n=this._callbacksByAction[t][i],s=n.callback,r=n.prerequisites,this.waitFor(t,r),s(this._payload),this._isFinished[i]=!0},s.prototype.startDispatching=function(t){return this._isStarted={},this._isFinished={},this._payload=t,this._isDispatching=!0},s.prototype.stopDispatching=function(){return this._payload=null,this._isDispatching=!1},r.Dispatcher=new s,i=function(t){var i,s,n;return o(t.action,"DeferredTask must register for exactly one action."),o(t.task,"DeferredTask must supply exactly one task to run"),i=t.action,n=t.task,"string"==typeof n&&(n=this[n]),n=u.defer.bind(this,n),s=r.Dispatcher.register(this,i.id,[],n),this._dispatcherIdsByAction={},this._dispatcherIdsByAction[i.id]=s,this},r.DeferredTask=i,c=function(t){return function(i,s){return s instanceof Function?s.bind(t):s}},e=function(t){return this._storeImpl={trigger:function(){return u.each(this.callbacks,function(t){return t()})}},this._storeImpl.dispatcherIdsByAction={},this._storeImpl.callbacks=[],u.assign(this._storeImpl,u.omit(t,"initialize","dispatches","public"),c(this._storeImpl)),t["public"]&&(u.assign(this,t["public"],c(this._storeImpl)),u.assign(this._storeImpl,t["public"],c(this._storeImpl))),this.displayName=t.displayName,t.initialize&&t.initialize.call(this._storeImpl),t.dispatches&&u.forEach(t.dispatches,function(t){return function(i){var s,n,e,a;return s=i.action,n=i.after,e=i.callback,o(!t._storeImpl.dispatcherIdsByAction[s.id],"Store "+t.displayName+" registered two callbacks for action "+s.displayName),"string"==typeof e&&(e=t._storeImpl[e]),e=e.bind(t._storeImpl),a=r.Dispatcher.register(t,s.id,n,e),t._storeImpl.dispatcherIdsByAction[s.id]=a}}(this)),this},e.prototype.register=function(t){return this._storeImpl.callbacks.push(t)},e.prototype.unregister=function(t){return this._storeImpl.callbacks=u.reject(this._storeImpl.callbacks,function(i){return i===t})},e.prototype.listen=function(t){var i;return i=this,{componentDidMount:function(){return i.register(this[t])},componentWillUnmount:function(){return i.unregister(this[t])}}},e.prototype.trigger=function(){return this._storeImpl.trigger()},r.Store=e,p?module.exports=r:this.Hippodrome=r}).call(this);
3
+ (function(){var t,i,s,e,r,n,a,c,o,l,p,h,u,d=[].slice;p="undefined"==typeof window,u=p?require("lodash"):this._,e={},c=function(){var t,i,s,e,r;if(s=arguments[0],r=arguments[1],i=3<=arguments.length?d.call(arguments,2):[],!s)throw t=0,e=new Error("Assertion Failed: "+r.replace(/%s/g,function(){return i[t++]})),e.framesToPop=1,e;return s},r=function(t){return this._lastId=1,this._prefix=t},r.prototype.next=function(){return""+this._prefix+"_"+this._lastId++},a=new r("Action_ID"),t=function(t,i){var s,r,n,c;return n=""+a.next()+"_"+t,r=function(){var t;return t=i.apply(null,arguments),t.action=n,t},c=function(t){return e.Dispatcher.dispatch(t)},s=function(){var t;return t=r.apply(null,arguments),c(t)},s.buildPayload=r,s.send=c,s.displayName=t,s.id=n,s.toString=function(){return n},s},e.Action=t,s=function(){return this._callbacksByAction={},this._isStarted={},this._isFinished={},this._isDispatching=!1,this._payload=null},l=new r("Dispatcher_ID"),s.prototype.register=function(){var t,i,s,e,r,n,a;return i=u.compact(arguments),3===i.length?this.register(i[0],i[1],[],i[2]):(n=i[0],t=i[1],r=i[2],s=i[3],null==(a=this._callbacksByAction)[t]&&(a[t]={}),e=l.next(),this._callbacksByAction[t][e]={callback:s,prerequisites:u.map(r,function(i){return i._storeImpl.dispatcherIdsByAction[t]})},e)},s.prototype.unregister=function(t,i){return c(this._callbacksByAction[t][i],"Dispatcher.unregister(%s, %s) does not map to a registered callback.",t.displayName,i),this._callbacksByAction[t][i]=null},s.prototype.waitFor=function(t,i){return c(this._isDispatching,"Dispatcher.waitFor must be invoked while dispatching."),u.forEach(i,function(i){return function(s){return i._isStarted[s]?void c(i._isFinished[s],"Dispatcher.waitFor encountered circular dependency while waiting for `%s` during %s.",s,t.displayName):(c(i._callbacksByAction[t][s],"Dispatcher.waitFor `%s` is not a registered callback for %s.",s,t.displayName),i.invokeCallback(t,s))}}(this))},s.prototype.dispatch=function(t){var i;c(!this._isDispatching,"Dispatch.dispatch cannot be called during dispatch."),this.startDispatching(t);try{return i=t.action,u.forEach(this._callbacksByAction[i],function(t){return function(s,e){return t._isStarted[e]?void 0:t.invokeCallback(i,e)}}(this))}finally{this.stopDispatching()}},s.prototype.invokeCallback=function(t,i){var s,e,r;return this._isStarted[i]=!0,r=this._callbacksByAction[t][i],s=r.callback,e=r.prerequisites,this.waitFor(t,e),s(this._payload),this._isFinished[i]=!0},s.prototype.startDispatching=function(t){return this._isStarted={},this._isFinished={},this._payload=t,this._isDispatching=!0},s.prototype.stopDispatching=function(){return this._payload=null,this._isDispatching=!1},e.Dispatcher=new s,h=function(t,i){return"string"==typeof i&&(i=t[i]),i=u.defer.bind(t,i)},i=function(t){var i,s,r;return this.displayName=t.displayName,c(t.action||t.dispatches,"Deferred Task "+this.displayName+" must include either an action key or dispatches list."),c(!t.action||t.task,"Deferred Task "+this.displayName+" declared an action, it must declare a task."),u.assign(this,u.omit(t,"dispatches","action","task"),o(this)),this._dispatcherIdsByAction={},t.action&&t.task&&(i=t.action,r=t.task,r=h(this,r),s=e.Dispatcher.register(this,i.id,[],r),this._dispatcherIdsByAction[i.id]=s),t.dispatches&&u.forEach(t.dispatches,function(t){return function(r){var n;return i=r.action,n=r.callback,c(!t._dispatcherIdsByAction[i.id],"Deferred Task "+t.displayName+" registered two callbacks for the action "+i.displayName+"."),n=h(t,n),s=e.Dispatcher.register(t,i.id,[],n),t._dispatcherIdsByAction[i.id]=s}}(this)),this},e.DeferredTask=i,o=function(t){return function(i,s){return s instanceof Function?s.bind(t):s}},n=function(t){return this._storeImpl={trigger:function(){return u.each(this.callbacks,function(t){return t()})}},this._storeImpl.dispatcherIdsByAction={},this._storeImpl.callbacks=[],u.assign(this._storeImpl,u.omit(t,"initialize","dispatches","public"),o(this._storeImpl)),t["public"]&&(u.assign(this,t["public"],o(this._storeImpl)),u.assign(this._storeImpl,t["public"],o(this._storeImpl))),this.displayName=t.displayName,t.initialize&&t.initialize.call(this._storeImpl),t.dispatches&&u.forEach(t.dispatches,function(t){return function(i){var s,r,n,a;return s=i.action,r=i.after,n=i.callback,c(!t._storeImpl.dispatcherIdsByAction[s.id],"Store "+t.displayName+" registered two callbacks for action "+s.displayName),"string"==typeof n&&(n=t._storeImpl[n]),n=n.bind(t._storeImpl),a=e.Dispatcher.register(t,s.id,r,n),t._storeImpl.dispatcherIdsByAction[s.id]=a}}(this)),this},n.prototype.register=function(t){return this._storeImpl.callbacks.push(t)},n.prototype.unregister=function(t){return this._storeImpl.callbacks=u.reject(this._storeImpl.callbacks,function(i){return i===t})},n.prototype.listen=function(t){var i;return i=this,{componentDidMount:function(){return i.register(this[t])},componentWillUnmount:function(){return i.unregister(this[t])}}},n.prototype.trigger=function(){return this._storeImpl.trigger()},e.Store=n,p?module.exports=e:this.Hippodrome=e}).call(this);
@@ -1,3 +1,3 @@
1
1
  module Hippodrome
2
- VERSION = '0.0.24'
2
+ VERSION = '0.0.25'
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hippodrome",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Your data, like your chariots, go around and around in one direction in this, a Flux implementation that only Ben Hur could love.",
5
5
  "main": "js/hippodrome.js",
6
6
  "scripts": {
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.24
4
+ version: 0.0.25
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-26 00:00:00.000000000 Z
12
+ date: 2014-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler