redux-saga-resources
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -13,3 +13,3 @@ 'use strict'; | ||
function reducer(descriptor) { | ||
function reducer(descriptor, options) { | ||
var actions = descriptor.actions; | ||
@@ -36,3 +36,3 @@ | ||
{ | ||
return _extends({}, state, { opened: false, loading: false, error: null, item: _extends({}, state.item, action.payload.item) }); | ||
return _extends({}, state, { opened: options.createImmediately, loading: false, error: null, item: _extends({}, state.item, action.payload.item) }); | ||
} | ||
@@ -39,0 +39,0 @@ case actions.CREATE_FAILURE: |
@@ -62,3 +62,3 @@ 'use strict'; | ||
return regeneratorRuntime.mark(function _callee4(action) { | ||
var item, _item, editing, _item2, _editing, _item3, _editing2, _item4, _editing3; | ||
var item, _item, editing, _item2, _editing, _item3, _editing2, _item4, _editing3, _item5, _editing4; | ||
@@ -83,3 +83,3 @@ return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
case 6: | ||
_context4.next = 83; | ||
_context4.next = 108; | ||
break; | ||
@@ -89,3 +89,3 @@ | ||
if (!(action.type === descriptor.actions.CREATE)) { | ||
_context4.next = 20; | ||
_context4.next = 30; | ||
break; | ||
@@ -95,3 +95,3 @@ } | ||
if (!options.createImmediately) { | ||
_context4.next = 18; | ||
_context4.next = 20; | ||
break; | ||
@@ -112,123 +112,153 @@ } | ||
case 18: | ||
_context4.next = 83; | ||
_context4.next = 28; | ||
break; | ||
case 20: | ||
_context4.t4 = _effects.put; | ||
_context4.t5 = descriptor.creators; | ||
_context4.next = 24; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 24: | ||
_context4.t6 = _context4.sent; | ||
_context4.t7 = _context4.t5.doCreateSuccess.call(_context4.t5, _context4.t6); | ||
_context4.next = 28; | ||
return (0, _context4.t4)(_context4.t7); | ||
case 28: | ||
_context4.next = 108; | ||
break; | ||
case 30: | ||
if (!(action.type === descriptor.actions.CREATE_FAILURE)) { | ||
_context4.next = 25; | ||
_context4.next = 35; | ||
break; | ||
} | ||
_context4.next = 23; | ||
_context4.next = 33; | ||
return (0, _effects.put)(resource.creators.doCreateFailure(action.payload.item, action.payload.reason)); | ||
case 23: | ||
_context4.next = 83; | ||
case 33: | ||
_context4.next = 108; | ||
break; | ||
case 25: | ||
case 35: | ||
if (!(action.type === descriptor.actions.UPDATE)) { | ||
_context4.next = 30; | ||
_context4.next = 45; | ||
break; | ||
} | ||
_context4.next = 28; | ||
if (!options.createImmediately) { | ||
_context4.next = 41; | ||
break; | ||
} | ||
_context4.next = 39; | ||
return (0, _effects.put)(resource.creators.doUpdate(action.payload.item)); | ||
case 28: | ||
_context4.next = 83; | ||
case 39: | ||
_context4.next = 43; | ||
break; | ||
case 30: | ||
case 41: | ||
_context4.next = 43; | ||
return (0, _effects.put)(resource.creators.doCreate(action.payload.item)); | ||
case 43: | ||
_context4.next = 108; | ||
break; | ||
case 45: | ||
if (!(action.type === descriptor.actions.UPDATE_FAILURE)) { | ||
_context4.next = 35; | ||
_context4.next = 50; | ||
break; | ||
} | ||
_context4.next = 33; | ||
_context4.next = 48; | ||
return (0, _effects.put)(resource.creators.doUpdateFailure(action.payload.item, action.payload.reason)); | ||
case 33: | ||
_context4.next = 83; | ||
case 48: | ||
_context4.next = 108; | ||
break; | ||
case 35: | ||
case 50: | ||
if (!(action.type === descriptor.actions.DELETE)) { | ||
_context4.next = 40; | ||
_context4.next = 55; | ||
break; | ||
} | ||
_context4.next = 38; | ||
_context4.next = 53; | ||
return (0, _effects.put)(resource.creators.doDelete(action.payload.item)); | ||
case 38: | ||
_context4.next = 83; | ||
case 53: | ||
_context4.next = 108; | ||
break; | ||
case 40: | ||
case 55: | ||
if (!(action.type === descriptor.actions.DELETE_FAILURE)) { | ||
_context4.next = 45; | ||
_context4.next = 60; | ||
break; | ||
} | ||
_context4.next = 43; | ||
_context4.next = 58; | ||
return (0, _effects.put)(resource.creators.doDeleteFailure(action.payload.item, action.payload.reason)); | ||
case 43: | ||
_context4.next = 83; | ||
case 58: | ||
_context4.next = 108; | ||
break; | ||
case 45: | ||
case 60: | ||
if (!(action.type === resource.actions.CREATE_SUCCESS)) { | ||
_context4.next = 55; | ||
_context4.next = 80; | ||
break; | ||
} | ||
if (!options.createImmediately) { | ||
_context4.next = 71; | ||
break; | ||
} | ||
_item = action.payload.item; | ||
_context4.next = 49; | ||
_context4.next = 65; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 49: | ||
case 65: | ||
editing = _context4.sent; | ||
if (!resource.hasSameId(editing, _item)) { | ||
_context4.next = 53; | ||
_context4.next = 69; | ||
break; | ||
} | ||
_context4.next = 53; | ||
_context4.next = 69; | ||
return (0, _effects.put)(descriptor.creators.doCreateSuccess(_item)); | ||
case 53: | ||
_context4.next = 83; | ||
case 69: | ||
_context4.next = 78; | ||
break; | ||
case 55: | ||
if (!(action.type === resource.actions.READ_SUCCESS)) { | ||
_context4.next = 65; | ||
break; | ||
} | ||
case 71: | ||
// Delayed create. | ||
_item2 = action.payload.item; | ||
_context4.next = 59; | ||
_context4.next = 74; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 59: | ||
case 74: | ||
_editing = _context4.sent; | ||
if (!resource.hasSameId(_editing, _item2)) { | ||
_context4.next = 63; | ||
_context4.next = 78; | ||
break; | ||
} | ||
_context4.next = 63; | ||
return (0, _effects.put)(descriptor.creators.doReadSuccess(_item2)); | ||
_context4.next = 78; | ||
return (0, _effects.put)(descriptor.creators.doUpdateSuccess(_item2)); | ||
case 63: | ||
_context4.next = 83; | ||
case 78: | ||
_context4.next = 108; | ||
break; | ||
case 65: | ||
if (!(action.type === resource.actions.UPDATE_SUCCESS)) { | ||
_context4.next = 75; | ||
case 80: | ||
if (!(action.type === resource.actions.READ_SUCCESS)) { | ||
_context4.next = 90; | ||
break; | ||
@@ -238,23 +268,23 @@ } | ||
_item3 = action.payload.item; | ||
_context4.next = 69; | ||
_context4.next = 84; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 69: | ||
case 84: | ||
_editing2 = _context4.sent; | ||
if (!resource.hasSameId(_editing2, _item3)) { | ||
_context4.next = 73; | ||
_context4.next = 88; | ||
break; | ||
} | ||
_context4.next = 73; | ||
return (0, _effects.put)(descriptor.creators.doUpdateSuccess(_item3)); | ||
_context4.next = 88; | ||
return (0, _effects.put)(descriptor.creators.doReadSuccess(_item3)); | ||
case 73: | ||
_context4.next = 83; | ||
case 88: | ||
_context4.next = 108; | ||
break; | ||
case 75: | ||
if (!(action.type === resource.actions.DELETE_SUCCESS)) { | ||
_context4.next = 83; | ||
case 90: | ||
if (!(action.type === resource.actions.UPDATE_SUCCESS)) { | ||
_context4.next = 100; | ||
break; | ||
@@ -264,17 +294,42 @@ } | ||
_item4 = action.payload.item; | ||
_context4.next = 79; | ||
_context4.next = 94; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 79: | ||
case 94: | ||
_editing3 = _context4.sent; | ||
if (!resource.hasSameId(_editing3, _item4)) { | ||
_context4.next = 83; | ||
_context4.next = 98; | ||
break; | ||
} | ||
_context4.next = 83; | ||
return (0, _effects.put)(descriptor.creators.doDeleteSuccess(_item4)); | ||
_context4.next = 98; | ||
return (0, _effects.put)(descriptor.creators.doUpdateSuccess(_item4)); | ||
case 83: | ||
case 98: | ||
_context4.next = 108; | ||
break; | ||
case 100: | ||
if (!(action.type === resource.actions.DELETE_SUCCESS)) { | ||
_context4.next = 108; | ||
break; | ||
} | ||
_item5 = action.payload.item; | ||
_context4.next = 104; | ||
return (0, _effects.select)(descriptor.selectors.item); | ||
case 104: | ||
_editing4 = _context4.sent; | ||
if (!resource.hasSameId(_editing4, _item5)) { | ||
_context4.next = 108; | ||
break; | ||
} | ||
_context4.next = 108; | ||
return (0, _effects.put)(descriptor.creators.doDeleteSuccess(_item5)); | ||
case 108: | ||
case 'end': | ||
@@ -281,0 +336,0 @@ return _context4.stop(); |
@@ -128,3 +128,3 @@ 'use strict'; | ||
return _extends({}, descriptor, { | ||
reducer: (0, _reducer4.default)(descriptor), | ||
reducer: (0, _reducer4.default)(descriptor, options), | ||
saga: _saga4.default.apply(undefined, [descriptor, options].concat(middlewares.map(function (f) { | ||
@@ -131,0 +131,0 @@ return f(descriptor); |
{ | ||
"name": "redux-saga-resources", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist", |
import { makeTempKey } from '../tempKey'; | ||
import { fields, stripFields } from '../fields'; | ||
export default function reducer(descriptor) { | ||
export default function reducer(descriptor, options) { | ||
const { actions } = descriptor; | ||
@@ -18,3 +18,3 @@ return (state = { opened: false, loading: false, error: null, item: {} }, action) => { | ||
case actions.CREATE_SUCCESS: { | ||
return { ...state, opened: false, loading: false, error: null, item: { ...state.item, ...action.payload.item } }; | ||
return { ...state, opened: options.createImmediately, loading: false, error: null, item: { ...state.item, ...action.payload.item } }; | ||
} | ||
@@ -21,0 +21,0 @@ case actions.CREATE_FAILURE: { |
@@ -29,32 +29,40 @@ import { | ||
yield put(descriptor.creators.doEdit(item)); | ||
} | ||
else if (action.type === descriptor.actions.CREATE) { | ||
} else if (action.type === descriptor.actions.CREATE) { | ||
if (options.createImmediately) { | ||
yield put(resource.creators.doCreate(yield select(descriptor.selectors.item))); | ||
} else { | ||
// Delayed create. | ||
yield put(descriptor.creators.doCreateSuccess(yield select(descriptor.selectors.item))); | ||
} | ||
} | ||
else if (action.type === descriptor.actions.CREATE_FAILURE) { | ||
} else if (action.type === descriptor.actions.CREATE_FAILURE) { | ||
yield put(resource.creators.doCreateFailure(action.payload.item, action.payload.reason)); | ||
} | ||
else if (action.type === descriptor.actions.UPDATE) { | ||
yield put(resource.creators.doUpdate(action.payload.item)); | ||
} | ||
else if (action.type === descriptor.actions.UPDATE_FAILURE) { | ||
} else if (action.type === descriptor.actions.UPDATE) { | ||
if (options.createImmediately) { | ||
yield put(resource.creators.doUpdate(action.payload.item)); | ||
} else { | ||
// Delayed create. | ||
yield put(resource.creators.doCreate(action.payload.item)); | ||
} | ||
} else if (action.type === descriptor.actions.UPDATE_FAILURE) { | ||
yield put(resource.creators.doUpdateFailure(action.payload.item, action.payload.reason)); | ||
} | ||
else if (action.type === descriptor.actions.DELETE) { | ||
} else if (action.type === descriptor.actions.DELETE) { | ||
yield put(resource.creators.doDelete(action.payload.item)); | ||
} | ||
else if (action.type === descriptor.actions.DELETE_FAILURE) { | ||
} else if (action.type === descriptor.actions.DELETE_FAILURE) { | ||
yield put(resource.creators.doDeleteFailure(action.payload.item, action.payload.reason)); | ||
} | ||
else if (action.type === resource.actions.CREATE_SUCCESS) { | ||
const item = action.payload.item; | ||
const editing = yield select(descriptor.selectors.item); | ||
if (resource.hasSameId(editing, item)) { | ||
yield put(descriptor.creators.doCreateSuccess(item)); | ||
} else if (action.type === resource.actions.CREATE_SUCCESS) { | ||
if (options.createImmediately) { | ||
const item = action.payload.item; | ||
const editing = yield select(descriptor.selectors.item); | ||
if (resource.hasSameId(editing, item)) { | ||
yield put(descriptor.creators.doCreateSuccess(item)); | ||
} | ||
} else { | ||
// Delayed create. | ||
const item = action.payload.item; | ||
const editing = yield select(descriptor.selectors.item); | ||
if (resource.hasSameId(editing, item)) { | ||
yield put(descriptor.creators.doUpdateSuccess(item)); | ||
} | ||
} | ||
} | ||
else if (action.type === resource.actions.READ_SUCCESS) { | ||
} else if (action.type === resource.actions.READ_SUCCESS) { | ||
const item = action.payload.item; | ||
@@ -65,4 +73,3 @@ const editing = yield select(descriptor.selectors.item); | ||
} | ||
} | ||
else if (action.type === resource.actions.UPDATE_SUCCESS) { | ||
} else if (action.type === resource.actions.UPDATE_SUCCESS) { | ||
const item = action.payload.item; | ||
@@ -73,4 +80,3 @@ const editing = yield select(descriptor.selectors.item); | ||
} | ||
} | ||
else if (action.type === resource.actions.DELETE_SUCCESS) { | ||
} else if (action.type === resource.actions.DELETE_SUCCESS) { | ||
const item = action.payload.item; | ||
@@ -110,19 +116,19 @@ const editing = yield select(descriptor.selectors.item); | ||
resource.actions.CREATE, | ||
resource.actions.CREATE_CANCEL, | ||
resource.actions.CREATE_SUCCESS, | ||
resource.actions.CREATE_FAILURE, | ||
resource.actions.READ, | ||
resource.actions.READ_CANCEL, | ||
resource.actions.READ_SUCCESS, | ||
resource.actions.READ_FAILURE, | ||
resource.actions.UPDATE, | ||
resource.actions.UPDATE_CANCEL, | ||
resource.actions.UPDATE_SUCCESS, | ||
resource.actions.UPDATE_FAILURE, | ||
resource.actions.DELETE, | ||
resource.actions.DELETE_CANCEL, | ||
resource.actions.DELETE_SUCCESS, | ||
resource.actions.DELETE_FAILURE, | ||
resource.actions.RESET | ||
resource.actions.CREATE, | ||
resource.actions.CREATE_CANCEL, | ||
resource.actions.CREATE_SUCCESS, | ||
resource.actions.CREATE_FAILURE, | ||
resource.actions.READ, | ||
resource.actions.READ_CANCEL, | ||
resource.actions.READ_SUCCESS, | ||
resource.actions.READ_FAILURE, | ||
resource.actions.UPDATE, | ||
resource.actions.UPDATE_CANCEL, | ||
resource.actions.UPDATE_SUCCESS, | ||
resource.actions.UPDATE_FAILURE, | ||
resource.actions.DELETE, | ||
resource.actions.DELETE_CANCEL, | ||
resource.actions.DELETE_SUCCESS, | ||
resource.actions.DELETE_FAILURE, | ||
resource.actions.RESET | ||
]; | ||
@@ -129,0 +135,0 @@ const f = applyMiddlewares(...middlewares, defaultMiddleware(descriptor, options)); |
@@ -93,3 +93,3 @@ import { | ||
...descriptor, | ||
reducer: makeEditorReducer(descriptor), | ||
reducer: makeEditorReducer(descriptor, options), | ||
saga: makeEditorSaga(descriptor, options, ...middlewares.map(f => f(descriptor))) | ||
@@ -96,0 +96,0 @@ } |
Sorry, the diff of this file is not supported yet
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
2675
183391