@qvibi-toolbox/qapp
Advanced tools
Comparing version 0.1.7 to 0.1.10
export * from './lib/effects'; | ||
export * from './lib/jobs'; | ||
export * from './lib/message'; | ||
@@ -9,1 +10,2 @@ export * from './lib/module'; | ||
export * from './lib/store'; | ||
export * from './lib/tools'; |
import { race, call, cancel, cancelled, fork, all, delay, ForkEffect, PutEffect } from 'redux-saga/effects'; | ||
import { AnyQAppMessage, AnyQAppMessageDef, ExtractQAppMessage } from './message'; | ||
import { AnyQAppModuleDef } from './module'; | ||
import { IQAppMsgSaga, IQAppSagaResult } from './saga'; | ||
declare function take<T extends AnyQAppMessageDef>(msgDef: T): IQAppSagaResult<ExtractQAppMessage<T>>; | ||
declare function take<T extends AnyQAppMessageDef[]>(msgDefs: T): IQAppSagaResult<ExtractQAppMessage<T>>; | ||
declare function takeEvery<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeEvery<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeLatest<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeLatest<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeLeading<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeLeading<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<T>): ForkEffect<never>; | ||
declare function takeEvery<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function takeEvery<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function takeLatest<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function takeLatest<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function takeLeading<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function takeLeading<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<AnyQAppModuleDef, T>): ForkEffect<never>; | ||
declare function put(msg: AnyQAppMessage): PutEffect<AnyQAppMessage>; | ||
@@ -13,0 +14,0 @@ declare function select<TResult, Fn extends (state: unknown, ...args: unknown[]) => TResult>(selector: Fn): IQAppSagaResult<ReturnType<Fn>>; |
@@ -0,17 +1,19 @@ | ||
import { Action } from 'redux'; | ||
import { AnyQAppModuleDef, ExtractQAppModuleName } from './module'; | ||
export interface IQAppMessage<TType, TPayload> { | ||
export interface IQAppMessage<TModuleDef extends AnyQAppModuleDef, TType, TPayload> extends Action<TType> { | ||
readonly type: TType; | ||
readonly payload: Readonly<TPayload>; | ||
} | ||
export interface IQAppMessageDef<TType, _TPayload> { | ||
export interface IQAppMessageDef<TModuleDef extends AnyQAppModuleDef, TType, _TPayload> { | ||
type: TType; | ||
} | ||
export interface IQAppMessageCreator<TType, TPayload> extends IQAppMessageDef<TType, TPayload> { | ||
(payload: TPayload): IQAppMessage<TType, TPayload>; | ||
readOnly(): IQAppMessageDef<TType, TPayload>; | ||
export interface IQAppMessageCreator<TModuleDef extends AnyQAppModuleDef, TType, TPayload> extends IQAppMessageDef<TModuleDef, TType, TPayload> { | ||
(payload: TPayload): IQAppMessage<TModuleDef, TType, TPayload>; | ||
readOnly(): IQAppMessageDef<TModuleDef, TType, TPayload>; | ||
} | ||
export declare type AnyQAppMessageDef = IQAppMessageDef<string, unknown>; | ||
export declare type AnyQAppMessage = IQAppMessage<string, unknown>; | ||
export declare type ExtractQAppMessage<TMessageDef> = TMessageDef extends Array<infer TInnerDefs> ? TInnerDefs extends IQAppMessageCreator<infer TType, infer TPayload> ? IQAppMessage<TType, TPayload> : TMessageDef extends IQAppMessageDef<infer TType, infer TPayload> ? IQAppMessage<TType, TPayload> : never : TMessageDef extends IQAppMessageCreator<infer TType, infer TPayload> ? IQAppMessage<TType, TPayload> : TMessageDef extends IQAppMessageDef<infer TType, infer TPayload> ? IQAppMessage<TType, TPayload> : never; | ||
export declare const withPayload: <TPayload = Record<string, never>>(_payload?: TPayload) => TPayload; | ||
export declare function defineMsgs<TModuleDef extends AnyQAppModuleDef, TModuleName extends ExtractQAppModuleName<TModuleDef>>(moduleDef: TModuleDef): <TType extends string, TPayload>(type: `${TType}`, _payload: TPayload) => IQAppMessageCreator<`${TModuleName} ${TType}`, TPayload>; | ||
export declare type AnyQAppMessageDef = IQAppMessageDef<AnyQAppModuleDef, string, unknown>; | ||
export declare type AnyQAppMessage = IQAppMessage<AnyQAppModuleDef, string, unknown>; | ||
export declare type ExtractQAppMessage<TMessageDef> = TMessageDef extends Array<infer TInnerDefs> ? TInnerDefs extends IQAppMessageCreator<infer TModuleDef, infer TType, infer TPayload> ? IQAppMessage<TModuleDef, TType, TPayload> : TMessageDef extends IQAppMessageDef<infer TModuleDef, infer TType, infer TPayload> ? IQAppMessage<TModuleDef, TType, TPayload> : never : TMessageDef extends IQAppMessageCreator<infer TModuleDef, infer TType, infer TPayload> ? IQAppMessage<TModuleDef, TType, TPayload> : TMessageDef extends IQAppMessageDef<infer TModuleDef, infer TType, infer TPayload> ? IQAppMessage<TModuleDef, TType, TPayload> : never; | ||
export declare function defineMsg<TModuleDef extends AnyQAppModuleDef, TModuleName extends ExtractQAppModuleName<TModuleDef>, TType extends string, TPayload>(moduleDef: TModuleDef, type: `${TType}`, payload: TPayload): IQAppMessageCreator<TModuleDef, `${TModuleName} ${TType}`, TPayload>; | ||
export declare const withPayload: <TPayload = {}>() => TPayload; | ||
export declare function getDefineMsgTool<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef): <TType extends string, TPayload>(type: `${TType}`, payload: TPayload) => IQAppMessageCreator<TModuleDef, `${ExtractQAppModuleName<TModuleDef>} ${TType}`, TPayload>; |
@@ -23,5 +23,3 @@ import { IQvibiModule } from '@qvibi-toolbox/core'; | ||
export declare function defineModule<TModuleName extends `${string}`, TState>(defOptions: IQAppModuleDefOptions<TModuleName, TState>, _state: TState): IQAppModuleDef<`${TModuleName}`, TState>; | ||
export interface NoState extends Record<string, never> { | ||
} | ||
export declare function withState<TState = NoState>(_payload?: TState): TState; | ||
export declare function withState<TState = {}>(): TState; | ||
export declare function createModule<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef, options: IQAppModuleOptions<TModuleDef>): IQAppModule<TModuleDef>; |
@@ -15,4 +15,5 @@ import { Reducer } from 'redux'; | ||
export declare type ExtractQAppReducerState<TReducer> = TReducer extends IQAppReducer<infer TState> ? TState : never; | ||
export declare function createModuleReducer<TModuleDef extends AnyQAppModuleDef, TState extends ExtractQAppModuleState<TModuleDef>>(moduleDef: TModuleDef, initialState: TState, mutators: IQAppReducerMutator<TModuleDef, AnyQAppMessageDef>[]): IQAppReducer<TModuleDef>; | ||
export declare function createModuleReducer<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef, initialState: ExtractQAppModuleState<TModuleDef>, mutators: IQAppReducerMutator<TModuleDef, AnyQAppMessageDef>[]): IQAppReducer<TModuleDef>; | ||
export declare function combineReducers<TModuleDef extends AnyQAppModuleDef>(reducers: IQAppReducersMap<TModuleDef>): IQAppReducer<TModuleDef>; | ||
export declare function on<TModuleDef extends AnyQAppModuleDef, TState extends ExtractQAppModuleState<TModuleDef>, TMsgDef extends AnyQAppMessageDef>(msgDef: TMsgDef, mutate: (state: Readonly<TState>, payload: ExtractQAppMessage<TMsgDef>['payload'], msg: ExtractQAppMessage<TMsgDef>) => TState): IQAppReducerMutator<TModuleDef, TMsgDef>; | ||
export declare function getCreateModuleReducerTool<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef): (initialState: ExtractQAppModuleState<TModuleDef>, mutators: IQAppReducerMutator<TModuleDef, AnyQAppMessageDef>[]) => IQAppReducer<TModuleDef>; |
@@ -5,4 +5,4 @@ import { ExtractRouteParams as ExtractRouteParamsFromPath } from 'react-router'; | ||
} | ||
export declare type IQAppRouteParams = Record<string, string | number | boolean>; | ||
export interface IQAppRouteDef<TPath extends string, _TParams extends IQAppRouteParams = Record<string, never>> { | ||
export declare type IQAppRouteParams = Record<string, string | number | boolean> | void; | ||
export interface IQAppRouteDef<TPath extends string, TParams extends IQAppRouteParams> { | ||
path: `${TPath}`; | ||
@@ -9,0 +9,0 @@ } |
@@ -5,6 +5,11 @@ import { AnyQAppMessageDef, ExtractQAppMessage } from './message'; | ||
export declare type QAppExtractResult<T> = T extends (...args: any) => infer R ? R extends IQAppSagaResult<infer X> ? X : R extends Promise<infer X> ? X : never : never; | ||
export declare type IQAppMsgSaga<T extends AnyQAppMessageDef | AnyQAppMessageDef[]> = (msg: ExtractQAppMessage<T>) => IQAppSagaResult<void>; | ||
export declare type IQAppModuleSaga<_T extends AnyQAppModuleDef> = () => IQAppSagaResult<void>; | ||
export declare function createMsgSaga<T extends AnyQAppMessageDef>(msgDef: T, worker: IQAppMsgSaga<T>): IQAppMsgSaga<T>; | ||
export declare function createMsgSaga<T extends AnyQAppMessageDef[]>(msgDefs: T, worker: IQAppMsgSaga<T>): IQAppMsgSaga<T>; | ||
export declare function createModuleSaga<T extends AnyQAppModuleDef>(moduleDef: T, worker: IQAppModuleSaga<T>): IQAppModuleSaga<T>; | ||
export declare type IQAppMsgSaga<TModuleDef extends AnyQAppModuleDef, TMsg extends AnyQAppMessageDef | AnyQAppMessageDef[]> = (payload: ExtractQAppMessage<TMsg>['payload'], msg: ExtractQAppMessage<TMsg>) => IQAppSagaResult<void>; | ||
export declare type IQAppModuleSaga<TModuleDef extends AnyQAppModuleDef> = () => IQAppSagaResult<void>; | ||
export declare function createMsgSaga<TModuleDef extends AnyQAppModuleDef, TMsg extends AnyQAppMessageDef>(moduleDef: TModuleDef, msgDef: TMsg, worker: IQAppMsgSaga<TModuleDef, TMsg>): IQAppMsgSaga<TModuleDef, TMsg>; | ||
export declare function createMsgSaga<TModuleDef extends AnyQAppModuleDef, TMsgs extends AnyQAppMessageDef[]>(moduleDef: TModuleDef, msgDefs: TMsgs, worker: IQAppMsgSaga<TModuleDef, TMsgs>): IQAppMsgSaga<TModuleDef, TMsgs>; | ||
export declare function createModuleSaga<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef, worker: IQAppModuleSaga<TModuleDef>): IQAppModuleSaga<TModuleDef>; | ||
export declare function getCreateMsgSagaTool<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef): { | ||
<TMsg extends AnyQAppMessageDef>(msgDef: TMsg, worker: IQAppMsgSaga<TModuleDef, TMsg>): IQAppMsgSaga<TModuleDef, TMsg>; | ||
<TMsgs extends AnyQAppMessageDef[]>(msgDefs: TMsgs, worker: IQAppMsgSaga<TModuleDef, TMsgs>): IQAppMsgSaga<TModuleDef, TMsgs>; | ||
}; | ||
export declare function getCreateModuleSagaTool<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef): (worker: IQAppModuleSaga<TModuleDef>) => IQAppModuleSaga<TModuleDef>; |
import { createSelector } from 'reselect'; | ||
import { AnyQAppModuleDef, ExtractQAppModuleState } from './module'; | ||
export declare function createModuleSelector<TModuleDef extends AnyQAppModuleDef, TState extends ExtractQAppModuleState<TModuleDef>>(moduleDef: TModuleDef): (store: Record<string, unknown>) => TState; | ||
export { createSelector }; | ||
export declare function createModuleSelector<TModuleDef extends AnyQAppModuleDef>(moduleDef: TModuleDef): (store: Record<string, any>) => ExtractQAppModuleState<TModuleDef>; |
@@ -7,3 +7,3 @@ import { Store, Middleware } from 'redux'; | ||
addModule(module: AnyQAppModule): void; | ||
getReduxStore(): Store<Record<string, unknown>, AnyQAppMessage>; | ||
getReduxStore(): Store<Record<string, any>, AnyQAppMessage>; | ||
complete(): Promise<void>; | ||
@@ -10,0 +10,0 @@ } |
{ | ||
"name": "@qvibi-toolbox/qapp", | ||
"version": "0.1.7", | ||
"version": "0.1.10", | ||
"main": "./qapp-qapp-core.umd.js", | ||
@@ -10,3 +10,3 @@ "module": "./qapp-qapp-core.esm.js", | ||
"redux": "4.0.5", | ||
"@qvibi-toolbox/core": "0.1.7", | ||
"@qvibi-toolbox/core": "0.1.10", | ||
"react-router": "5.2.0", | ||
@@ -13,0 +13,0 @@ "reselect": "4.0.0" |
@@ -1,6 +0,6 @@ | ||
import { take as take$1, takeEvery as takeEvery$1, takeLatest as takeLatest$1, takeLeading as takeLeading$1, put as put$1, select as select$1 } from 'redux-saga/effects'; | ||
import { take as take$1, takeEvery as takeEvery$1, takeLatest as takeLatest$1, takeLeading as takeLeading$1, put as put$1, select as select$1, call, cancelled, all } from 'redux-saga/effects'; | ||
export { all, call, cancel, cancelled, delay, fork, race } from 'redux-saga/effects'; | ||
import { combineReducers as combineReducers$1, compose, createStore, applyMiddleware } from 'redux'; | ||
export { createSelector } from 'reselect'; | ||
import { generatePath as generatePath$1 } from 'react-router'; | ||
export { createSelector } from 'reselect'; | ||
import createSagaMiddleware, { END } from 'redux-saga'; | ||
@@ -74,11 +74,17 @@ | ||
function takeEvery(msgDef, worker) { | ||
return takeEvery$1(defToPattern(msgDef), worker); | ||
return takeEvery$1(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
function takeLatest(msgDef, worker) { | ||
return takeLatest$1(defToPattern(msgDef), worker); | ||
return takeLatest$1(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
function takeLeading(msgDef, worker) { | ||
return takeLeading$1(defToPattern(msgDef), worker); | ||
return takeLeading$1(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
@@ -108,3 +114,3 @@ | ||
function defineMsg(moduleDef, type, _payload) { | ||
function defineMsg(moduleDef, type, payload) { | ||
var finalType = moduleDef.moduleName + ' ' + type; | ||
@@ -129,7 +135,6 @@ | ||
} | ||
var withPayload = function withPayload(_payload) { | ||
var withPayload = function withPayload() { | ||
return null; | ||
}; | ||
function defineMsgs(moduleDef) { | ||
function getDefineMsgTool(moduleDef) { | ||
return function (type, payload) { | ||
@@ -140,21 +145,2 @@ return defineMsg(moduleDef, type); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
function defineModule(defOptions, _state) { | ||
return { | ||
moduleName: "" + defOptions.moduleName | ||
}; | ||
} | ||
function withState(_payload) { | ||
return null; | ||
} | ||
function createModule(moduleDef, options) { | ||
return { | ||
moduleName: moduleDef.moduleName, | ||
reducer: options.reducer, | ||
saga: options.saga | ||
}; | ||
} | ||
function createModuleReducer(moduleDef, initialState, mutators) { | ||
@@ -191,13 +177,9 @@ var map = mutators.reduce(function (acc, h) { | ||
} | ||
function defineRoute(options) { | ||
return { | ||
path: options.path | ||
function getCreateModuleReducerTool(moduleDef) { | ||
return function (initialState, mutators) { | ||
return createModuleReducer(moduleDef, initialState, mutators); | ||
}; | ||
} | ||
function generatePath(routeDef, params) { | ||
return generatePath$1(routeDef.path, params); | ||
} | ||
function createMsgSaga(_msgDef, worker) { | ||
function createMsgSaga(moduleDef, _msgDef, worker) { | ||
return worker; | ||
@@ -208,3 +190,15 @@ } | ||
} | ||
function getCreateMsgSagaTool(moduleDef) { | ||
function create(_msgDef, worker) { | ||
return worker; | ||
} | ||
return create; | ||
} | ||
function getCreateModuleSagaTool(moduleDef) { | ||
return function (worker) { | ||
return createModuleSaga(moduleDef, worker); | ||
}; | ||
} | ||
function createModuleSelector(moduleDef) { | ||
@@ -216,2 +210,259 @@ return function (store) { | ||
function getModuleTools(moduleDef) { | ||
return { | ||
defineMsg: getDefineMsgTool(moduleDef), | ||
createSaga: getCreateModuleSagaTool(moduleDef), | ||
createMsgSaga: getCreateMsgSagaTool(), | ||
createReducer: getCreateModuleReducerTool(moduleDef), | ||
getState: createModuleSelector(moduleDef), | ||
createJobGroup: getCreateJobGroupTool(moduleDef), | ||
createJob: getCreateJobTool(moduleDef) | ||
}; | ||
} | ||
function createJobGroup(moduleDef, options) { | ||
var defineMsg = getModuleTools(moduleDef).defineMsg; | ||
var defineCoordinatorMsg = function defineCoordinatorMsg(jobProgress, payload) { | ||
var type = "job-group:" + options.jobGroupName + " " + jobProgress; | ||
return defineMsg(type, payload); | ||
}; | ||
var beganMsg = defineCoordinatorMsg('began', withPayload()); | ||
var doneMsg = defineCoordinatorMsg('done', withPayload()); | ||
var failedMsg = defineCoordinatorMsg('failed', withPayload()); | ||
var cancelledMsg = defineCoordinatorMsg('cancelled', withPayload()); | ||
var jobBeganMsg = defineCoordinatorMsg('job_began', withPayload()); | ||
var jobDoneMsg = defineCoordinatorMsg('job_done', withPayload()); | ||
var jobFailedMsg = defineCoordinatorMsg('job_failed', withPayload()); | ||
var jobCancelledMsg = defineCoordinatorMsg('job_cancelled', withPayload()); | ||
var jobs = []; | ||
var execute = function execute() { | ||
var statuses, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 4, 6, 10]); | ||
return [4 | ||
/*yield*/ | ||
, put(beganMsg({}))]; | ||
case 1: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, all(jobs.map(function (job) { | ||
return call(function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 4, 6, 10]); | ||
return [4 | ||
/*yield*/ | ||
, put(jobBeganMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 1: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, job.worker()]; | ||
case 2: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(jobDoneMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 3: | ||
_b.sent(); | ||
return [2 | ||
/*return*/ | ||
, true]; | ||
case 4: | ||
_a = _b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(jobFailedMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 5: | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 6: | ||
return [4 | ||
/*yield*/ | ||
, cancelled()]; | ||
case 7: | ||
if (!_b.sent()) return [3 | ||
/*break*/ | ||
, 9]; | ||
return [4 | ||
/*yield*/ | ||
, put(jobCancelledMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 8: | ||
_b.sent(); | ||
_b.label = 9; | ||
case 9: | ||
return [7 | ||
/*endfinally*/ | ||
]; | ||
case 10: | ||
return [2 | ||
/*return*/ | ||
, false]; | ||
} | ||
}); | ||
}); | ||
}))]; | ||
case 2: | ||
statuses = _b.sent(); | ||
if (~statuses.indexOf(false)) { | ||
throw new Error("failed to execute jobgroup " + options.jobGroupName); | ||
} // check if all job finished properly | ||
return [4 | ||
/*yield*/ | ||
, put(doneMsg({}))]; | ||
case 3: | ||
// check if all job finished properly | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 4: | ||
_a = _b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(failedMsg({}))]; | ||
case 5: | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 6: | ||
return [4 | ||
/*yield*/ | ||
, cancelled()]; | ||
case 7: | ||
if (!_b.sent()) return [3 | ||
/*break*/ | ||
, 9]; | ||
return [4 | ||
/*yield*/ | ||
, put(cancelledMsg({}))]; | ||
case 8: | ||
_b.sent(); | ||
_b.label = 9; | ||
case 9: | ||
return [7 | ||
/*endfinally*/ | ||
]; | ||
case 10: | ||
return [2 | ||
/*return*/ | ||
]; | ||
} | ||
}); | ||
}; | ||
return { | ||
jobGroupName: moduleDef.moduleName + " job-group:" + options.jobGroupName, | ||
execute: execute, | ||
addJob: function addJob(job) { | ||
jobs.push(job); | ||
}, | ||
removeJob: function removeJob(job) { | ||
jobs.splice(jobs.indexOf(job)); | ||
} | ||
}; | ||
} | ||
function createJob(moduleDef, jobGroup, jobName, worker) { | ||
return { | ||
jobName: jobGroup.jobGroupName + " | " + moduleDef.moduleName + " " + jobName, | ||
worker: worker | ||
}; | ||
} | ||
function runJobGroup(jobGroup) { | ||
return call(jobGroup.execute); | ||
} | ||
function getCreateJobGroupTool(moduleDef) { | ||
return function (options) { | ||
return createJobGroup(moduleDef, options); | ||
}; | ||
} | ||
function getCreateJobTool(moduleDef) { | ||
return function (jobGroup, jobName, worker) { | ||
return createJob(moduleDef, jobGroup, jobName, worker); | ||
}; | ||
} | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
function defineModule(defOptions, _state) { | ||
return { | ||
moduleName: "" + defOptions.moduleName | ||
}; | ||
} | ||
function withState() { | ||
return null; | ||
} | ||
function createModule(moduleDef, options) { | ||
return { | ||
moduleName: moduleDef.moduleName, | ||
reducer: options.reducer, | ||
saga: options.saga | ||
}; | ||
} | ||
function defineRoute(options) { | ||
return { | ||
path: options.path | ||
}; | ||
} | ||
function generatePath(routeDef, params) { | ||
return generatePath$1(routeDef.path, params); | ||
} | ||
/* eslint no-use-before-define: 0 */ | ||
@@ -362,2 +613,2 @@ | ||
export { combineReducers, createModule, createModuleReducer, createModuleSaga, createModuleSelector, createMsgSaga, createQApp, defineModule, defineMsgs, defineRoute, generatePath, on, put, select, take, takeEvery, takeLatest, takeLeading, withPayload, withState }; | ||
export { combineReducers, createJob, createJobGroup, createModule, createModuleReducer, createModuleSaga, createModuleSelector, createMsgSaga, createQApp, defineModule, defineMsg, defineRoute, generatePath, getCreateJobGroupTool, getCreateJobTool, getCreateModuleReducerTool, getCreateModuleSagaTool, getCreateMsgSagaTool, getDefineMsgTool, getModuleTools, on, put, runJobGroup, select, take, takeEvery, takeLatest, takeLeading, withPayload, withState }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('redux-saga/effects'), require('redux'), require('react-router'), require('reselect'), require('redux-saga')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'redux-saga/effects', 'redux', 'react-router', 'reselect', 'redux-saga'], factory) : | ||
(global = global || self, factory(global.QappQappCore = {}, global.effects, global.redux, global.reactRouter, global.reselect, global.createSagaMiddleware)); | ||
}(this, (function (exports, effects, redux, reactRouter, reselect, createSagaMiddleware) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('redux-saga/effects'), require('redux'), require('reselect'), require('react-router'), require('redux-saga')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'redux-saga/effects', 'redux', 'reselect', 'react-router', 'redux-saga'], factory) : | ||
(global = global || self, factory(global.QappQappCore = {}, global.effects, global.redux, global.reselect, global.reactRouter, global.createSagaMiddleware)); | ||
}(this, (function (exports, effects, redux, reselect, reactRouter, createSagaMiddleware) { 'use strict'; | ||
@@ -75,11 +75,17 @@ var createSagaMiddleware__default = 'default' in createSagaMiddleware ? createSagaMiddleware['default'] : createSagaMiddleware; | ||
function takeEvery(msgDef, worker) { | ||
return effects.takeEvery(defToPattern(msgDef), worker); | ||
return effects.takeEvery(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
function takeLatest(msgDef, worker) { | ||
return effects.takeLatest(defToPattern(msgDef), worker); | ||
return effects.takeLatest(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
function takeLeading(msgDef, worker) { | ||
return effects.takeLeading(defToPattern(msgDef), worker); | ||
return effects.takeLeading(defToPattern(msgDef), function (msg) { | ||
return worker(msg.payload, msg); | ||
}); | ||
} | ||
@@ -109,3 +115,3 @@ | ||
function defineMsg(moduleDef, type, _payload) { | ||
function defineMsg(moduleDef, type, payload) { | ||
var finalType = moduleDef.moduleName + ' ' + type; | ||
@@ -130,7 +136,6 @@ | ||
} | ||
var withPayload = function withPayload(_payload) { | ||
var withPayload = function withPayload() { | ||
return null; | ||
}; | ||
function defineMsgs(moduleDef) { | ||
function getDefineMsgTool(moduleDef) { | ||
return function (type, payload) { | ||
@@ -141,21 +146,2 @@ return defineMsg(moduleDef, type); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
function defineModule(defOptions, _state) { | ||
return { | ||
moduleName: "" + defOptions.moduleName | ||
}; | ||
} | ||
function withState(_payload) { | ||
return null; | ||
} | ||
function createModule(moduleDef, options) { | ||
return { | ||
moduleName: moduleDef.moduleName, | ||
reducer: options.reducer, | ||
saga: options.saga | ||
}; | ||
} | ||
function createModuleReducer(moduleDef, initialState, mutators) { | ||
@@ -192,13 +178,9 @@ var map = mutators.reduce(function (acc, h) { | ||
} | ||
function defineRoute(options) { | ||
return { | ||
path: options.path | ||
function getCreateModuleReducerTool(moduleDef) { | ||
return function (initialState, mutators) { | ||
return createModuleReducer(moduleDef, initialState, mutators); | ||
}; | ||
} | ||
function generatePath(routeDef, params) { | ||
return reactRouter.generatePath(routeDef.path, params); | ||
} | ||
function createMsgSaga(_msgDef, worker) { | ||
function createMsgSaga(moduleDef, _msgDef, worker) { | ||
return worker; | ||
@@ -209,3 +191,15 @@ } | ||
} | ||
function getCreateMsgSagaTool(moduleDef) { | ||
function create(_msgDef, worker) { | ||
return worker; | ||
} | ||
return create; | ||
} | ||
function getCreateModuleSagaTool(moduleDef) { | ||
return function (worker) { | ||
return createModuleSaga(moduleDef, worker); | ||
}; | ||
} | ||
function createModuleSelector(moduleDef) { | ||
@@ -217,2 +211,259 @@ return function (store) { | ||
function getModuleTools(moduleDef) { | ||
return { | ||
defineMsg: getDefineMsgTool(moduleDef), | ||
createSaga: getCreateModuleSagaTool(moduleDef), | ||
createMsgSaga: getCreateMsgSagaTool(), | ||
createReducer: getCreateModuleReducerTool(moduleDef), | ||
getState: createModuleSelector(moduleDef), | ||
createJobGroup: getCreateJobGroupTool(moduleDef), | ||
createJob: getCreateJobTool(moduleDef) | ||
}; | ||
} | ||
function createJobGroup(moduleDef, options) { | ||
var defineMsg = getModuleTools(moduleDef).defineMsg; | ||
var defineCoordinatorMsg = function defineCoordinatorMsg(jobProgress, payload) { | ||
var type = "job-group:" + options.jobGroupName + " " + jobProgress; | ||
return defineMsg(type, payload); | ||
}; | ||
var beganMsg = defineCoordinatorMsg('began', withPayload()); | ||
var doneMsg = defineCoordinatorMsg('done', withPayload()); | ||
var failedMsg = defineCoordinatorMsg('failed', withPayload()); | ||
var cancelledMsg = defineCoordinatorMsg('cancelled', withPayload()); | ||
var jobBeganMsg = defineCoordinatorMsg('job_began', withPayload()); | ||
var jobDoneMsg = defineCoordinatorMsg('job_done', withPayload()); | ||
var jobFailedMsg = defineCoordinatorMsg('job_failed', withPayload()); | ||
var jobCancelledMsg = defineCoordinatorMsg('job_cancelled', withPayload()); | ||
var jobs = []; | ||
var execute = function execute() { | ||
var statuses, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 4, 6, 10]); | ||
return [4 | ||
/*yield*/ | ||
, put(beganMsg({}))]; | ||
case 1: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, effects.all(jobs.map(function (job) { | ||
return effects.call(function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 4, 6, 10]); | ||
return [4 | ||
/*yield*/ | ||
, put(jobBeganMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 1: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, job.worker()]; | ||
case 2: | ||
_b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(jobDoneMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 3: | ||
_b.sent(); | ||
return [2 | ||
/*return*/ | ||
, true]; | ||
case 4: | ||
_a = _b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(jobFailedMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 5: | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 6: | ||
return [4 | ||
/*yield*/ | ||
, effects.cancelled()]; | ||
case 7: | ||
if (!_b.sent()) return [3 | ||
/*break*/ | ||
, 9]; | ||
return [4 | ||
/*yield*/ | ||
, put(jobCancelledMsg({ | ||
jobName: job.jobName | ||
}))]; | ||
case 8: | ||
_b.sent(); | ||
_b.label = 9; | ||
case 9: | ||
return [7 | ||
/*endfinally*/ | ||
]; | ||
case 10: | ||
return [2 | ||
/*return*/ | ||
, false]; | ||
} | ||
}); | ||
}); | ||
}))]; | ||
case 2: | ||
statuses = _b.sent(); | ||
if (~statuses.indexOf(false)) { | ||
throw new Error("failed to execute jobgroup " + options.jobGroupName); | ||
} // check if all job finished properly | ||
return [4 | ||
/*yield*/ | ||
, put(doneMsg({}))]; | ||
case 3: | ||
// check if all job finished properly | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 4: | ||
_a = _b.sent(); | ||
return [4 | ||
/*yield*/ | ||
, put(failedMsg({}))]; | ||
case 5: | ||
_b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 10]; | ||
case 6: | ||
return [4 | ||
/*yield*/ | ||
, effects.cancelled()]; | ||
case 7: | ||
if (!_b.sent()) return [3 | ||
/*break*/ | ||
, 9]; | ||
return [4 | ||
/*yield*/ | ||
, put(cancelledMsg({}))]; | ||
case 8: | ||
_b.sent(); | ||
_b.label = 9; | ||
case 9: | ||
return [7 | ||
/*endfinally*/ | ||
]; | ||
case 10: | ||
return [2 | ||
/*return*/ | ||
]; | ||
} | ||
}); | ||
}; | ||
return { | ||
jobGroupName: moduleDef.moduleName + " job-group:" + options.jobGroupName, | ||
execute: execute, | ||
addJob: function addJob(job) { | ||
jobs.push(job); | ||
}, | ||
removeJob: function removeJob(job) { | ||
jobs.splice(jobs.indexOf(job)); | ||
} | ||
}; | ||
} | ||
function createJob(moduleDef, jobGroup, jobName, worker) { | ||
return { | ||
jobName: jobGroup.jobGroupName + " | " + moduleDef.moduleName + " " + jobName, | ||
worker: worker | ||
}; | ||
} | ||
function runJobGroup(jobGroup) { | ||
return effects.call(jobGroup.execute); | ||
} | ||
function getCreateJobGroupTool(moduleDef) { | ||
return function (options) { | ||
return createJobGroup(moduleDef, options); | ||
}; | ||
} | ||
function getCreateJobTool(moduleDef) { | ||
return function (jobGroup, jobName, worker) { | ||
return createJob(moduleDef, jobGroup, jobName, worker); | ||
}; | ||
} | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
function defineModule(defOptions, _state) { | ||
return { | ||
moduleName: "" + defOptions.moduleName | ||
}; | ||
} | ||
function withState() { | ||
return null; | ||
} | ||
function createModule(moduleDef, options) { | ||
return { | ||
moduleName: moduleDef.moduleName, | ||
reducer: options.reducer, | ||
saga: options.saga | ||
}; | ||
} | ||
function defineRoute(options) { | ||
return { | ||
path: options.path | ||
}; | ||
} | ||
function generatePath(routeDef, params) { | ||
return reactRouter.generatePath(routeDef.path, params); | ||
} | ||
/* eslint no-use-before-define: 0 */ | ||
@@ -412,2 +663,4 @@ | ||
exports.combineReducers = combineReducers; | ||
exports.createJob = createJob; | ||
exports.createJobGroup = createJobGroup; | ||
exports.createModule = createModule; | ||
@@ -420,7 +673,15 @@ exports.createModuleReducer = createModuleReducer; | ||
exports.defineModule = defineModule; | ||
exports.defineMsgs = defineMsgs; | ||
exports.defineMsg = defineMsg; | ||
exports.defineRoute = defineRoute; | ||
exports.generatePath = generatePath; | ||
exports.getCreateJobGroupTool = getCreateJobGroupTool; | ||
exports.getCreateJobTool = getCreateJobTool; | ||
exports.getCreateModuleReducerTool = getCreateModuleReducerTool; | ||
exports.getCreateModuleSagaTool = getCreateModuleSagaTool; | ||
exports.getCreateMsgSagaTool = getCreateMsgSagaTool; | ||
exports.getDefineMsgTool = getDefineMsgTool; | ||
exports.getModuleTools = getModuleTools; | ||
exports.on = on; | ||
exports.put = put; | ||
exports.runJobGroup = runJobGroup; | ||
exports.select = select; | ||
@@ -427,0 +688,0 @@ exports.take = take; |
57347
16
1281
+ Added@qvibi-toolbox/core@0.1.10(transitive)
- Removed@qvibi-toolbox/core@0.1.7(transitive)
Updated@qvibi-toolbox/core@0.1.10