redux-saga-resources
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -58,3 +58,3 @@ 'use strict'; | ||
function defaultMiddleware(descriptor) { | ||
function defaultMiddleware(descriptor, options) { | ||
var resource = descriptor.resource; | ||
@@ -83,3 +83,3 @@ | ||
case 6: | ||
_context4.next = 82; | ||
_context4.next = 83; | ||
break; | ||
@@ -89,89 +89,94 @@ | ||
if (!(action.type === descriptor.actions.CREATE)) { | ||
_context4.next = 19; | ||
_context4.next = 20; | ||
break; | ||
} | ||
if (!options.createImmediately) { | ||
_context4.next = 18; | ||
break; | ||
} | ||
_context4.t0 = _effects.put; | ||
_context4.t1 = resource.creators; | ||
_context4.next = 13; | ||
_context4.next = 14; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 13: | ||
case 14: | ||
_context4.t2 = _context4.sent; | ||
_context4.t3 = _context4.t1.doCreate.call(_context4.t1, _context4.t2); | ||
_context4.next = 17; | ||
_context4.next = 18; | ||
return (0, _context4.t0)(_context4.t3); | ||
case 17: | ||
_context4.next = 82; | ||
case 18: | ||
_context4.next = 83; | ||
break; | ||
case 19: | ||
case 20: | ||
if (!(action.type === descriptor.actions.CREATE_FAILURE)) { | ||
_context4.next = 24; | ||
_context4.next = 25; | ||
break; | ||
} | ||
_context4.next = 22; | ||
_context4.next = 23; | ||
return (0, _effects.put)(resource.creators.doCreateFailure(action.payload.item, action.payload.reason)); | ||
case 22: | ||
_context4.next = 82; | ||
case 23: | ||
_context4.next = 83; | ||
break; | ||
case 24: | ||
case 25: | ||
if (!(action.type === descriptor.actions.UPDATE)) { | ||
_context4.next = 29; | ||
_context4.next = 30; | ||
break; | ||
} | ||
_context4.next = 27; | ||
_context4.next = 28; | ||
return (0, _effects.put)(resource.creators.doUpdate(action.payload.item)); | ||
case 27: | ||
_context4.next = 82; | ||
case 28: | ||
_context4.next = 83; | ||
break; | ||
case 29: | ||
case 30: | ||
if (!(action.type === descriptor.actions.UPDATE_FAILURE)) { | ||
_context4.next = 34; | ||
_context4.next = 35; | ||
break; | ||
} | ||
_context4.next = 32; | ||
_context4.next = 33; | ||
return (0, _effects.put)(resource.creators.doUpdateFailure(action.payload.item, action.payload.reason)); | ||
case 32: | ||
_context4.next = 82; | ||
case 33: | ||
_context4.next = 83; | ||
break; | ||
case 34: | ||
case 35: | ||
if (!(action.type === descriptor.actions.DELETE)) { | ||
_context4.next = 39; | ||
_context4.next = 40; | ||
break; | ||
} | ||
_context4.next = 37; | ||
_context4.next = 38; | ||
return (0, _effects.put)(resource.creators.doDelete(action.payload.item)); | ||
case 37: | ||
_context4.next = 82; | ||
case 38: | ||
_context4.next = 83; | ||
break; | ||
case 39: | ||
case 40: | ||
if (!(action.type === descriptor.actions.DELETE_FAILURE)) { | ||
_context4.next = 44; | ||
_context4.next = 45; | ||
break; | ||
} | ||
_context4.next = 42; | ||
_context4.next = 43; | ||
return (0, _effects.put)(resource.creators.doDeleteFailure(action.payload.item, action.payload.reason)); | ||
case 42: | ||
_context4.next = 82; | ||
case 43: | ||
_context4.next = 83; | ||
break; | ||
case 44: | ||
case 45: | ||
if (!(action.type === resource.actions.CREATE_SUCCESS)) { | ||
_context4.next = 54; | ||
_context4.next = 55; | ||
break; | ||
@@ -181,23 +186,23 @@ } | ||
_item = action.payload.item; | ||
_context4.next = 48; | ||
_context4.next = 49; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 48: | ||
case 49: | ||
editing = _context4.sent; | ||
if (!resource.hasSameId(editing, _item)) { | ||
_context4.next = 52; | ||
_context4.next = 53; | ||
break; | ||
} | ||
_context4.next = 52; | ||
_context4.next = 53; | ||
return (0, _effects.put)(descriptor.creators.doCreateSuccess(_item)); | ||
case 52: | ||
_context4.next = 82; | ||
case 53: | ||
_context4.next = 83; | ||
break; | ||
case 54: | ||
case 55: | ||
if (!(action.type === resource.actions.READ_SUCCESS)) { | ||
_context4.next = 64; | ||
_context4.next = 65; | ||
break; | ||
@@ -207,23 +212,23 @@ } | ||
_item2 = action.payload.item; | ||
_context4.next = 58; | ||
_context4.next = 59; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 58: | ||
case 59: | ||
_editing = _context4.sent; | ||
if (!resource.hasSameId(_editing, _item2)) { | ||
_context4.next = 62; | ||
_context4.next = 63; | ||
break; | ||
} | ||
_context4.next = 62; | ||
_context4.next = 63; | ||
return (0, _effects.put)(descriptor.creators.doReadSuccess(_item2)); | ||
case 62: | ||
_context4.next = 82; | ||
case 63: | ||
_context4.next = 83; | ||
break; | ||
case 64: | ||
case 65: | ||
if (!(action.type === resource.actions.UPDATE_SUCCESS)) { | ||
_context4.next = 74; | ||
_context4.next = 75; | ||
break; | ||
@@ -233,23 +238,23 @@ } | ||
_item3 = action.payload.item; | ||
_context4.next = 68; | ||
_context4.next = 69; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 68: | ||
case 69: | ||
_editing2 = _context4.sent; | ||
if (!resource.hasSameId(_editing2, _item3)) { | ||
_context4.next = 72; | ||
_context4.next = 73; | ||
break; | ||
} | ||
_context4.next = 72; | ||
_context4.next = 73; | ||
return (0, _effects.put)(descriptor.creators.doUpdateSuccess(_item3)); | ||
case 72: | ||
_context4.next = 82; | ||
case 73: | ||
_context4.next = 83; | ||
break; | ||
case 74: | ||
case 75: | ||
if (!(action.type === resource.actions.DELETE_SUCCESS)) { | ||
_context4.next = 82; | ||
_context4.next = 83; | ||
break; | ||
@@ -259,17 +264,17 @@ } | ||
_item4 = action.payload.item; | ||
_context4.next = 78; | ||
_context4.next = 79; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 78: | ||
case 79: | ||
_editing3 = _context4.sent; | ||
if (!resource.hasSameId(_editing3, _item4)) { | ||
_context4.next = 82; | ||
_context4.next = 83; | ||
break; | ||
} | ||
_context4.next = 82; | ||
_context4.next = 83; | ||
return (0, _effects.put)(descriptor.creators.doDeleteSuccess(_item4)); | ||
case 82: | ||
case 83: | ||
case 'end': | ||
@@ -283,3 +288,3 @@ return _context4.stop(); | ||
function makeSaga(descriptor) { | ||
function makeSaga(descriptor, options) { | ||
var resource = descriptor.resource; | ||
@@ -289,7 +294,7 @@ | ||
for (var _len2 = arguments.length, middlewares = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
middlewares[_key2 - 1] = arguments[_key2]; | ||
for (var _len2 = arguments.length, middlewares = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
middlewares[_key2 - 2] = arguments[_key2]; | ||
} | ||
var f = applyMiddlewares.apply(undefined, middlewares.concat([defaultMiddleware(descriptor)])); | ||
var f = applyMiddlewares.apply(undefined, middlewares.concat([defaultMiddleware(descriptor, options)])); | ||
return regeneratorRuntime.mark(function internal() { | ||
@@ -296,0 +301,0 @@ return regeneratorRuntime.wrap(function internal$(_context5) { |
@@ -110,3 +110,4 @@ 'use strict'; | ||
options = _extends({ | ||
id: 'id' | ||
id: 'id', | ||
createImmediately: true | ||
}, options); | ||
@@ -129,3 +130,3 @@ | ||
reducer: (0, _reducer4.default)(descriptor), | ||
saga: _saga4.default.apply(undefined, [descriptor].concat(middlewares.map(function (f) { | ||
saga: _saga4.default.apply(undefined, [descriptor, options].concat(middlewares.map(function (f) { | ||
return f(descriptor); | ||
@@ -132,0 +133,0 @@ }))) |
@@ -163,2 +163,6 @@ declare module "redux-saga-resources" { | ||
} | ||
interface IEditorOptions { | ||
createImmediately?: boolean; | ||
id?: string; | ||
} | ||
interface IEditorDescriptor { | ||
@@ -183,9 +187,17 @@ name: string; | ||
interface IOptions { | ||
interface IResourceOptions { | ||
id?: string; | ||
} | ||
function createResource(name, options: IOptions, ...middlewares: IMiddlewareFactory[]): IResource; | ||
function createEditor(name, options: IOptions, resource: IResource): IEditor; | ||
function httpMiddleware(api, path): IMiddlewareFactory; | ||
interface IHttpApiHandler { | ||
get(path: string); | ||
post(path: string, entity: any); | ||
patch(path: string, entity: any); | ||
put(path: string, entity: any); | ||
del(path: string, entity: any); | ||
} | ||
function createResource(name: string, options: IResourceOptions, ...middlewares: IMiddlewareFactory[]): IResource; | ||
function createEditor(name: string, options: IEditorOptions, resource: IResource): IEditor; | ||
function httpMiddleware(api: IHttpApiHandler, path: string): IMiddlewareFactory; | ||
} |
{ | ||
"name": "redux-saga-resources", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist", |
@@ -21,3 +21,3 @@ import { | ||
function defaultMiddleware(descriptor) { | ||
function defaultMiddleware(descriptor, options) { | ||
const { | ||
@@ -32,3 +32,5 @@ resource | ||
else if (action.type === descriptor.actions.CREATE) { | ||
yield put(resource.creators.doCreate(yield select(descriptor.selectors.item))); | ||
if (options.createImmediately) { | ||
yield put(resource.creators.doCreate(yield select(descriptor.selectors.item))); | ||
} | ||
} | ||
@@ -82,3 +84,3 @@ else if (action.type === descriptor.actions.CREATE_FAILURE) { | ||
export default function makeSaga(descriptor, ...middlewares) { | ||
export default function makeSaga(descriptor, options, ...middlewares) { | ||
const { | ||
@@ -126,3 +128,3 @@ resource | ||
]; | ||
const f = applyMiddlewares(...middlewares, defaultMiddleware(descriptor)); | ||
const f = applyMiddlewares(...middlewares, defaultMiddleware(descriptor, options)); | ||
return function* internal() { | ||
@@ -129,0 +131,0 @@ yield takeEvery(actions, f); |
@@ -78,2 +78,3 @@ import { | ||
id: 'id', | ||
createImmediately: true, | ||
...options | ||
@@ -94,3 +95,3 @@ } | ||
reducer: makeEditorReducer(descriptor), | ||
saga: makeEditorSaga(descriptor, ...middlewares.map(f => f(descriptor))) | ||
saga: makeEditorSaga(descriptor, options, ...middlewares.map(f => f(descriptor))) | ||
} | ||
@@ -97,0 +98,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
184302
2625
0