Comparing version 1.0.1 to 1.0.2-stop
@@ -1,27 +0,36 @@ | ||
"use strict"; | ||
// Dependencies | ||
'use strict'; | ||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
// Dependencies | ||
var EventEmitter = require("events").EventEmitter; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var assign = _interopRequire(require("object-assign")); | ||
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; } | ||
var _ = _interopRequire(require("lodash")); | ||
var _events = require('events'); | ||
var _objectAssign = require('object-assign'); | ||
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 +50,14 @@ | ||
}; | ||
eventMethods.beep = eventMethods.emitChange; // beep boop | ||
// | ||
var store = assign({}, options, eventMethods); | ||
var actionHandlers = options.actionHandlers; | ||
var storeOptions = _objectWithoutProperties(options, ['actionHandlers']); | ||
var store = (0, _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 +67,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 +84,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 +94,3 @@ }); | ||
componentWillUnmount: function componentWillUnmount() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -86,5 +101,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 +115,4 @@ } else { | ||
exports.Capacitor = createStore; | ||
exports.Mixin = storeHandlerMixin; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNhcGFjaXRvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7SUFDUyxZQUFZLFdBQVEsUUFBUSxFQUE1QixZQUFZOztJQUNkLE1BQU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mKF8uaXNBcnJheSh0aGlzLmxpc3RlblRvKSkge1xuICAgICAgICAgICAgXy5lYWNoKHRoaXMubGlzdGVuVG8sIChzdG9yZSkgPT4ge1xuICAgICAgICAgICAgICAgIHN0b3JlLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmxpc3RlblRvLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICB9XG4gICAgfSxcbiAgICBvbkNoYW5nZSAoKSB7XG4gICAgICAgIHRoaXMuc2V0U3RhdGUodGhpcy5nZXRTdGF0ZSgpKTtcbiAgICB9XG59O1xuXG5leHBvcnQgeyBjcmVhdGVTdG9yZSBhcyBDYXBhY2l0b3IsIHN0b3JlSGFuZGxlck1peGluIGFzIE1peGluIH07XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= | ||
exports.Capacitor = createCapacitor; | ||
exports.Mixin = capacitorMixin; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNhcGFjaXRvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7OztzQkFDNkIsUUFBUTs7NEJBQ2xCLGVBQWU7Ozs7c0JBQ3BCLFFBQVE7Ozs7O0FBS3RCLElBQU0sWUFBWSxHQUFHLFFBQVEsQ0FBQzs7Ozs7O0FBUTlCLFNBQVMsZUFBZSxDQUFFLE9BQU8sRUFBRSxVQUFVLEVBQUU7O0FBRTNDLFFBQUksQ0FBQyxVQUFVLEVBQUUsTUFBTSxJQUFJLEtBQUssQ0FBQyxpRUFBaUUsQ0FBQyxDQUFDO0FBQ3BHLFFBQUksQ0FBQyxvQkFBRSxHQUFHLENBQUMsT0FBTyxFQUFFLGdCQUFnQixDQUFDLEVBQUUsTUFBTSxJQUFJ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JzIE1peGluXG4gKiAvLyB0b2RvOiB3cml0ZSB1c2VmdWwgY29tbWVudHNcbiAqL1xudmFyIGNhcGFjaXRvck1peGluID0ge1xuICAgIGdldEluaXRpYWxTdGF0ZSAoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmdldFN0YXRlKCk7XG4gICAgfSxcbiAgICBjb21wb25lbnREaWRNb3VudCAoKSB7XG4gICAgICAgIGlmKCF0aGlzLmxpc3RlblRvKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYoXy5pc0FycmF5KHRoaXMubGlzdGVuVG8pKSB7XG4gICAgICAgICAgICBfLmVhY2godGhpcy5saXN0ZW5UbywgKHN0b3JlKSA9PiB7XG4gICAgICAgICAgICAgICAgc3RvcmUuYWRkQ2hhbmdlTGlzdGVuZXIodGhpcy5vbkNoYW5nZSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMubGlzdGVuVG8uYWRkQ2hhbmdlTGlzdGVuZXIodGhpcy5vbkNoYW5nZSk7XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGNvbXBvbmVudFdpbGxVbm1vdW50ICgpIHtcbiAgICAgICAgaWYoIXRoaXMubGlzdGVuVG8pIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmKF8uaXNBcnJheSh0aGlzLmxpc3RlblRvKSkge1xuICAgICAgICAgICAgXy5lYWNoKHRoaXMubGlzdGVuVG8sIChzdG9yZSkgPT4ge1xuICAgICAgICAgICAgICAgIHN0b3JlLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmxpc3RlblRvLnJlbW92ZUNoYW5nZUxpc3RlbmVyKHRoaXMub25DaGFuZ2UpO1xuICAgICAgICB9XG4gICAgfSxcbiAgICBvbkNoYW5nZSAoKSB7XG4gICAgICAgIHRoaXMuc2V0U3RhdGUodGhpcy5nZXRTdGF0ZSgpKTtcbiAgICB9XG59O1xuXG5leHBvcnQgeyBjcmVhdGVDYXBhY2l0b3IgYXMgQ2FwYWNpdG9yLCBjYXBhY2l0b3JNaXhpbiBhcyBNaXhpbiB9O1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9 |
@@ -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-stop", | ||
"description": "Simple Flux stores utilities.", | ||
@@ -28,3 +28,3 @@ "main": "dist/capacitor.js", | ||
"gulp": "3.8.11", | ||
"gulp-babel": "4.0.0", | ||
"gulp-babel": "5.1.0", | ||
"gulp-sourcemaps": "1.5.1", | ||
@@ -31,0 +31,0 @@ "mocha": "2.2.1" |
@@ -1,24 +0,4 @@ | ||
# Flux Capacitor | ||
# Flux Utils | ||
![Maintenance](https://img.shields.io/maintenance/no/2016.svg?maxAge=2592000) | ||
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) | ||
**Early adopters**, careful with breaking changes as the versions rev quickly in early stages. | ||
## TODO | ||
- expose `store.dispatchToken` for use with `#waitFor()` | ||
- write more tests | ||
- remove `.beep()` that's just silly | ||
- finish this readme, include some examples for usage | ||
- some other things I'm probably not thinking of | ||
- oh, a changelog | ||
## Quick Start | ||
`npm install flux-capacitors` | ||
```js | ||
import Capacitor from 'flux-capacitors' | ||
let MyStore = Capacitor({...}); | ||
``` | ||
Heya, we hacked this together before lots of the Flux stuff took off. It was simple, and worked, and it was great for a time. I didn't end up sticking with Flux - although we still have an app or two that uses it they don't really need much innovation in this space. |
@@ -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; | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15954
242
1
2
5