diff --git a/src/createAction.js b/src/createAction.js index 675f5ff..326ebf2 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -1,5 +1,6 @@ var _ = require('./utils'), - Reflux = require('../src'); + Reflux = require('../src'), + keep = require('./keep'); /** * Creates an action functor object @@ -22,6 +23,8 @@ module.exports = function(definition) { _.extend(functor,context); + keep.createdActions.push(functor); + return functor; }; diff --git a/src/createStore.js b/src/createStore.js index ec7c99d..028fa7a 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -1,5 +1,6 @@ var _ = require('./utils'), - Reflux = require('../src'); + Reflux = require('../src'), + keep = require('./keep'); /** * Creates an event emitting Data Store @@ -32,5 +33,8 @@ module.exports = function(definition) { shouldEmit: definition.shouldEmit || Reflux.publisherMethods.shouldEmit }); - return new Store(); + var store = new Store(); + keep.createdStores.push(store); + + return store; }; diff --git a/src/index.js b/src/index.js index 88b8746..a66bd6c 100644 --- a/src/index.js +++ b/src/index.js @@ -29,3 +29,5 @@ exports.nextTick = function(nextTick) { var _ = require('./utils'); _.nextTick = nextTick; }; + +exports.__keep = require('./keep'); diff --git a/src/keep.js b/src/keep.js new file mode 100644 index 0000000..9ad1dc6 --- /dev/null +++ b/src/keep.js @@ -0,0 +1,12 @@ +exports.createdStores = []; + +exports.createdActions = []; + +exports.reset = function() { + while(exports.createdStores.length) { + exports.createdStores.pop(); + } + while(exports.createdActions.length) { + exports.createdActions.pop(); + } +}; diff --git a/src/utils.js b/src/utils.js index bc7ff7c..4508e21 100644 --- a/src/utils.js +++ b/src/utils.js @@ -34,4 +34,4 @@ exports.nextTick = function(callback) { exports.callbackName = function(string){ return "on"+string.charAt(0).toUpperCase()+string.slice(1); -}; \ No newline at end of file +}; diff --git a/test/inspectWithKeep.spec.js b/test/inspectWithKeep.spec.js new file mode 100644 index 0000000..45f04c6 --- /dev/null +++ b/test/inspectWithKeep.spec.js @@ -0,0 +1,33 @@ +var chai = require('chai'), + assert = chai.assert, + Reflux = require('../src'); + +describe('with the keep reset', function() { + beforeEach(function () { + Reflux.__keep.reset(); + }); + + describe('when an action is created', function() { + var action; + + beforeEach(function () { + action = Reflux.createAction(); + }); + + it('should be in the keep', function() { + assert.equal(Reflux.__keep.createdActions[0], action); + }); + }); + + describe('when a store is created', function() { + var store; + + beforeEach(function () { + store = Reflux.createStore({ init: function() { /* no-op */} }); + }); + + it('should be in the keep', function() { + assert.equal(Reflux.__keep.createdStores[0], store); + }); + }); +});