@albertli90/redux-advanced
Advanced tools
Comparing version 1.1.0-beta.10 to 1.1.0-beta.11
@@ -16,3 +16,2 @@ import { StrictEffect } from "@redux-saga/types"; | ||
} | ||
export declare type ActionWithFields<TPayload, TFieldsObj> = Action<TPayload> & TFieldsObj; | ||
export interface ActionHelper<TPayload = any, TResult = any> { | ||
@@ -47,3 +46,3 @@ type: string; | ||
dispatch(payload: TPayload): Promise<TResult>; | ||
get saga(): (payload: TPayload) => Generator<StrictEffect<any, any>, any, any>; | ||
get saga(): ((input: TPayload | Action<TPayload>) => Generator<StrictEffect<any, any>, any, any>) | ((payload: TPayload) => Generator<import("redux-saga/effects").CallEffect<import("redux-saga/effects").SagaReturnType<this["dispatch"]>>, any, unknown>); | ||
} | ||
@@ -50,0 +49,0 @@ export declare function createActionHelpers<TModel extends Model>(storeContext: StoreContext, container: ContainerImpl<TModel>): ExtractActionHelpers<ExtractReducers<TModel>, ExtractEffects<TModel>, ExtractSagaEffects<TModel>>; |
@@ -15,14 +15,6 @@ import { __generator, __read, __values } from "tslib"; | ||
ActionHelperImpl.prototype.create = function (payload) { | ||
var _a; | ||
var action = { | ||
return { | ||
type: this.type, | ||
payload: payload, | ||
}; | ||
// todo move ctx to this.create | ||
var _b = __read(splitLastPart(this.type), 2), actionName = _b[1]; | ||
if (this._storeContext && ((_a = this._storeContext.contextByModel | ||
.get(this._container.model)) === null || _a === void 0 ? void 0 : _a.sagaEffectByActionName.has(actionName))) { | ||
action.context = this._container.sagaContext; | ||
} | ||
return action; | ||
}; | ||
@@ -64,14 +56,16 @@ ActionHelperImpl.prototype.dispatch = function (payload) { | ||
if (!!theSaga) { | ||
return function (payload) { | ||
var arg; | ||
return function (input) { | ||
var payload; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!payload["context"]) { | ||
arg = self.create(payload.payload); | ||
if (!!input.type) { | ||
// input is action from saga | ||
payload = input.payload; | ||
} | ||
else { | ||
arg = self.create(payload); | ||
// input is payload from custom | ||
payload = input; | ||
} | ||
return [5 /*yield**/, __values(theSaga(arg))]; | ||
return [5 /*yield**/, __values(theSaga(self._container.sagaContext, payload))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -78,0 +72,0 @@ } |
@@ -5,5 +5,4 @@ export { Action, ActionHelper, AnyAction } from "./action"; | ||
export { ExtractDependencies } from "./dependencies"; | ||
export { SGA } from "./saga"; | ||
export { createModelBuilder, ExtractModel, flattenModels, Model, ModelOptions, Models, } from "./model"; | ||
export { ExtractState } from "./state"; | ||
export { init, ReduxAdvancedInstance, ReduxAdvancedOptions } from "./store"; |
@@ -93,6 +93,6 @@ import { __assign, __generator, __read, __spread, __values } from "tslib"; | ||
_e[subKey] = assignObjectDeeply({}, model.sagas, function (oldSaga) { | ||
var newSagaEffect = function (action) { | ||
var newSagaEffect = function (context, payload) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [5 /*yield**/, __values(oldSaga(__assign(__assign({}, action), { context: __assign(__assign({}, action.context), { getState: function () { var _a; return (_a = action.context.getState()) === null || _a === void 0 ? void 0 : _a[subKey]; }, getters: action.context.getters[subKey], actions: action.context.actions[subKey] }) })))]; | ||
case 0: return [5 /*yield**/, __values(oldSaga(__assign(__assign({}, context), { getState: function () { var _a; return (_a = context.getState()) === null || _a === void 0 ? void 0 : _a[subKey]; }, getters: context.getters[subKey], actions: context.actions[subKey] }), payload))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -99,0 +99,0 @@ } |
import { StrictEffect } from "@redux-saga/types"; | ||
import { Getters } from "./selector"; | ||
import { ActionHelpers, ActionWithFields, ExtractActionDispatchResult, ExtractActionPayload } from "./action"; | ||
import { Action, ActionHelpers, ExtractActionDispatchResult, ExtractActionPayload } from "./action"; | ||
import { GetContainer } from "./container"; | ||
import { Model } from "./model"; | ||
import { StoreContext } from "./context"; | ||
export declare type SGA<P, D = any, S extends object = any, G extends Getters = any, A extends ActionHelpers = any> = ActionWithFields<P, { | ||
context: SagaContext<D, S, G, A>; | ||
}>; | ||
export declare type SagaAction<P = any> = Action<P>; | ||
export interface SagaContext<TDependencies = any, TState extends object = any, TGetters extends Getters = any, TActionHelpers extends ActionHelpers = any> { | ||
@@ -20,3 +18,3 @@ dependencies: TDependencies; | ||
} | ||
export declare type SagaEffect<TDependencies = any, TState extends object = any, TGetters extends Getters = any, TActionHelpers extends ActionHelpers = any, TPayload = any, TResult = any> = (action: SGA<TPayload, TDependencies, TState, TGetters, TActionHelpers>) => Generator<StrictEffect, TResult, SGA<TPayload, TDependencies, TState, TGetters, TActionHelpers> | any[] | any>; | ||
export declare type SagaEffect<TDependencies = any, TState extends object = any, TGetters extends Getters = any, TActionHelpers extends ActionHelpers = any, TPayload = any, TResult = any> = (ctx: SagaContext<TDependencies, TState, TGetters, TActionHelpers>, pl: TPayload) => Generator<StrictEffect, TResult, SagaAction<TPayload> | any[] | any>; | ||
export interface SagaEffects<TDependencies = any, TState extends object = any, TGetters extends Getters = any, TActionHelpers extends ActionHelpers = any> { | ||
@@ -23,0 +21,0 @@ [name: string]: SagaEffect<TDependencies, TState, TGetters, TActionHelpers> | SagaEffects<TDependencies, TState, TGetters, TActionHelpers>; |
@@ -6,7 +6,7 @@ import { __generator, __read, __values } from "tslib"; | ||
export function rootSagaBuilder(storeCtx) { | ||
function _doSpawnEntries(action, entrySagaEffects, baseNamespace, key) { | ||
function _doSpawnEntries(context, action, entrySagaEffects, baseNamespace, key) { | ||
var allTasks, action_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, all(entrySagaEffects.map(function (saga) { return fork(saga, action); }))]; | ||
case 0: return [4 /*yield*/, all(entrySagaEffects.map(function (saga) { return fork(saga, context, action.payload); }))]; | ||
case 1: | ||
@@ -41,3 +41,3 @@ allTasks = _a.sent(); | ||
_loop_1 = function (options) { | ||
var baseNamespace, key, modelIndex, models, model, modelCtx, container, newAction, entrySagaEffects; | ||
var baseNamespace, key, modelIndex, models, model, modelCtx, container, entrySagaEffects; | ||
return __generator(this, function (_a) { | ||
@@ -54,4 +54,2 @@ switch (_a.label) { | ||
container = storeCtx.getContainer(model, key); | ||
newAction = action; | ||
newAction.context = container.sagaContext; | ||
entrySagaEffects = []; | ||
@@ -64,3 +62,3 @@ modelCtx.sagaEffectByActionName.forEach(function (oneSaga, key) { | ||
if (!(entrySagaEffects.length > 0)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, spawn(_doSpawnEntries, newAction, entrySagaEffects, baseNamespace, key)]; | ||
return [4 /*yield*/, spawn(_doSpawnEntries, container.sagaContext, action, entrySagaEffects, baseNamespace, key)]; | ||
case 1: | ||
@@ -126,8 +124,8 @@ _a.sent(); | ||
newAction = {}; | ||
newAction.type = action.type; | ||
newAction.payload = action.payload; | ||
newAction.context = container.sagaContext; | ||
_f.label = 2; | ||
case 2: | ||
_f.trys.push([2, 4, , 5]); | ||
return [5 /*yield**/, __values(theSaga(newAction))]; | ||
return [5 /*yield**/, __values(theSaga(container.sagaContext, newAction.payload))]; | ||
case 3: | ||
@@ -134,0 +132,0 @@ result = _f.sent(); |
{ | ||
"name": "@albertli90/redux-advanced", | ||
"version": "1.1.0-beta.10", | ||
"version": "1.1.0-beta.11", | ||
"description": "A state management library based on Redux", | ||
@@ -5,0 +5,0 @@ "authors": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
343027
8838