Skip to content

Commit

Permalink
Merge pull request #96 from f/trigger_mixin
Browse files Browse the repository at this point in the history
fix some formatting and run the build
  • Loading branch information
darcyadams committed May 23, 2016
2 parents a86c138 + 0eaa9df commit 470bff8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
14 changes: 12 additions & 2 deletions dist/delorean.js
@@ -1,4 +1,4 @@
/*! delorean - v0.9.6-0 - 2015-08-24 */
/*! delorean - v0.9.8 - 2016-05-23 */
(function (DeLorean) {
'use strict';

Expand Down Expand Up @@ -99,7 +99,6 @@
DeLorean.EventEmitter.defaultMaxListeners = 50;
this.listener = new DeLorean.EventEmitter();
this.stores = stores;

/* Stores should be listened for rollback events. */
__rollbackListener(Object.keys(stores).map(function (key) {
return stores[key];
Expand Down Expand Up @@ -567,6 +566,17 @@

// ## Built-in React Mixin
DeLorean.Flux.mixins = {

// This mixin adds the this.trigger method to the component
// Components can then trigger actions in flux w/out watching stores and having their state
trigger: {
componentWillMount: function () {
this.__dispatcher = __findDispatcher(this);
},
trigger: function () {
this.__dispatcher.emit.apply(this.__dispatcher, arguments);
}
},
// It should be inserted to the React components which
// used in Flux.
// Simply `mixin: [Flux.mixins.storeListener]` will work.
Expand Down
2 changes: 1 addition & 1 deletion dist/delorean.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/delorean.min.js.map

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/delorean.js
Expand Up @@ -98,7 +98,6 @@
DeLorean.EventEmitter.defaultMaxListeners = 50;
this.listener = new DeLorean.EventEmitter();
this.stores = stores;

/* Stores should be listened for rollback events. */
__rollbackListener(Object.keys(stores).map(function (key) {
return stores[key];
Expand Down Expand Up @@ -570,17 +569,13 @@
// This mixin adds the this.trigger method to the component
// Components can then trigger actions in flux w/out watching stores and having their state
trigger: {

componentWillMount: function () {
this.__dispatcher = __findDispatcher(this);
},

trigger: function () {
this.__dispatcher.emit.apply(this.__dispatcher, arguments);
}

},

// It should be inserted to the React components which
// used in Flux.
// Simply `mixin: [Flux.mixins.storeListener]` will work.
Expand Down
12 changes: 4 additions & 8 deletions test/spec/core/fluxSpec.js
Expand Up @@ -95,22 +95,18 @@ describe('Flux', function () {
});

it('should cleanup unused events after firing an action handler', function () {
MyAppDispatcher.dispatch('noChange', 'someText')
MyAppDispatcher.dispatch('noChange', 'someText')
MyAppDispatcher.dispatch('noChange', 'someText')
MyAppDispatcher.dispatch('noChange', 'someText')

MyAppDispatcher.dispatch('noChange', 'someText');
MyAppDispatcher.dispatch('noChange', 'someText');
MyAppDispatcher.dispatch('noChange', 'someText');
MyAppDispatcher.dispatch('noChange', 'someText');
changeListenerCount = myStore.listener.listeners('change').length;
rollbackListenerCount = myStore.listener.listeners('rollback').length;

// Note that the 'cleanup_{actionName}' event has not fired yet and removed the last 2 events (change & rolback), so there will be one remaining of each event at this point.
// however, without the cleanup, there would be 4 of each after 4 calls
expect(changeListenerCount).toEqual(1);
expect(rollbackListenerCount).toEqual(1);

});


it('dispatcher can listen events', function () {
var spy = jasmine.createSpy('dispatcher listener');
MyAppDispatcher.on('hello', spy);
Expand Down

0 comments on commit 470bff8

Please sign in to comment.