Comparing version 1.0.1 to 1.0.2
@@ -1,27 +0,37 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
// Dependencies | ||
var EventEmitter = require("events").EventEmitter; | ||
var _events = require('events'); | ||
var assign = _interopRequire(require("object-assign")); | ||
var _objectAssign = require('object-assign'); | ||
var _ = _interopRequire(require("lodash")); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var _lodash = require('lodash'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
// Class Variables | ||
var CHANGE_EVENT = "change"; | ||
var CHANGE_EVENT = 'change'; | ||
// Create Stores Module | ||
function createStore(options, Dispatcher) { | ||
/* | ||
* Flux Capacitors | ||
* // todo: write useful comments | ||
*/ | ||
function createCapacitor(options, Dispatcher) { | ||
// validation | ||
if (!Dispatcher) throw new Error("You must provide a Flux Dispatcher to register this store with."); | ||
if (!_.has(options, "actionHandlers")) throw new Error("Your store must provide an `actionHandlers` property mapping handlers to flux `action.type` constants"); | ||
if (!Dispatcher) throw new Error('You must provide a Flux Dispatcher to register this store with.'); | ||
if (!_lodash2['default'].has(options, 'actionHandlers')) throw new Error('Your store must provide an `actionHandlers` property mapping handlers to flux `action.type` constants'); | ||
// | ||
var emitter = new EventEmitter(); | ||
var emitter = new _events.EventEmitter(); | ||
emitter.setMaxListeners(0); | ||
@@ -41,11 +51,14 @@ | ||
}; | ||
eventMethods.beep = eventMethods.emitChange; // beep boop | ||
// | ||
var store = assign({}, options, eventMethods); | ||
var actionHandlers = options.actionHandlers; | ||
var storeOptions = _objectWithoutProperties(options, ['actionHandlers']); | ||
var store = _objectAssign2['default']({}, storeOptions, eventMethods); | ||
store.dispatchToken = Dispatcher.register(function (action) { | ||
if (_.has(store.actionHandlers, action.type)) { | ||
var actionHandler = store.actionHandlers[action.type]; | ||
actionHandler(action); | ||
if (_lodash2['default'].has(actionHandlers, action.type)) { | ||
var actionHandler = actionHandlers[action.type]; | ||
actionHandler.call(store, action); | ||
} | ||
@@ -55,6 +68,9 @@ }); | ||
return store; | ||
}; | ||
} | ||
// Component mixin for wiring to Capacitor stores | ||
var storeHandlerMixin = { | ||
/* | ||
* Flux Capacitors Mixin | ||
* // todo: write useful comments | ||
*/ | ||
var capacitorMixin = { | ||
getInitialState: function getInitialState() { | ||
@@ -69,4 +85,4 @@ return this.getState(); | ||
} | ||
if (_.isArray(this.listenTo)) { | ||
_.each(this.listenTo, function (store) { | ||
if (_lodash2['default'].isArray(this.listenTo)) { | ||
_lodash2['default'].each(this.listenTo, function (store) { | ||
store.addChangeListener(_this.onChange); | ||
@@ -79,3 +95,3 @@ }); | ||
componentWillUnmount: function componentWillUnmount() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -86,5 +102,5 @@ if (!this.listenTo) { | ||
if (_.isArray(this.listenTo)) { | ||
_.each(this.listenTo, function (store) { | ||
store.removeChangeListener(_this.onChange); | ||
if (_lodash2['default'].isArray(this.listenTo)) { | ||
_lodash2['default'].each(this.listenTo, function (store) { | ||
store.removeChangeListener(_this2.onChange); | ||
}); | ||
@@ -100,4 +116,4 @@ } else { | ||
exports.Capacitor = createStore; | ||
exports.Mixin = storeHandlerMixin; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNhcGFjaXRvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7SUFDUyxZQUFZLFdBQVEsUUFBUSxFQUE1QixZQUFZOztJQUNkLE1BQU0sMkJBQU0sZUFBZTs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GlzLmxpc3RlblRvKSkge1xuICAgICAgICAgICAgXy5lYWNoKHRoaXMubGlzdGVuVG8sIChzdG9yZSkgPT4ge1xuICAgICAgICAgICAgICAgIHN0b3JlLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmxpc3RlblRvLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICB9XG4gICAgfSxcbiAgICBvbkNoYW5nZSAoKSB7XG4gICAgICAgIHRoaXMuc2V0U3RhdGUodGhpcy5nZXRTdGF0ZSgpKTtcbiAgICB9XG59O1xuXG5leHBvcnQgeyBjcmVhdGVTdG9yZSBhcyBDYXBhY2l0b3IsIHN0b3JlSGFuZGxlck1peGluIGFzIE1peGluIH07XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= | ||
exports.Capacitor = createCapacitor; | ||
exports.Mixin = capacitorMixin; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNhcGFjaXRvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7c0JBQzZCLFFBQVE7OzRCQUNsQixlQUFlOzs7O3NCQUNwQixRQUFROzs7OztBQUt0QixJQUFNLFlBQVksR0FBRyxRQUFRLENBQUM7Ozs7OztBQVE5QixTQUFTLGVBQWUsQ0FBRSxPQUFPLEVBQUUsVUFBVSxFQUFFOztBQUUzQyxRQUFJLENBQUMsVUFBVSxFQUFFLE1BQU0sSUFBSSxLQUFLLENBQUMsaUVBQWlFLENBQUMsQ0FBQztBQUNwRyxRQUFJLENBQUMsb0JBQUUsR0FBRyxDQUFDLE9BQU8sRUFBRSxnQkFBZ0IsQ0FBQyxFQUFFLE1BQU0sSUFBSSxLQUFLLENBQUMsdUdBQXVHLENBQUMs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AgICB9LFxuICAgIG9uQ2hhbmdlICgpIHtcbiAgICAgICAgdGhpcy5zZXRTdGF0ZSh0aGlzLmdldFN0YXRlKCkpO1xuICAgIH1cbn07XG5cbmV4cG9ydCB7IGNyZWF0ZUNhcGFjaXRvciBhcyBDYXBhY2l0b3IsIGNhcGFjaXRvck1peGluIGFzIE1peGluIH07XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= |
@@ -14,5 +14,5 @@ // Dependencies | ||
.pipe(sourcemaps.init()) | ||
.pipe(babel()) | ||
.pipe(babel({ stage: 1 })) | ||
.pipe(sourcemaps.write()) | ||
.pipe(gulp.dest('dist')); | ||
}); |
{ | ||
"name": "flux-utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Simple Flux stores utilities.", | ||
@@ -9,3 +9,3 @@ "main": "dist/capacitor.js", | ||
"build": "gulp", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build && npm test" | ||
}, | ||
@@ -29,3 +29,3 @@ "repository": { | ||
"gulp": "3.8.11", | ||
"gulp-babel": "4.0.0", | ||
"gulp-babel": "5.1.0", | ||
"gulp-sourcemaps": "1.5.1", | ||
@@ -32,0 +32,0 @@ "mocha": "2.2.1" |
@@ -1,4 +0,4 @@ | ||
# Flux Capacitor | ||
# Flux Utils | ||
Pardon the dust, hacking away at this to make it OSS / Release worthy. Intended use: a util library to facilitate in creating Flux Stores with ease. (More info to come) | ||
Pardon the dust, quickly hacking away at this to make it OSS / Release worthy. Intended use: a util library to facilitate in creating Flux Stores with ease. (More info to come) | ||
@@ -10,16 +10,41 @@ **Early adopters**, careful with breaking changes as the versions rev quickly in early stages. | ||
- expose `store.dispatchToken` for use with `#waitFor()` | ||
- write more tests | ||
- remove `.beep()` that's just silly | ||
- write more tests (or fill in the todos) | ||
- finish this readme, include some examples for usage | ||
- some other things I'm probably not thinking of | ||
- oh, a changelog | ||
- oh, a changelog would be nice to keep | ||
## Quick Start | ||
`npm install flux-capacitors` | ||
## Capacitor Quick Start | ||
`npm install flux-utils` | ||
```js | ||
// myStore.js | ||
import Capacitor from 'flux-capacitors' | ||
let MyStore = Capacitor({...}); | ||
let actionHandlers = {}; | ||
actionHandlers[MY_CONST_ACTION_TYPE] = function myConstActionTypeHandler (action) { | ||
// process action, emit change (only if necessary) | ||
MyStore.emitchange(); | ||
}; | ||
let MyStore = Capacitor({ actionHandlers }, MyFluxDispatcher); | ||
``` | ||
## Mixin Quick Start | ||
`npm install flux-utils` | ||
```js | ||
// myComponent.js | ||
import { Mixin as Capacitors } from 'flux-capacitors' | ||
var ReactComponent = React.createClass({ | ||
mixins: [Capacitors], | ||
listenTo: [MyCapacitorStore], | ||
render () { | ||
// #wheee | ||
} | ||
}) | ||
``` | ||
@@ -13,4 +13,7 @@ // Dependencies | ||
// Create Stores Module | ||
function createStore (options, Dispatcher) { | ||
/* | ||
* Flux Capacitors | ||
* // todo: write useful comments | ||
*/ | ||
function createCapacitor (options, Dispatcher) { | ||
// validation | ||
@@ -36,11 +39,11 @@ if (!Dispatcher) throw new Error('You must provide a Flux Dispatcher to register this store with.'); | ||
}; | ||
eventMethods.beep = eventMethods.emitChange; // beep boop | ||
// | ||
var store = assign({}, options, eventMethods); | ||
var { actionHandlers, ...storeOptions } = options; | ||
var store = assign({}, storeOptions, eventMethods); | ||
store.dispatchToken = Dispatcher.register(function (action) { | ||
if (_.has(store.actionHandlers, action.type)) { | ||
let actionHandler = store.actionHandlers[action.type]; | ||
actionHandler(action); | ||
if (_.has(actionHandlers, action.type)) { | ||
let actionHandler = actionHandlers[action.type]; | ||
actionHandler.call(store, action); | ||
} | ||
@@ -50,6 +53,9 @@ }); | ||
return store; | ||
}; | ||
} | ||
// Component mixin for wiring to Capacitor stores | ||
var storeHandlerMixin = { | ||
/* | ||
* Flux Capacitors Mixin | ||
* // todo: write useful comments | ||
*/ | ||
var capacitorMixin = { | ||
getInitialState () { | ||
@@ -88,2 +94,2 @@ return this.getState(); | ||
export { createStore as Capacitor, storeHandlerMixin as Mixin }; | ||
export { createCapacitor as Capacitor, capacitorMixin as Mixin }; |
@@ -25,6 +25,6 @@ // Test Dependencies | ||
// Tests | ||
describe('Using Capacitor', function () { | ||
describe('Creating Stores', function () { | ||
it('should expose #createStore by default', function () { | ||
expect(Capacitor.name).to.equal('createStore'); | ||
describe('Flux Utils', function () { | ||
describe('Creating Capacitor Stores', function () { | ||
it('should expose #createCapacitor by default', function () { | ||
expect(Capacitor.name).to.equal('createCapacitor'); | ||
}); | ||
@@ -42,9 +42,35 @@ | ||
describe('Using created stores', function () { | ||
it('should expose a .dispatchToken for use with Dispatcher#waitFor()'); | ||
it('should expose emitChange()'); | ||
it('should expose addChangeListener()'); | ||
it('should expose removeChangeListener()'); | ||
var store = goodCapacitor(); | ||
it('should expose a store.dispatchToken for use with Dispatcher#waitFor()', function () { | ||
expect(store).to.have.property('dispatchToken'); | ||
expect(store.dispatchToken).to.be.ok; | ||
}); | ||
it('should expose store#emitChange()', function () { | ||
expect(store).to.have.property('emitChange'); | ||
expect(store.emitChange).to.be.a('function'); | ||
}); | ||
it('should expose store#addChangeListener()', function () { | ||
expect(store).to.have.property('addChangeListener'); | ||
expect(store.addChangeListener).to.be.a('function'); | ||
}); | ||
it('should expose store#removeChangeListener()', function () { | ||
expect(store).to.have.property('removeChangeListener'); | ||
expect(store.removeChangeListener).to.be.a('function'); | ||
}); | ||
it('should not expose store.actionHandlers', function () { | ||
expect(store).to.not.have.property('actionHandlers'); | ||
}); | ||
it('should invoke appropriate actionHandler for registered action.type'); | ||
it('emitChange() should invoke provided callbacks'); | ||
it('emitChange() should invoke provided change callbacks'); | ||
}); | ||
describe('Using Capacitor Mixin', function () { | ||
it('should have more tests stubbed out than this'); | ||
}); | ||
}); | ||
@@ -61,2 +87,3 @@ | ||
var store = Capacitor(basicStore, basicDispatcher); | ||
return store; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16806
242
50
1