@jfront/core-redux-saga
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -21,2 +21,10 @@ "use strict"; | ||
var _createOptionsSlice = require("./slice/createOptionsSlice"); | ||
Object.keys(_createOptionsSlice).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _createOptionsSlice[key]) return; | ||
exports[key] = _createOptionsSlice[key]; | ||
}); | ||
var _types = require("./types"); | ||
@@ -23,0 +31,0 @@ |
@@ -62,3 +62,3 @@ "use strict"; | ||
state.isLoading = false; | ||
state.error = action.error; | ||
state.error = action.payload.error; | ||
} | ||
@@ -76,4 +76,3 @@ }, reducers), | ||
_marked5 = /*#__PURE__*/regeneratorRuntime.mark(setCurrentRecord), | ||
_marked6 = /*#__PURE__*/regeneratorRuntime.mark(selectRecords), | ||
_marked7 = /*#__PURE__*/regeneratorRuntime.mark(entityWatcher); | ||
_marked6 = /*#__PURE__*/regeneratorRuntime.mark(selectRecords); | ||
@@ -143,3 +142,3 @@ function create(action) { | ||
_context2.next = 3; | ||
return (0, _effects.call)(api.update, String(action.payload.primaryKey), action.payload.values); | ||
return (0, _effects.call)(api.update, action.payload.primaryKey, action.payload.values); | ||
@@ -199,3 +198,3 @@ case 3: | ||
return (0, _effects.all)(action.payload.primaryKeys.map(function (primaryKey) { | ||
return (0, _effects.call)(api["delete"], String(primaryKey)); | ||
return (0, _effects.call)(api["delete"], primaryKey); | ||
})); | ||
@@ -253,3 +252,3 @@ | ||
_context4.next = 3; | ||
return (0, _effects.call)(api.getRecordById, String(action.payload.primaryKey)); | ||
return (0, _effects.call)(api.getRecordById, action.payload.primaryKey); | ||
@@ -343,31 +342,43 @@ case 3: | ||
function entityWatcher() { | ||
return regeneratorRuntime.wrap(function entityWatcher$(_context7) { | ||
return /*#__PURE__*/regeneratorRuntime.mark(function saga() { | ||
return regeneratorRuntime.wrap(function saga$(_context7) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
_context7.next = 2; | ||
_context7.t0 = _effects.all; | ||
_context7.next = 3; | ||
return (0, _effects.takeEvery)(actions.create.type, create); | ||
case 2: | ||
_context7.next = 4; | ||
case 3: | ||
_context7.t1 = _context7.sent; | ||
_context7.next = 6; | ||
return (0, _effects.takeEvery)(actions.update.type, update); | ||
case 4: | ||
_context7.next = 6; | ||
case 6: | ||
_context7.t2 = _context7.sent; | ||
_context7.next = 9; | ||
return (0, _effects.takeEvery)(actions["delete"].type, _delete); | ||
case 6: | ||
_context7.next = 8; | ||
case 9: | ||
_context7.t3 = _context7.sent; | ||
_context7.next = 12; | ||
return (0, _effects.takeEvery)(actions.getRecordById.type, getRecordById); | ||
case 8: | ||
_context7.next = 10; | ||
case 12: | ||
_context7.t4 = _context7.sent; | ||
_context7.next = 15; | ||
return (0, _effects.takeEvery)(actions.setCurrentRecord.type, setCurrentRecord); | ||
case 10: | ||
_context7.next = 12; | ||
case 15: | ||
_context7.t5 = _context7.sent; | ||
_context7.next = 18; | ||
return (0, _effects.takeEvery)(actions.selectRecords.type, selectRecords); | ||
case 12: | ||
case 18: | ||
_context7.t6 = _context7.sent; | ||
_context7.t7 = [_context7.t1, _context7.t2, _context7.t3, _context7.t4, _context7.t5, _context7.t6]; | ||
_context7.next = 22; | ||
return (0, _context7.t0)(_context7.t7); | ||
case 22: | ||
case "end": | ||
@@ -377,18 +388,2 @@ return _context7.stop(); | ||
} | ||
}, _marked7); | ||
} | ||
return /*#__PURE__*/regeneratorRuntime.mark(function saga() { | ||
return regeneratorRuntime.wrap(function saga$(_context8) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
_context8.next = 2; | ||
return entityWatcher(); | ||
case 2: | ||
case "end": | ||
return _context8.stop(); | ||
} | ||
} | ||
}, saga); | ||
@@ -395,0 +390,0 @@ }); |
@@ -26,5 +26,7 @@ "use strict"; | ||
state.searchTemplate = action.payload.searchTemplate; | ||
state.searchId = undefined; | ||
}, | ||
postSearchRequest: function postSearchRequest(state, action) { | ||
state.isLoading = true; | ||
state.searchId = undefined; | ||
}, | ||
@@ -48,3 +50,4 @@ postSearchRequestSuccess: function postSearchRequestSuccess(state, action) { | ||
failure: function failure(state, action) { | ||
state.error = action.error; | ||
state.isLoading = false; | ||
state.error = action.payload.error; | ||
} | ||
@@ -57,19 +60,40 @@ }, reducers), | ||
var createSagaMiddleware = function createSagaMiddleware(api) { | ||
var _marked = /*#__PURE__*/regeneratorRuntime.mark(postSearchRequest), | ||
_marked2 = /*#__PURE__*/regeneratorRuntime.mark(search), | ||
_marked3 = /*#__PURE__*/regeneratorRuntime.mark(postSearch), | ||
_marked4 = /*#__PURE__*/regeneratorRuntime.mark(searchWatcher); | ||
var _marked = /*#__PURE__*/regeneratorRuntime.mark(setSearchTemplate), | ||
_marked2 = /*#__PURE__*/regeneratorRuntime.mark(postSearchRequest), | ||
_marked3 = /*#__PURE__*/regeneratorRuntime.mark(search), | ||
_marked4 = /*#__PURE__*/regeneratorRuntime.mark(postSearch); | ||
function setSearchTemplate(action) { | ||
return regeneratorRuntime.wrap(function setSearchTemplate$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!action.payload.callback) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_context.next = 3; | ||
return (0, _effects.call)(action.payload.callback, action.payload.searchTemplate); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _marked); | ||
} | ||
function postSearchRequest(action) { | ||
var searchId, result; | ||
return regeneratorRuntime.wrap(function postSearchRequest$(_context) { | ||
return regeneratorRuntime.wrap(function postSearchRequest$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
return (0, _effects.call)(api.postSearchRequest, action.payload.searchTemplate); | ||
case 3: | ||
searchId = _context.sent; | ||
searchId = _context2.sent; | ||
result = { | ||
@@ -79,3 +103,3 @@ searchId: searchId, | ||
}; | ||
_context.next = 7; | ||
_context2.next = 7; | ||
return (0, _effects.put)(actions.postSearchRequestSuccess(result)); | ||
@@ -85,18 +109,18 @@ | ||
if (!action.payload.onSuccess) { | ||
_context.next = 10; | ||
_context2.next = 10; | ||
break; | ||
} | ||
_context.next = 10; | ||
_context2.next = 10; | ||
return (0, _effects.call)(action.payload.onSuccess, result); | ||
case 10: | ||
return _context.abrupt("return", result); | ||
return _context2.abrupt("return", result); | ||
case 13: | ||
_context.prev = 13; | ||
_context.t0 = _context["catch"](0); | ||
_context.next = 17; | ||
_context2.prev = 13; | ||
_context2.t0 = _context2["catch"](0); | ||
_context2.next = 17; | ||
return (0, _effects.put)(actions.failure({ | ||
error: _context.t0 | ||
error: _context2.t0 | ||
})); | ||
@@ -106,15 +130,15 @@ | ||
if (!action.payload.onFailure) { | ||
_context.next = 20; | ||
_context2.next = 20; | ||
break; | ||
} | ||
_context.next = 20; | ||
return (0, _effects.call)(action.payload.onFailure, _context.t0); | ||
_context2.next = 20; | ||
return (0, _effects.call)(action.payload.onFailure, _context2.t0); | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _marked, null, [[0, 13]]); | ||
}, _marked2, null, [[0, 13]]); | ||
} | ||
@@ -124,18 +148,18 @@ | ||
var records, resultSetSize; | ||
return regeneratorRuntime.wrap(function search$(_context2) { | ||
return regeneratorRuntime.wrap(function search$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
_context3.prev = 0; | ||
_context3.next = 3; | ||
return (0, _effects.call)(api.search, action.payload.searchId, action.payload.pageSize, action.payload.page); | ||
case 3: | ||
records = _context2.sent; | ||
_context2.next = 6; | ||
records = _context3.sent; | ||
_context3.next = 6; | ||
return (0, _effects.call)(api.getResultSetSize, action.payload.searchId); | ||
case 6: | ||
resultSetSize = _context2.sent; | ||
_context2.next = 9; | ||
resultSetSize = _context3.sent; | ||
_context3.next = 9; | ||
return (0, _effects.put)(actions.searchSuccess({ | ||
@@ -148,7 +172,7 @@ records: records, | ||
if (!action.payload.onSuccess) { | ||
_context2.next = 12; | ||
_context3.next = 12; | ||
break; | ||
} | ||
_context2.next = 12; | ||
_context3.next = 12; | ||
return (0, _effects.call)(action.payload.onSuccess, { | ||
@@ -160,11 +184,11 @@ records: records, | ||
case 12: | ||
_context2.next = 21; | ||
_context3.next = 21; | ||
break; | ||
case 14: | ||
_context2.prev = 14; | ||
_context2.t0 = _context2["catch"](0); | ||
_context2.next = 18; | ||
_context3.prev = 14; | ||
_context3.t0 = _context3["catch"](0); | ||
_context3.next = 18; | ||
return (0, _effects.put)(actions.failure({ | ||
error: _context2.t0 | ||
error: _context3.t0 | ||
})); | ||
@@ -174,15 +198,15 @@ | ||
if (!action.payload.onFailure) { | ||
_context2.next = 21; | ||
_context3.next = 21; | ||
break; | ||
} | ||
_context2.next = 21; | ||
return (0, _effects.call)(action.payload.onFailure, _context2.t0); | ||
_context3.next = 21; | ||
return (0, _effects.call)(action.payload.onFailure, _context3.t0); | ||
case 21: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _marked2, null, [[0, 14]]); | ||
}, _marked3, null, [[0, 14]]); | ||
} | ||
@@ -192,7 +216,7 @@ | ||
var payload; | ||
return regeneratorRuntime.wrap(function postSearch$(_context3) { | ||
return regeneratorRuntime.wrap(function postSearch$(_context4) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context3.next = 2; | ||
_context4.next = 2; | ||
return (0, _effects.call)(postSearchRequest, { | ||
@@ -207,4 +231,4 @@ type: actions.postSearchRequest.type, | ||
case 2: | ||
payload = _context3.sent; | ||
_context3.next = 5; | ||
payload = _context4.sent; | ||
_context4.next = 5; | ||
return (0, _effects.put)(actions.search({ | ||
@@ -220,41 +244,39 @@ searchId: payload.searchId, | ||
case "end": | ||
return _context3.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _marked3); | ||
}, _marked4); | ||
} | ||
function searchWatcher() { | ||
return regeneratorRuntime.wrap(function searchWatcher$(_context4) { | ||
return /*#__PURE__*/regeneratorRuntime.mark(function saga() { | ||
return regeneratorRuntime.wrap(function saga$(_context5) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context4.next = 2; | ||
_context5.t0 = _effects.all; | ||
_context5.next = 3; | ||
return (0, _effects.takeEvery)(actions.setSearchTemplate.type, setSearchTemplate); | ||
case 3: | ||
_context5.t1 = _context5.sent; | ||
_context5.next = 6; | ||
return (0, _effects.takeLatest)(actions.postSearchRequest.type, postSearchRequest); | ||
case 2: | ||
_context4.next = 4; | ||
case 6: | ||
_context5.t2 = _context5.sent; | ||
_context5.next = 9; | ||
return (0, _effects.takeLatest)(actions.search.type, search); | ||
case 4: | ||
_context4.next = 6; | ||
case 9: | ||
_context5.t3 = _context5.sent; | ||
_context5.next = 12; | ||
return (0, _effects.takeLatest)(actions.postSearch.type, postSearch); | ||
case 6: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _marked4); | ||
} | ||
case 12: | ||
_context5.t4 = _context5.sent; | ||
_context5.t5 = [_context5.t1, _context5.t2, _context5.t3, _context5.t4]; | ||
_context5.next = 16; | ||
return (0, _context5.t0)(_context5.t5); | ||
return /*#__PURE__*/regeneratorRuntime.mark(function saga() { | ||
return regeneratorRuntime.wrap(function saga$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return searchWatcher(); | ||
case 2: | ||
case 16: | ||
case "end": | ||
@@ -261,0 +283,0 @@ return _context5.stop(); |
export * from "./slice/createCrudSlice"; | ||
export * from "./slice/createSearchSlice"; | ||
export * from "./slice/createOptionsSlice"; | ||
export * from "./types"; | ||
@@ -4,0 +5,0 @@ export * from "./action/actionTypes"; |
@@ -64,3 +64,3 @@ function _extends() { _extends = Object.assign || 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); } | ||
state.isLoading = false; | ||
state.error = action.error; | ||
state.error = action.payload.error; | ||
} | ||
@@ -97,3 +97,3 @@ | ||
try { | ||
var updatedRecord = yield call(api.update, String(action.payload.primaryKey), action.payload.values); | ||
var updatedRecord = yield call(api.update, action.payload.primaryKey, action.payload.values); | ||
yield put(actions.updateSuccess({ | ||
@@ -119,3 +119,3 @@ record: updatedRecord | ||
try { | ||
yield all(action.payload.primaryKeys.map(primaryKey => call(api.delete, String(primaryKey)))); | ||
yield all(action.payload.primaryKeys.map(primaryKey => call(api.delete, primaryKey))); | ||
yield put(actions.deleteSuccess()); | ||
@@ -139,3 +139,3 @@ | ||
try { | ||
var record = yield call(api.getRecordById, String(action.payload.primaryKey)); | ||
var record = yield call(api.getRecordById, action.payload.primaryKey); | ||
yield put(actions.getRecordByIdSuccess({ | ||
@@ -171,13 +171,4 @@ record | ||
function* entityWatcher() { | ||
yield takeEvery(actions.create.type, create); | ||
yield takeEvery(actions.update.type, update); | ||
yield takeEvery(actions.delete.type, _delete); | ||
yield takeEvery(actions.getRecordById.type, getRecordById); | ||
yield takeEvery(actions.setCurrentRecord.type, setCurrentRecord); | ||
yield takeEvery(actions.selectRecords.type, selectRecords); | ||
} | ||
return function* saga() { | ||
yield entityWatcher(); | ||
yield all([yield takeEvery(actions.create.type, create), yield takeEvery(actions.update.type, update), yield takeEvery(actions.delete.type, _delete), yield takeEvery(actions.getRecordById.type, getRecordById), yield takeEvery(actions.setCurrentRecord.type, setCurrentRecord), yield takeEvery(actions.selectRecords.type, selectRecords)]); | ||
}; | ||
@@ -184,0 +175,0 @@ }; |
function _extends() { _extends = Object.assign || 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 { createSlice } from "@reduxjs/toolkit"; | ||
import { call, put, takeLatest } from "redux-saga/effects"; | ||
import { all, call, put, takeEvery, takeLatest } from "redux-saga/effects"; | ||
export var createSearchSlice = (_ref) => { | ||
@@ -18,2 +18,3 @@ var { | ||
state.searchTemplate = action.payload.searchTemplate; | ||
state.searchId = undefined; | ||
}, | ||
@@ -23,2 +24,3 @@ | ||
state.isLoading = true; | ||
state.searchId = undefined; | ||
}, | ||
@@ -47,3 +49,4 @@ | ||
failure(state, action) { | ||
state.error = action.error; | ||
state.isLoading = false; | ||
state.error = action.payload.error; | ||
} | ||
@@ -57,2 +60,8 @@ | ||
var createSagaMiddleware = api => { | ||
function* setSearchTemplate(action) { | ||
if (action.payload.callback) { | ||
yield call(action.payload.callback, action.payload.searchTemplate); | ||
} | ||
} | ||
function* postSearchRequest(action) { | ||
@@ -126,10 +135,4 @@ try { | ||
function* searchWatcher() { | ||
yield takeLatest(actions.postSearchRequest.type, postSearchRequest); | ||
yield takeLatest(actions.search.type, search); | ||
yield takeLatest(actions.postSearch.type, postSearch); | ||
} | ||
return function* saga() { | ||
yield searchWatcher(); | ||
yield all([yield takeEvery(actions.setSearchTemplate.type, setSearchTemplate), yield takeLatest(actions.postSearchRequest.type, postSearchRequest), yield takeLatest(actions.search.type, search), yield takeLatest(actions.postSearch.type, postSearch)]); | ||
}; | ||
@@ -136,0 +139,0 @@ }; |
export interface FailureAction<T> { | ||
error: T; | ||
} | ||
export interface GetOptionsAction { | ||
params?: any; | ||
} | ||
export interface GetOptionsActionSuccess<T> { | ||
options: Array<T>; | ||
} |
@@ -32,4 +32,4 @@ export interface CreateAction<T> { | ||
export interface SetCurrentRecordAction<T> { | ||
currentRecord: T; | ||
callback?: (record: T) => void; | ||
currentRecord?: T; | ||
callback?: (record?: T) => void; | ||
} | ||
@@ -36,0 +36,0 @@ export interface SelectRecordsAction<T> { |
import { SearchRequest } from "@jfront/core-rest"; | ||
export interface SetSearchTemplateAction<V> { | ||
searchTemplate: SearchRequest<V>; | ||
onSuccess?: () => void; | ||
onFailure?: (error: any) => void; | ||
callback?: (searchTemplate?: SearchRequest<V>) => void; | ||
} | ||
@@ -7,0 +6,0 @@ export interface PostSearchRequestAction<V> { |
export * from "./slice/createCrudSlice"; | ||
export * from "./slice/createSearchSlice"; | ||
export * from "./slice/createOptionsSlice"; | ||
export * from "./types"; | ||
@@ -4,0 +5,0 @@ export * from "./action/actionTypes"; |
@@ -7,3 +7,3 @@ import { SliceCaseReducers, ValidateSliceCaseReducers, PayloadAction, ActionReducerMapBuilder, CaseReducers } from "@reduxjs/toolkit"; | ||
declare type NoInfer<T> = [T][T extends any ? 0 : never]; | ||
export declare const createCrudSlice: <PrimaryKey = any, Entity = any, CreateEntity = Entity, UpdateEntity = Entity, S extends EntityState<Entity> = EntityState<Entity>, Reducers extends SliceCaseReducers<S> = SliceCaseReducers<S>>({ name, initialState, reducers, extraReducers, }: { | ||
export declare const createCrudSlice: <PrimaryKey = string, Entity = any, CreateEntity = Entity, UpdateEntity = Entity, S extends EntityState<Entity> = EntityState<Entity>, Reducers extends SliceCaseReducers<S> = SliceCaseReducers<S>>({ name, initialState, reducers, extraReducers, }: { | ||
name: string; | ||
@@ -53,3 +53,3 @@ initialState: S; | ||
deleteSuccess(state: S): void; | ||
failure(state: S, action: FailureAction<any>): void; | ||
failure(state: S, action: PayloadAction<FailureAction<any>>): void; | ||
} & Reducers & { [T in keyof Reducers]: Reducers[T] extends { | ||
@@ -61,4 +61,4 @@ reducer(s: S, action?: infer A | undefined): any; | ||
reducer: import("redux").Reducer<S, import("redux").AnyAction>; | ||
createSagaMiddleware: (api: ConnectorCrud<Entity, CreateEntity, UpdateEntity>) => () => Generator<Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>, void, unknown>; | ||
createSagaMiddleware: (api: ConnectorCrud<Entity, PrimaryKey, CreateEntity, UpdateEntity>) => () => Generator<import("redux-saga/effects").ForkEffect<never> | import("redux-saga/effects").AllEffect<any>, void, any>; | ||
}; | ||
export {}; |
@@ -39,3 +39,3 @@ import { ActionReducerMapBuilder, CaseReducers, PayloadAction, SliceCaseReducers, ValidateSliceCaseReducers } from "@reduxjs/toolkit"; | ||
}): void; | ||
failure(state: S, action: FailureAction<any>): void; | ||
failure(state: S, action: PayloadAction<FailureAction<any>>): void; | ||
} & Reducers & { [T in keyof Reducers]: Reducers[T] extends { | ||
@@ -47,4 +47,4 @@ reducer(s: S, action?: infer A | undefined): any; | ||
reducer: import("redux").Reducer<S, import("redux").AnyAction>; | ||
createSagaMiddleware: (api: ConnectorSearch<Entity, SearchTemplate>) => () => Generator<Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>, void, unknown>; | ||
createSagaMiddleware: (api: ConnectorSearch<Entity, SearchTemplate>) => () => Generator<import("redux-saga/effects").ForkEffect<never> | import("redux-saga/effects").AllEffect<any>, void, any>; | ||
}; | ||
export {}; |
{ | ||
"name": "@jfront/core-redux-saga", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"license": "Apache-2.0", | ||
@@ -28,3 +28,3 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@jfront/core-rest": "^0.1.0-rc.0" | ||
"@jfront/core-rest": "^0.1.0" | ||
}, | ||
@@ -42,3 +42,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "de961e5bfe0aac421d683629cc78de686a68f123" | ||
"gitHead": "487771e31f8825ceffaafd8cc3b62717398c7fe8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
125790
43
1353
Updated@jfront/core-rest@^0.1.0