@modern-js-reduck/plugin-effects
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -5,7 +5,19 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import { createPromise } from 'redux-promise-middleware'; | ||
import thunk from 'redux-thunk'; | ||
const isReduxPromiseFulfilled = data => { | ||
return typeof data === 'object' && data.action && data.value; | ||
}; | ||
const isPromise = value => { | ||
if (value !== null && typeof value === 'object') { | ||
return value && typeof value.then === 'function'; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Generate dispatch action from effects definitions. | ||
*/ | ||
const createDispatchActionsFromEffects = (store, name, effects, setDispatchAction) => { | ||
@@ -27,4 +39,11 @@ const path = [name]; | ||
if (value instanceof Promise || typeof value === 'function') { | ||
return dispatch(value); | ||
if (isPromise(value) || typeof value === 'function') { | ||
const res = dispatch(value); | ||
if (isPromise(res)) { | ||
// parse redux-promise result, return orginal value of the effect | ||
return res.then(data => isReduxPromiseFulfilled(data) ? data.value : data); | ||
} | ||
return res; | ||
} | ||
@@ -49,6 +68,6 @@ | ||
return _extends({}, storeConfig, { | ||
middlewares: [...(storeConfig.middlewares || []), createPromise({ | ||
middlewares: [createPromise({ | ||
promiseTypeDelimiter: '/' | ||
}), thunk // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects | ||
] | ||
}), // middlewares from config are at the end | ||
...(storeConfig.middlewares || [])] | ||
}); | ||
@@ -55,0 +74,0 @@ }, |
@@ -12,6 +12,2 @@ "use strict"; | ||
var _reduxThunk = _interopRequireDefault(require("redux-thunk")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
@@ -23,5 +19,18 @@ | ||
const isReduxPromiseFulfilled = data => { | ||
return typeof data === 'object' && data.action && data.value; | ||
}; | ||
const isPromise = value => { | ||
if (value !== null && typeof value === 'object') { | ||
return value && typeof value.then === 'function'; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Generate dispatch action from effects definitions. | ||
*/ | ||
const createDispatchActionsFromEffects = (store, name, effects, setDispatchAction) => { | ||
@@ -43,4 +52,11 @@ const path = [name]; | ||
if (value instanceof Promise || typeof value === 'function') { | ||
return dispatch(value); | ||
if (isPromise(value) || typeof value === 'function') { | ||
const res = dispatch(value); | ||
if (isPromise(res)) { | ||
// parse redux-promise result, return orginal value of the effect | ||
return res.then(data => isReduxPromiseFulfilled(data) ? data.value : data); | ||
} | ||
return res; | ||
} | ||
@@ -65,6 +81,6 @@ | ||
return _objectSpread(_objectSpread({}, storeConfig), {}, { | ||
middlewares: [...(storeConfig.middlewares || []), (0, _reduxPromiseMiddleware.createPromise)({ | ||
middlewares: [(0, _reduxPromiseMiddleware.createPromise)({ | ||
promiseTypeDelimiter: '/' | ||
}), _reduxThunk.default // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects | ||
] | ||
}), // middlewares from config are at the end | ||
...(storeConfig.middlewares || [])] | ||
}); | ||
@@ -71,0 +87,0 @@ }, |
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { createPlugin } from '@modern-js-reduck/store'; | ||
import { createPromise } from 'redux-promise-middleware'; | ||
import thunk from 'redux-thunk'; | ||
const isReduxPromiseFulfilled = data => { | ||
return typeof data === 'object' && data.action && data.value; | ||
}; | ||
const isPromise = value => { | ||
if (value !== null && typeof value === 'object') { | ||
return value && typeof value.then === 'function'; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Generate dispatch action from effects definitions. | ||
*/ | ||
const createDispatchActionsFromEffects = (store, name, effects, setDispatchAction) => { | ||
@@ -25,4 +37,11 @@ const path = [name]; | ||
if (value instanceof Promise || typeof value === 'function') { | ||
return dispatch(value); | ||
if (isPromise(value) || typeof value === 'function') { | ||
const res = dispatch(value); | ||
if (isPromise(res)) { | ||
// parse redux-promise result, return orginal value of the effect | ||
return res.then(data => isReduxPromiseFulfilled(data) ? data.value : data); | ||
} | ||
return res; | ||
} | ||
@@ -47,6 +66,6 @@ | ||
return _extends({}, storeConfig, { | ||
middlewares: [...(storeConfig.middlewares || []), createPromise({ | ||
middlewares: [createPromise({ | ||
promiseTypeDelimiter: '/' | ||
}), thunk // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects | ||
] | ||
}), // middlewares from config are at the end | ||
...(storeConfig.middlewares || [])] | ||
}); | ||
@@ -53,0 +72,0 @@ }, |
@@ -9,7 +9,7 @@ interface Config { | ||
} | ||
export default function handleEffect(config?: Config): { | ||
pending: (state: any) => any; | ||
fulfilled: (state: any, payload: any) => any; | ||
rejected: (state: any, error: any) => any; | ||
export default function handleEffect<State = any, Payload = any, Error = string>(config?: Config): { | ||
pending: (state: State) => State | void; | ||
fulfilled: (state: State, payload: Payload) => State | void; | ||
rejected: (state: State, error: Error) => State | void; | ||
}; | ||
export {}; |
{ | ||
"name": "@modern-js-reduck/plugin-effects", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"files": [ | ||
@@ -36,7 +36,6 @@ "dist" | ||
"redux": "^4.1.1", | ||
"redux-promise-middleware": "^6.1.2", | ||
"redux-thunk": "^2.3.0" | ||
"redux-promise-middleware": "^6.1.2" | ||
}, | ||
"devDependencies": { | ||
"@modern-js-reduck/store": "1.0.6", | ||
"@modern-js-reduck/store": "1.1.0", | ||
"@modern-js/module-tools": "^1.7.1", | ||
@@ -54,3 +53,3 @@ "@modern-js/plugin-testing": "^1.6.0", | ||
"peerDependencies": { | ||
"@modern-js-reduck/store": "^1.0.6" | ||
"@modern-js-reduck/store": "^1.1.0" | ||
}, | ||
@@ -57,0 +56,0 @@ "publishConfig": { |
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
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
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
55639
4
1697
1
- Removedredux-thunk@^2.3.0
- Removedredux-thunk@2.4.2(transitive)