Comparing version 2.1.0 to 3.0.0
10
diode.js
@@ -7,5 +7,4 @@ /** | ||
var invariant = require('./invariant') | ||
var _callbacks = [] | ||
var _tick = null; | ||
var _tick = null | ||
@@ -29,4 +28,2 @@ /** | ||
unsubscribe: function(callback) { | ||
invariant(_callbacks.indexOf(callback) > -1, 'Diode.unsubscribe() was asked to remove callback that it was not subscribed to.'); | ||
_callbacks = _callbacks.filter(function(i) { | ||
@@ -41,6 +38,3 @@ return i !== callback | ||
subscribe: function(callback) { | ||
var type = typeof callback; | ||
invariant(type === 'function', 'Diode.subscribe() expects a function, instead it received a ' + type); | ||
_callbacks = _callbacks.concat(callback); | ||
_callbacks = _callbacks.concat(callback) | ||
}, | ||
@@ -47,0 +41,0 @@ |
{ | ||
"name": "diode", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "A simple, eventually consistent, state propagation tool for Flux/React apps", | ||
@@ -5,0 +5,0 @@ "main": "diode.js", |
@@ -1,3 +0,2 @@ | ||
var Diode = require('./diode'); | ||
var invariant = require('./invariant'); | ||
var Diode = require('./diode') | ||
@@ -7,24 +6,27 @@ var Stateful = { | ||
getInitialState: function() { | ||
invariant(this.getState, "Stateful mixin requires `getState` implementation."); | ||
return this.getState(); | ||
if (!this.getState) { | ||
throw new Error("Stateful mixin requires `getState` implementation.") | ||
} | ||
return this.getState() | ||
}, | ||
_updateState: function() { | ||
this.setState(this.getState()); | ||
this.setState(this.getState()) | ||
}, | ||
componentDidMount: function() { | ||
Diode.subscribe(this._updateState); | ||
Diode.subscribe(this._updateState) | ||
}, | ||
componentWillUnmount: function() { | ||
Diode.unsubscribe(this._updateState); | ||
Diode.unsubscribe(this._updateState) | ||
}, | ||
componentWillReceiveProps: function() { | ||
this._updateState(); | ||
this._updateState() | ||
} | ||
}; | ||
} | ||
module.exports = Stateful |
5940
8
65