Comparing version 1.0.3 to 1.0.4-rc1
@@ -10,2 +10,3 @@ /** | ||
var generateUUID = require('../utils/generateUUID'); | ||
var callAction = require('../utils/callAction'); | ||
@@ -83,34 +84,2 @@ var __DEV__ = process.env.NODE_ENV !== 'production'; | ||
/** | ||
* Executes an action, and calls either resolve or reject based on the callback result | ||
* This is extracted from FluxContext.prototype.executeAction to prevent this method de-optimising | ||
* due to the try/catch | ||
* @param {Object} actionContext FluxContext object | ||
* @param {Function} action Action to call | ||
* @param {Object} payload Payload for the action | ||
* @private | ||
*/ | ||
function callAction(actionContext, action, payload) { | ||
return new Promise(function (resolve, reject) { | ||
setImmediate(function () { | ||
try { | ||
var syncResult = action(actionContext, payload, function (err, result) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
if (isPromise(syncResult)) { | ||
syncResult.then(resolve, reject); | ||
} else if (action.length < 3) { | ||
resolve(syncResult); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Executes an action passing an action interface to as the first parameter | ||
@@ -130,4 +99,2 @@ * If a promise is returned by the action, it will wait for its resolution or rejection | ||
function executeActionProxy(context, actionContext, action, payload, done) { | ||
var displayName = action.displayName || action.name; | ||
payload = (undefined !== payload) ? payload : {}; | ||
if (__DEV__) { | ||
@@ -138,2 +105,6 @@ if (!action) { | ||
} | ||
} | ||
var displayName = action.displayName || action.name; | ||
payload = (undefined !== payload) ? payload : {}; | ||
if (__DEV__) { | ||
if (context._dispatcher && context._dispatcher.currentAction) { | ||
@@ -153,16 +124,3 @@ var currentActionDisplayName = context._dispatcher.currentAction.displayName || | ||
} | ||
var executeActionPromise = callAction(actionContext, action, payload); | ||
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); | ||
}); | ||
} | ||
return executeActionPromise; | ||
return callAction(actionContext, action, payload, done); | ||
} | ||
@@ -169,0 +127,0 @@ |
{ | ||
"name": "fluxible", | ||
"version": "1.0.3", | ||
"version": "1.0.4-rc1", | ||
"description": "A pluggable container for isomorphic flux applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,6 +38,6 @@ # Fluxible | ||
* [Yeoman generator](https://github.com/yahoo/generator-fluxible) | ||
* [Example Applications](https://github.com/yahoo/flux-examples) | ||
* [Fluxible Routing](https://github.com/yahoo/fluxible-router) | ||
* [Isomorphic Data Services](https://github.com/yahoo/fluxible-plugin-fetchr) | ||
* [Yeoman generator](https://github.com/yahoo/fluxible/blob/master/packages/generator-fluxible) | ||
* [Example Applications](https://github.com/yahoo/fluxible/blob/master/examples) | ||
* [Fluxible Routing](https://github.com/yahoo/fluxible/blob/master/packages/fluxible-router) | ||
* [Isomorphic Data Services](https://github.com/yahoo/fluxible/blob/master/packages/fluxible-plugin-fetchr) | ||
@@ -44,0 +44,0 @@ ## Usage |
@@ -9,2 +9,29 @@ /** | ||
function callActionInternal(actionContext, action, payload, resolve, reject) { | ||
try { | ||
var syncResult = action(actionContext, payload, function (err, result) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
if (isPromise(syncResult)) { | ||
syncResult.then(resolve, reject); | ||
} else if (action.length < 3) { | ||
resolve(syncResult); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function callActionNoImmediate(actionContext, action, payload, done) { | ||
var executeActionPromise = new Promise(function (resolve, reject) { | ||
callActionInternal(actionContext, action, payload, resolve, reject); | ||
}); | ||
return finalizeAction(executeActionPromise, done); | ||
} | ||
/** | ||
@@ -16,31 +43,26 @@ * Call an action supporting Promise expectations on invocation. | ||
*/ | ||
function callAction (action, context, payload, done) { | ||
if (typeof action !== 'function') { | ||
throw new Error('An action need to be a function'); | ||
} | ||
function callAction (actionContext, action, payload, done) { | ||
var executeActionPromise = new Promise(function (resolve, reject) { | ||
setImmediate(callActionInternal.bind(null, actionContext, action, payload, resolve, reject)); | ||
}); | ||
if (done) { | ||
return action(context, payload, done); | ||
} | ||
return finalizeAction(executeActionPromise, done); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
var syncResult = action(context, payload, function (err, result) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
if (isPromise(syncResult)) { | ||
syncResult.then(resolve, reject); | ||
} else if (action.length < 3) { | ||
resolve(syncResult); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
function finalizeAction(executeActionPromise, done) { | ||
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); | ||
}); | ||
} | ||
}); | ||
return executeActionPromise; | ||
} | ||
module.exports = callAction; | ||
module.exports.callActionNoImmediate = callActionNoImmediate; |
@@ -33,5 +33,5 @@ /** | ||
}); | ||
return callAction(action, this, payload, callback); | ||
return callAction.callActionNoImmediate(this, action, payload, callback); | ||
}; | ||
module.exports = MockActionContext; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
44082
736
2