Comparing version 1.3.0 to 1.4.0
# Change Log | ||
## 1.4.0 | ||
### Enhancement | ||
* [#537] Add config to allow removing second setImmediate wrapper around callback during action execution, so that there is less artifial yielding for most of the normal cases where callback function executes successfully with no exception. | ||
## 1.3.0 | ||
@@ -4,0 +10,0 @@ |
@@ -11,2 +11,3 @@ /** | ||
var dispatchr = require('dispatchr'); | ||
var promiseCallback = require('../utils/promiseCallback'); | ||
var __DEV__ = process.env.NODE_ENV !== 'production'; | ||
@@ -57,3 +58,4 @@ | ||
* @method createContext | ||
* @param {Object} [options] | ||
* @param {Object} [options] The options object. Please refer to FluxibleContext's constructor | ||
* doc for supported subfields and detailed description. | ||
* @returns {FluxibleContext} | ||
@@ -64,3 +66,3 @@ */ | ||
options = options || {}; | ||
var context = new FluxibleContext(self); | ||
var context = new FluxibleContext(self, options); | ||
@@ -174,3 +176,4 @@ // Plug context with app plugins that implement plugContext method | ||
* @param {Object} obj.plugins Dehydrated app plugin state | ||
* @param {Object} obj.context Dehydrated context state | ||
* @param {Object} obj.context Dehydrated context state. See FluxibleContext's | ||
* rehydrate() for subfields in this object. | ||
* @param {Function} callback | ||
@@ -210,3 +213,3 @@ * @async Rehydration may require more asset loading or async IO calls | ||
var context = self.createContext(); | ||
var context = self.createContext(obj.context && obj.context.options); | ||
var rehydratePromise = Promise.all(pluginTasks).then(function rehydratePluginTasks() { | ||
@@ -217,12 +220,3 @@ return context.rehydrate(obj.context || {}); | ||
if (callback) { | ||
rehydratePromise | ||
.then(function (contextValue) { | ||
callback(null, contextValue); | ||
}, function (err) { | ||
callback(err); | ||
})['catch'](function (err) { | ||
setImmediate(function () { | ||
throw err; | ||
}); | ||
}); | ||
promiseCallback(rehydratePromise, callback, {optimize: true}); | ||
} | ||
@@ -229,0 +223,0 @@ |
@@ -19,5 +19,13 @@ /** | ||
* @param {Fluxible} app The Fluxible instance used to create the context | ||
* @param {Object} options The options sharable by the context and context plugins | ||
* @param {Boolean} options.optimizePromiseCallback Whether to optimize Promise callback. | ||
* Defaults to `false`. `FluxibleContext` uses two setImmediate in utils/callAction | ||
* when executing every action. The second `setImmediate` wraps callback execution | ||
* to make sure exceptions thrown during callback execution are not swallowed by Promise. | ||
* This optimization eliminates the second `setImmediate` by catching errors caught by | ||
* Promise and throwing it. This way, successful callback executions won't need this extra | ||
* yielding because of the `setImmediate`. | ||
* @constructor | ||
*/ | ||
function FluxContext(app) { | ||
function FluxContext(app, options) { | ||
this._app = app; | ||
@@ -38,2 +46,4 @@ | ||
this._storeContext = null; | ||
this._optimizePromiseCallback = !!(options && options.optimizePromiseCallback); | ||
} | ||
@@ -190,4 +200,5 @@ | ||
displayName: displayName, | ||
stack: (parentActionContext.stack || []).concat([displayName]), | ||
rootId: (parentActionContext.rootId) || generateUUID() | ||
optimizePromiseCallback: this._optimizePromiseCallback, | ||
rootId: (parentActionContext.rootId) || generateUUID(), | ||
stack: (parentActionContext.stack || []).concat([displayName]) | ||
}); | ||
@@ -317,2 +328,5 @@ newActionContext.executeAction = newActionContext.executeAction.bind(newActionContext); | ||
dispatcher: (this._dispatcher && this._dispatcher.dehydrate()) || {}, | ||
options: { | ||
optimizePromiseCallback: this._optimizePromiseCallback | ||
}, | ||
plugins: {} | ||
@@ -335,2 +349,4 @@ }; | ||
* @param {Object} obj Configuration | ||
* @param {Object} obj.options Dehydrated context options | ||
* @param {Boolean} obj.options.optimizePromiseCallback Default to false. | ||
* @param {Object} obj.plugins Dehydrated context plugin state | ||
@@ -349,2 +365,3 @@ * @param {Object} obj.dispatcher Dehydrated dispatcher state | ||
obj.plugins = obj.plugins || {}; | ||
self._optimizePromiseCallback = !!(obj.options && obj.options.optimizePromiseCallback); | ||
var pluginTasks = self._plugins.filter(function (plugin) { | ||
@@ -351,0 +368,0 @@ return 'function' === typeof plugin.rehydrate |
{ | ||
"name": "fluxible", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A pluggable container for isomorphic flux applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,3 @@ /** | ||
var isPromise = require('is-promise'); | ||
var promiseCallback = require('./promiseCallback'); | ||
require('setimmediate'); | ||
@@ -40,10 +41,3 @@ | ||
if (done) { | ||
executeActionPromise | ||
.then(function(result) { | ||
// Ensures that errors in callback are not swallowed by promise | ||
setImmediate(done, null, result); | ||
}, function (err) { | ||
// Ensures that errors in callback are not swallowed by promise | ||
setImmediate(done, err); | ||
}); | ||
promiseCallback(executeActionPromise, done, {optimize: actionContext.optimizePromiseCallback}); | ||
} | ||
@@ -50,0 +44,0 @@ |
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
47911
20
792