reflux-core
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -5,9 +5,2 @@ "use strict"; | ||
value: true | ||
}); | ||
/** | ||
* A module of methods that you want to include in all actions. | ||
* This module is consumed by `createAction`. | ||
*/ | ||
var ActionMethods = {}; | ||
exports.default = ActionMethods; | ||
}); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = createAction; | ||
exports.createAction = createAction; | ||
@@ -15,14 +15,12 @@ var _utils = require("./utils"); | ||
var _ActionMethods2 = _interopRequireDefault(_ActionMethods); | ||
var ActionMethods = _interopRequireWildcard(_ActionMethods); | ||
var _PublisherMethods = require("./PublisherMethods"); | ||
var _PublisherMethods2 = _interopRequireDefault(_PublisherMethods); | ||
var PublisherMethods = _interopRequireWildcard(_PublisherMethods); | ||
var _Keep = require("./Keep"); | ||
var _Keep2 = _interopRequireDefault(_Keep); | ||
var Keep = _interopRequireWildcard(_Keep); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -46,4 +44,4 @@ | ||
for (var a in _ActionMethods2.default) { | ||
if (!allowed[a] && _PublisherMethods2.default[a]) { | ||
for (var a in ActionMethods) { | ||
if (!allowed[a] && PublisherMethods[a]) { | ||
throw new Error("Cannot override API method " + a + " in Reflux.ActionMethods. Use another method name or override it on Reflux.PublisherMethods instead."); | ||
@@ -54,3 +52,3 @@ } | ||
for (var d in definition) { | ||
if (!allowed[d] && _PublisherMethods2.default[d]) { | ||
if (!allowed[d] && PublisherMethods[d]) { | ||
throw new Error("Cannot override API method " + d + " in action creation. Use another method name or override it on Reflux.PublisherMethods instead."); | ||
@@ -76,3 +74,3 @@ } | ||
_isAction: true | ||
}, _PublisherMethods2.default, _ActionMethods2.default, definition); | ||
}, PublisherMethods, ActionMethods, definition); | ||
@@ -86,5 +84,5 @@ var functor = function functor() { | ||
_Keep2.default.addAction(functor); | ||
Keep.addAction(functor); | ||
return functor; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = createStore; | ||
exports.createStore = createStore; | ||
@@ -15,8 +15,6 @@ var _utils = require("./utils"); | ||
var _Keep2 = _interopRequireDefault(_Keep); | ||
var Keep = _interopRequireWildcard(_Keep); | ||
var _mixer = require("./mixer"); | ||
var _mixer2 = _interopRequireDefault(_mixer); | ||
var _bindMethods = require("./bindMethods"); | ||
@@ -26,14 +24,12 @@ | ||
var _StoreMethods2 = _interopRequireDefault(_StoreMethods); | ||
var StoreMethods = _interopRequireWildcard(_StoreMethods); | ||
var _PublisherMethods = require("./PublisherMethods"); | ||
var _PublisherMethods2 = _interopRequireDefault(_PublisherMethods); | ||
var PublisherMethods = _interopRequireWildcard(_PublisherMethods); | ||
var _ListenerMethods = require("./ListenerMethods"); | ||
var _ListenerMethods2 = _interopRequireDefault(_ListenerMethods); | ||
var ListenerMethods = _interopRequireWildcard(_ListenerMethods); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -55,4 +51,4 @@ | ||
for (var a in _StoreMethods2.default) { | ||
if (!allowed[a] && (_PublisherMethods2.default[a] || _ListenerMethods2.default[a])) { | ||
for (var a in StoreMethods) { | ||
if (!allowed[a] && (PublisherMethods[a] || ListenerMethods[a])) { | ||
throw new Error("Cannot override API method " + a + " in Reflux.StoreMethods. Use another method name or override it on Reflux.PublisherMethods / Reflux.ListenerMethods instead."); | ||
@@ -63,3 +59,3 @@ } | ||
for (var d in definition) { | ||
if (!allowed[d] && (_PublisherMethods2.default[d] || _ListenerMethods2.default[d])) { | ||
if (!allowed[d] && (PublisherMethods[d] || ListenerMethods[d])) { | ||
throw new Error("Cannot override API method " + d + " in store creation. Use another method name or override it on Reflux.PublisherMethods / Reflux.ListenerMethods instead."); | ||
@@ -69,3 +65,3 @@ } | ||
definition = (0, _mixer2.default)(definition); | ||
definition = (0, _mixer.mix)(definition); | ||
@@ -90,8 +86,8 @@ function Store() { | ||
_.extend(Store.prototype, _ListenerMethods2.default, _PublisherMethods2.default, _StoreMethods2.default, definition); | ||
_.extend(Store.prototype, ListenerMethods, PublisherMethods, StoreMethods, definition); | ||
var store = new Store(); | ||
_Keep2.default.addStore(store); | ||
Keep.addStore(store); | ||
return store; | ||
} |
@@ -6,18 +6,19 @@ "use strict"; | ||
}); | ||
exports.__keep = exports.joinConcat = exports.joinStrict = exports.joinLeading = exports.all = exports.joinTrailing = exports.use = exports.nextTick = exports.setEventEmitter = exports.createActions = exports.createStore = exports.createAction = exports.utils = exports.StoreMethods = exports.PublisherMethods = exports.ListenerMethods = exports.ActionMethods = exports.version = undefined; | ||
var _ActionMethods = require("./ActionMethods"); | ||
var _ActionMethods2 = _interopRequireDefault(_ActionMethods); | ||
var ActionMethods = _interopRequireWildcard(_ActionMethods); | ||
var _ListenerMethods = require("./ListenerMethods"); | ||
var _ListenerMethods2 = _interopRequireDefault(_ListenerMethods); | ||
var ListenerMethods = _interopRequireWildcard(_ListenerMethods); | ||
var _PublisherMethods = require("./PublisherMethods"); | ||
var _PublisherMethods2 = _interopRequireDefault(_PublisherMethods); | ||
var PublisherMethods = _interopRequireWildcard(_PublisherMethods); | ||
var _StoreMethods = require("./StoreMethods"); | ||
var _StoreMethods2 = _interopRequireDefault(_StoreMethods); | ||
var StoreMethods = _interopRequireWildcard(_StoreMethods); | ||
@@ -32,18 +33,12 @@ var _joins = require("./joins"); | ||
var _createAction2 = _interopRequireDefault(_createAction); | ||
var _createStore = require("./createStore"); | ||
var _createStore2 = _interopRequireDefault(_createStore); | ||
var _Keep = require("./Keep"); | ||
var _Keep2 = _interopRequireDefault(_Keep); | ||
var __keep = _interopRequireWildcard(_Keep); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var version = { | ||
"reflux-core": "0.4.0" | ||
"reflux-core": "0.4.1" | ||
}; | ||
@@ -70,3 +65,3 @@ | ||
var val = definitions[actionName]; | ||
actions[actionName] = (0, _createAction2.default)(val); | ||
actions[actionName] = (0, _createAction.createAction)(val); | ||
}); | ||
@@ -82,3 +77,3 @@ }; | ||
} else { | ||
actions[val] = (0, _createAction2.default)(val); | ||
actions[val] = (0, _createAction.createAction)(val); | ||
} | ||
@@ -115,22 +110,20 @@ }); | ||
/*eslint-disable no-underscore-dangle*/ | ||
exports.default = { | ||
version: version, | ||
ActionMethods: _ActionMethods2.default, | ||
ListenerMethods: _ListenerMethods2.default, | ||
PublisherMethods: _PublisherMethods2.default, | ||
StoreMethods: _StoreMethods2.default, | ||
utils: utils, | ||
createAction: _createAction2.default, | ||
createStore: _createStore2.default, | ||
createActions: createActions, | ||
setEventEmitter: setEventEmitter, | ||
nextTick: nextTick, | ||
use: use, | ||
joinTrailing: joinTrailing, | ||
all: all, | ||
joinLeading: joinLeading, | ||
joinStrict: joinStrict, | ||
joinConcat: joinConcat, | ||
__keep: _Keep2.default | ||
}; | ||
exports.version = version; | ||
exports.ActionMethods = ActionMethods; | ||
exports.ListenerMethods = ListenerMethods; | ||
exports.PublisherMethods = PublisherMethods; | ||
exports.StoreMethods = StoreMethods; | ||
exports.utils = utils; | ||
exports.createAction = _createAction.createAction; | ||
exports.createStore = _createStore.createStore; | ||
exports.createActions = createActions; | ||
exports.setEventEmitter = setEventEmitter; | ||
exports.nextTick = nextTick; | ||
exports.use = use; | ||
exports.joinTrailing = joinTrailing; | ||
exports.all = all; | ||
exports.joinLeading = joinLeading; | ||
exports.joinStrict = joinStrict; | ||
exports.joinConcat = joinConcat; | ||
exports.__keep = __keep; | ||
/*eslint-enable no-underscore-dangle*/ | ||
@@ -137,0 +130,0 @@ |
@@ -11,4 +11,2 @@ "use strict"; | ||
var _createStore2 = _interopRequireDefault(_createStore); | ||
var _utils = require("./utils"); | ||
@@ -20,4 +18,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -43,3 +39,3 @@ * Internal module used to create static and instance join methods | ||
var listenables = slice.call(arguments); | ||
return (0, _createStore2.default)({ | ||
return (0, _createStore.createStore)({ | ||
init: function init() { | ||
@@ -46,0 +42,0 @@ this[strategyMethodNames[strategy]].apply(this, listenables.concat("triggerAsync")); |
@@ -41,2 +41,7 @@ "use strict"; | ||
exports.default = { useKeep: useKeep, addStore: addStore, addAction: addAction, createdStores: createdStores, createdActions: createdActions, reset: reset }; | ||
exports.useKeep = useKeep; | ||
exports.addStore = addStore; | ||
exports.addAction = addAction; | ||
exports.createdStores = createdStores; | ||
exports.createdActions = createdActions; | ||
exports.reset = reset; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.joinStrict = exports.joinConcat = exports.joinLeading = exports.joinTrailing = exports.fetchInitialState = exports.stopListeningToAll = exports.stopListeningTo = exports.listenTo = exports.validateListening = exports.listenToMany = exports.hasListener = undefined; | ||
@@ -62,183 +63,177 @@ var _utils = require("./utils"); | ||
/** | ||
* A module of methods related to listening. | ||
* An internal utility function used by `validateListening` | ||
* | ||
* @param {Action|Store} listenable The listenable we want to search for | ||
* @returns {Boolean} The result of a recursive search among `this.subscriptions` | ||
*/ | ||
exports.default = { | ||
/** | ||
* An internal utility function used by `validateListening` | ||
* | ||
* @param {Action|Store} listenable The listenable we want to search for | ||
* @returns {Boolean} The result of a recursive search among `this.subscriptions` | ||
*/ | ||
hasListener: function hasListener(listenable) { | ||
var i = 0, | ||
j, | ||
listener, | ||
listenables; | ||
for (; i < (this.subscriptions || []).length; ++i) { | ||
listenables = [].concat(this.subscriptions[i].listenable); | ||
for (j = 0; j < listenables.length; j++) { | ||
listener = listenables[j]; | ||
if (listener === listenable || listener.hasListener && listener.hasListener(listenable)) { | ||
return true; | ||
} | ||
var hasListener = exports.hasListener = function hasListener(listenable) { | ||
var i = 0, | ||
j, | ||
listener, | ||
listenables; | ||
for (; i < (this.subscriptions || []).length; ++i) { | ||
listenables = [].concat(this.subscriptions[i].listenable); | ||
for (j = 0; j < listenables.length; j++) { | ||
listener = listenables[j]; | ||
if (listener === listenable || listener.hasListener && listener.hasListener(listenable)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
} | ||
return false; | ||
}; | ||
/** | ||
* A convenience method that listens to all listenables in the given object. | ||
* | ||
* @param {Object} listenables An object of listenables. Keys will be used as callback method names. | ||
*/ | ||
listenToMany: function listenToMany(listenables) { | ||
var allListenables = flattenListenables(listenables); | ||
for (var key in allListenables) { | ||
var cbname = _.callbackName(key), | ||
localname = this[cbname] ? cbname : this[key] ? key : undefined; | ||
if (localname) { | ||
this.listenTo(allListenables[key], localname, this[cbname + "Default"] || this[localname + "Default"] || localname); | ||
} | ||
/** | ||
* A convenience method that listens to all listenables in the given object. | ||
* | ||
* @param {Object} listenables An object of listenables. Keys will be used as callback method names. | ||
*/ | ||
var listenToMany = exports.listenToMany = function listenToMany(listenables) { | ||
var allListenables = flattenListenables(listenables); | ||
for (var key in allListenables) { | ||
var cbname = _.callbackName(key), | ||
localname = this[cbname] ? cbname : this[key] ? key : undefined; | ||
if (localname) { | ||
this.listenTo(allListenables[key], localname, this[cbname + "Default"] || this[localname + "Default"] || localname); | ||
} | ||
}, | ||
} | ||
}; | ||
/** | ||
* Checks if the current context can listen to the supplied listenable | ||
* | ||
* @param {Action|Store} listenable An Action or Store that should be | ||
* listened to. | ||
* @returns {String|Undefined} An error message, or undefined if there was no problem. | ||
*/ | ||
validateListening: function validateListening(listenable) { | ||
if (listenable === this) { | ||
return "Listener is not able to listen to itself"; | ||
} | ||
if (!_.isFunction(listenable.listen)) { | ||
return listenable + " is missing a listen method"; | ||
} | ||
if (listenable.hasListener && listenable.hasListener(this)) { | ||
return "Listener cannot listen to this listenable because of circular loop"; | ||
} | ||
}, | ||
/** | ||
* Checks if the current context can listen to the supplied listenable | ||
* | ||
* @param {Action|Store} listenable An Action or Store that should be | ||
* listened to. | ||
* @returns {String|Undefined} An error message, or undefined if there was no problem. | ||
*/ | ||
var validateListening = exports.validateListening = function validateListening(listenable) { | ||
if (listenable === this) { | ||
return "Listener is not able to listen to itself"; | ||
} | ||
if (!_.isFunction(listenable.listen)) { | ||
return listenable + " is missing a listen method"; | ||
} | ||
if (listenable.hasListener && listenable.hasListener(this)) { | ||
return "Listener cannot listen to this listenable because of circular loop"; | ||
} | ||
}; | ||
/** | ||
* Sets up a subscription to the given listenable for the context object | ||
* | ||
* @param {Action|Store} listenable An Action or Store that should be | ||
* listened to. | ||
* @param {Function|String} callback The callback to register as event handler | ||
* @param {Function|String} defaultCallback The callback to register as default handler | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is the object being listened to | ||
*/ | ||
listenTo: function listenTo(listenable, callback, defaultCallback) { | ||
var desub, | ||
unsubscriber, | ||
subscriptionobj, | ||
subs = this.subscriptions = this.subscriptions || []; | ||
_.throwIf(this.validateListening(listenable)); | ||
this.fetchInitialState(listenable, defaultCallback); | ||
desub = listenable.listen(this[callback] || callback, this); | ||
unsubscriber = function unsubscriber() { | ||
var index = subs.indexOf(subscriptionobj); | ||
_.throwIf(index === -1, "Tried to remove listen already gone from subscriptions list!"); | ||
subs.splice(index, 1); | ||
desub(); | ||
}; | ||
subscriptionobj = { | ||
stop: unsubscriber, | ||
listenable: listenable | ||
}; | ||
subs.push(subscriptionobj); | ||
return subscriptionobj; | ||
}, | ||
/** | ||
* Sets up a subscription to the given listenable for the context object | ||
* | ||
* @param {Action|Store} listenable An Action or Store that should be | ||
* listened to. | ||
* @param {Function|String} callback The callback to register as event handler | ||
* @param {Function|String} defaultCallback The callback to register as default handler | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is the object being listened to | ||
*/ | ||
var listenTo = exports.listenTo = function listenTo(listenable, callback, defaultCallback) { | ||
var desub, | ||
unsubscriber, | ||
subscriptionobj, | ||
subs = this.subscriptions = this.subscriptions || []; | ||
_.throwIf(this.validateListening(listenable)); | ||
this.fetchInitialState(listenable, defaultCallback); | ||
desub = listenable.listen(this[callback] || callback, this); | ||
unsubscriber = function unsubscriber() { | ||
var index = subs.indexOf(subscriptionobj); | ||
_.throwIf(index === -1, "Tried to remove listen already gone from subscriptions list!"); | ||
subs.splice(index, 1); | ||
desub(); | ||
}; | ||
subscriptionobj = { | ||
stop: unsubscriber, | ||
listenable: listenable | ||
}; | ||
subs.push(subscriptionobj); | ||
return subscriptionobj; | ||
}; | ||
/** | ||
* Stops listening to a single listenable | ||
* | ||
* @param {Action|Store} listenable The action or store we no longer want to listen to | ||
* @returns {Boolean} True if a subscription was found and removed, otherwise false. | ||
*/ | ||
stopListeningTo: function stopListeningTo(listenable) { | ||
var sub, | ||
i = 0, | ||
subs = this.subscriptions || []; | ||
for (; i < subs.length; i++) { | ||
sub = subs[i]; | ||
if (sub.listenable === listenable) { | ||
sub.stop(); | ||
_.throwIf(subs.indexOf(sub) !== -1, "Failed to remove listen from subscriptions list!"); | ||
return true; | ||
} | ||
/** | ||
* Stops listening to a single listenable | ||
* | ||
* @param {Action|Store} listenable The action or store we no longer want to listen to | ||
* @returns {Boolean} True if a subscription was found and removed, otherwise false. | ||
*/ | ||
var stopListeningTo = exports.stopListeningTo = function stopListeningTo(listenable) { | ||
var sub, | ||
i = 0, | ||
subs = this.subscriptions || []; | ||
for (; i < subs.length; i++) { | ||
sub = subs[i]; | ||
if (sub.listenable === listenable) { | ||
sub.stop(); | ||
_.throwIf(subs.indexOf(sub) !== -1, "Failed to remove listen from subscriptions list!"); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Stops all subscriptions and empties subscriptions array | ||
*/ | ||
stopListeningToAll: function stopListeningToAll() { | ||
var remaining, | ||
subs = this.subscriptions || []; | ||
while (remaining = subs.length) { | ||
subs[0].stop(); | ||
_.throwIf(subs.length !== remaining - 1, "Failed to remove listen from subscriptions list!"); | ||
} | ||
}, | ||
/** | ||
* Stops all subscriptions and empties subscriptions array | ||
*/ | ||
var stopListeningToAll = exports.stopListeningToAll = function stopListeningToAll() { | ||
var remaining, | ||
subs = this.subscriptions || []; | ||
while (remaining = subs.length) { | ||
subs[0].stop(); | ||
_.throwIf(subs.length !== remaining - 1, "Failed to remove listen from subscriptions list!"); | ||
} | ||
}; | ||
/** | ||
* Used in `listenTo`. Fetches initial data from a publisher if it has a `getInitialState` method. | ||
* @param {Action|Store} listenable The publisher we want to get initial state from | ||
* @param {Function|String} defaultCallback The method to receive the data | ||
*/ | ||
fetchInitialState: function fetchInitialState(listenable, defaultCallback) { | ||
defaultCallback = defaultCallback && this[defaultCallback] || defaultCallback; | ||
var me = this; | ||
if (_.isFunction(defaultCallback) && _.isFunction(listenable.getInitialState)) { | ||
var data = listenable.getInitialState(); | ||
if (data && _.isFunction(data.then)) { | ||
data.then(function () { | ||
defaultCallback.apply(me, arguments); | ||
}); | ||
} else { | ||
defaultCallback.call(this, data); | ||
} | ||
/** | ||
* Used in `listenTo`. Fetches initial data from a publisher if it has a `getInitialState` method. | ||
* @param {Action|Store} listenable The publisher we want to get initial state from | ||
* @param {Function|String} defaultCallback The method to receive the data | ||
*/ | ||
var fetchInitialState = exports.fetchInitialState = function fetchInitialState(listenable, defaultCallback) { | ||
defaultCallback = defaultCallback && this[defaultCallback] || defaultCallback; | ||
var me = this; | ||
if (_.isFunction(defaultCallback) && _.isFunction(listenable.getInitialState)) { | ||
var data = listenable.getInitialState(); | ||
if (data && _.isFunction(data.then)) { | ||
data.then(function () { | ||
defaultCallback.apply(me, arguments); | ||
}); | ||
} else { | ||
defaultCallback.call(this, data); | ||
} | ||
}, | ||
} | ||
}; | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with the last emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
joinTrailing: (0, _joins.instanceJoinCreator)("last"), | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with the last emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
var joinTrailing = exports.joinTrailing = (0, _joins.instanceJoinCreator)("last"); | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with the first emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
joinLeading: (0, _joins.instanceJoinCreator)("first"), | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with the first emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
var joinLeading = exports.joinLeading = (0, _joins.instanceJoinCreator)("first"); | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with all emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
joinConcat: (0, _joins.instanceJoinCreator)("all"), | ||
/** | ||
* The callback will be called once all listenables have triggered at least once. | ||
* It will be invoked with all emission from each listenable. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
var joinConcat = exports.joinConcat = (0, _joins.instanceJoinCreator)("all"); | ||
/** | ||
* The callback will be called once all listenables have triggered. | ||
* If a callback triggers twice before that happens, an error is thrown. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
joinStrict: (0, _joins.instanceJoinCreator)("strict") | ||
}; | ||
/** | ||
* The callback will be called once all listenables have triggered. | ||
* If a callback triggers twice before that happens, an error is thrown. | ||
* @param {...Publishers} publishers Publishers that should be tracked. | ||
* @param {Function|String} callback The method to call when all publishers have emitted | ||
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is an array of listenables | ||
*/ | ||
var joinStrict = exports.joinStrict = (0, _joins.instanceJoinCreator)("strict"); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = mix; | ||
exports.mix = mix; | ||
@@ -9,0 +9,0 @@ var _utils = require("./utils"); |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.deferWith = exports.triggerAsync = exports.trigger = exports.listen = exports.shouldEmit = exports.preEmit = undefined; | ||
@@ -18,90 +19,87 @@ var _utils = require("./utils"); | ||
*/ | ||
exports.default = { | ||
/** | ||
* Hook used by the publisher that is invoked before emitting | ||
* and before `shouldEmit`. The arguments are the ones that the action | ||
* is invoked with. If this function returns something other than | ||
* undefined, that will be passed on as arguments for shouldEmit and | ||
* emission. | ||
*/ | ||
preEmit: function preEmit() {}, | ||
/** | ||
* Hook used by the publisher that is invoked before emitting | ||
* and before `shouldEmit`. The arguments are the ones that the action | ||
* is invoked with. If this function returns something other than | ||
* undefined, that will be passed on as arguments for shouldEmit and | ||
* emission. | ||
*/ | ||
var preEmit = exports.preEmit = function preEmit() {}; | ||
/** | ||
* Hook used by the publisher after `preEmit` to determine if the | ||
* event should be emitted with given arguments. This may be overridden | ||
* in your application, default implementation always returns true. | ||
* | ||
* @returns {Boolean} true if event should be emitted | ||
*/ | ||
shouldEmit: function shouldEmit() { | ||
return true; | ||
}, | ||
/** | ||
* Hook used by the publisher after `preEmit` to determine if the | ||
* event should be emitted with given arguments. This may be overridden | ||
* in your application, default implementation always returns true. | ||
* | ||
* @returns {Boolean} true if event should be emitted | ||
*/ | ||
var shouldEmit = exports.shouldEmit = function shouldEmit() { | ||
return true; | ||
}; | ||
/** | ||
* Subscribes the given callback for action triggered | ||
* | ||
* @param {Function} callback The callback to register as event handler | ||
* @param {Mixed} [optional] bindContext The context to bind the callback with | ||
* @returns {Function} Callback that unsubscribes the registered event handler | ||
*/ | ||
listen: function listen(callback, bindContext) { | ||
bindContext = bindContext || this; | ||
var eventHandler = function eventHandler(args) { | ||
if (aborted) { | ||
return; | ||
} | ||
callback.apply(bindContext, args); | ||
}, | ||
me = this, | ||
aborted = false; | ||
this.emitter.addListener(this.eventLabel, eventHandler); | ||
return function () { | ||
aborted = true; | ||
me.emitter.removeListener(me.eventLabel, eventHandler); | ||
}; | ||
}, | ||
/** | ||
* Publishes an event using `this.emitter` (if `shouldEmit` agrees) | ||
*/ | ||
trigger: function trigger() { | ||
var args = arguments, | ||
pre = this.preEmit.apply(this, args); | ||
args = pre === undefined ? args : _.isArguments(pre) ? pre : [].concat(pre); | ||
if (this.shouldEmit.apply(this, args)) { | ||
this.emitter.emit(this.eventLabel, args); | ||
/** | ||
* Subscribes the given callback for action triggered | ||
* | ||
* @param {Function} callback The callback to register as event handler | ||
* @param {Mixed} [optional] bindContext The context to bind the callback with | ||
* @returns {Function} Callback that unsubscribes the registered event handler | ||
*/ | ||
var listen = exports.listen = function listen(callback, bindContext) { | ||
bindContext = bindContext || this; | ||
var eventHandler = function eventHandler(args) { | ||
if (aborted) { | ||
return; | ||
} | ||
callback.apply(bindContext, args); | ||
}, | ||
me = this, | ||
aborted = false; | ||
this.emitter.addListener(this.eventLabel, eventHandler); | ||
return function () { | ||
aborted = true; | ||
me.emitter.removeListener(me.eventLabel, eventHandler); | ||
}; | ||
}; | ||
/** | ||
* Tries to publish the event on the next tick | ||
*/ | ||
triggerAsync: function triggerAsync() { | ||
var args = arguments, | ||
me = this; | ||
_.nextTick(function () { | ||
me.trigger.apply(me, args); | ||
}); | ||
}, | ||
/** | ||
* Wraps the trigger mechanism with a deferral function. | ||
* | ||
* @param {Function} callback the deferral function, | ||
* first argument is the resolving function and the | ||
* rest are the arguments provided from the previous | ||
* trigger invocation | ||
*/ | ||
deferWith: function deferWith(callback) { | ||
var oldTrigger = this.trigger, | ||
ctx = this, | ||
resolver = function resolver() { | ||
oldTrigger.apply(ctx, arguments); | ||
}; | ||
this.trigger = function () { | ||
callback.apply(ctx, [resolver].concat([].splice.call(arguments, 0))); | ||
}; | ||
/** | ||
* Publishes an event using `this.emitter` (if `shouldEmit` agrees) | ||
*/ | ||
var trigger = exports.trigger = function trigger() { | ||
var args = arguments, | ||
pre = this.preEmit.apply(this, args); | ||
args = pre === undefined ? args : _.isArguments(pre) ? pre : [].concat(pre); | ||
if (this.shouldEmit.apply(this, args)) { | ||
this.emitter.emit(this.eventLabel, args); | ||
} | ||
}; | ||
/** | ||
* Tries to publish the event on the next tick | ||
*/ | ||
var triggerAsync = exports.triggerAsync = function triggerAsync() { | ||
var args = arguments, | ||
me = this; | ||
_.nextTick(function () { | ||
me.trigger.apply(me, args); | ||
}); | ||
}; | ||
/** | ||
* Wraps the trigger mechanism with a deferral function. | ||
* | ||
* @param {Function} callback the deferral function, | ||
* first argument is the resolving function and the | ||
* rest are the arguments provided from the previous | ||
* trigger invocation | ||
*/ | ||
var deferWith = exports.deferWith = function deferWith(callback) { | ||
var oldTrigger = this.trigger, | ||
ctx = this, | ||
resolver = function resolver() { | ||
oldTrigger.apply(ctx, arguments); | ||
}; | ||
this.trigger = function () { | ||
callback.apply(ctx, [resolver].concat([].splice.call(arguments, 0))); | ||
}; | ||
}; |
@@ -5,9 +5,2 @@ "use strict"; | ||
value: true | ||
}); | ||
/** | ||
* A module of methods that you want to include in all stores. | ||
* This module is consumed by `createStore`. | ||
*/ | ||
var StoreMethods = {}; | ||
exports.default = StoreMethods; | ||
}); |
{ | ||
"name": "reflux-core", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A simple library for uni-directional dataflow application architecture inspired by ReactJS Flux", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
0
54702
834