Skip to content

Commit

Permalink
Adding a keep for introspection
Browse files Browse the repository at this point in the history
Hopefully someone will manage to write browser plugin that uses
this.

This fixes #56
  • Loading branch information
spoike committed Sep 11, 2014
1 parent 74a3755 commit 9991cfb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/createAction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('./utils'),
Reflux = require('../src');
Reflux = require('../src'),
keep = require('./keep');

/**
* Creates an action functor object
Expand All @@ -22,6 +23,8 @@ module.exports = function(definition) {

_.extend(functor,context);

keep.createdActions.push(functor);

return functor;

};
8 changes: 6 additions & 2 deletions src/createStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('./utils'),
Reflux = require('../src');
Reflux = require('../src'),
keep = require('./keep');

/**
* Creates an event emitting Data Store
Expand Down Expand Up @@ -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;
};
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ exports.nextTick = function(nextTick) {
var _ = require('./utils');
_.nextTick = nextTick;
};

exports.__keep = require('./keep');
12 changes: 12 additions & 0 deletions src/keep.js
Original file line number Diff line number Diff line change
@@ -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();
}
};
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ exports.nextTick = function(callback) {

exports.callbackName = function(string){
return "on"+string.charAt(0).toUpperCase()+string.slice(1);
};
};
33 changes: 33 additions & 0 deletions test/inspectWithKeep.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 9991cfb

Please sign in to comment.