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 +4 -4
- data/README.md +24 -8
- data/app/assets/javascripts/hippodrome.js +31 -10
- data/app/assets/javascripts/hippodrome.min.js +1 -1
- data/lib/hippodrome/version.rb +1 -1
- data/package.json +1 -1
- 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: 4bede62bfabff37412be8a2a77b34c462cf39129
|
4
|
+
data.tar.gz: 0851339e619a727f6dc56bbd7fb117445f52dd40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
166
|
-
assert(options.
|
167
|
-
action
|
168
|
-
|
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
|
-
|
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,
|
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);
|
data/lib/hippodrome/version.rb
CHANGED
data/package.json
CHANGED
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.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-
|
12
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|