app-redux-utils
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=Controller.js.map |
@@ -1,10 +0,16 @@ | ||
export class ControllerBase { | ||
constructor(reduxStore) { | ||
if (new.target === ControllerBase) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ControllerBase = void 0; | ||
var ControllerBase = /** @class */ (function () { | ||
function ControllerBase(reduxStore) { | ||
var _newTarget = this.constructor; | ||
if (_newTarget === ControllerBase) { | ||
throw new Error('Cannot construct ControllerBase instance directly'); | ||
} | ||
this.dispatch = reduxStore.dispatch; | ||
this.getState = () => reduxStore.getState(); | ||
this.getState = function () { return reduxStore.getState(); }; | ||
} | ||
} | ||
return ControllerBase; | ||
}()); | ||
exports.ControllerBase = ControllerBase; | ||
//# sourceMappingURL=ControllerBase.js.map |
@@ -1,27 +0,46 @@ | ||
import { __awaiter } from "tslib"; | ||
import { isAction } from '../types'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.controllerMiddleware = void 0; | ||
var tslib_1 = require("tslib"); | ||
var types_1 = require("../types"); | ||
function controllerMiddleware(watchers) { | ||
return (reduxStore) => (next) => (action) => __awaiter(this, void 0, void 0, function* () { | ||
next(action); | ||
if (!isAction(action)) { | ||
return; | ||
} | ||
const generator = controllerGenerator(watchers, reduxStore, action); | ||
let iterator; | ||
do { | ||
iterator = generator.next(); | ||
if (!iterator.done) { | ||
try { | ||
yield iterator.value; | ||
} | ||
catch (error) { | ||
console.error('Unhandled exception in controller', error); | ||
} | ||
var _this = this; | ||
return function (reduxStore) { return function (next) { return function (action) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var generator, iterator, error_1; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
next(action); | ||
if (!types_1.isAction(action)) { | ||
return [2 /*return*/]; | ||
} | ||
generator = controllerGenerator(watchers, reduxStore, action); | ||
_a.label = 1; | ||
case 1: | ||
iterator = generator.next(); | ||
if (!!iterator.done) return [3 /*break*/, 5]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
return [4 /*yield*/, iterator.value]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
error_1 = _a.sent(); | ||
console.error('Unhandled exception in controller', error_1); | ||
return [3 /*break*/, 5]; | ||
case 5: | ||
if (!iterator.done) return [3 /*break*/, 1]; | ||
_a.label = 6; | ||
case 6: return [2 /*return*/]; | ||
} | ||
} while (!iterator.done); | ||
}); | ||
}); | ||
}); }; }; }; | ||
} | ||
exports.controllerMiddleware = controllerMiddleware; | ||
function controllerGenerator(watchers, reduxStore, initAction) { | ||
let actionCursor = 0; | ||
const actions = [() => initAction]; | ||
var _a; | ||
var actionCursor = 0; | ||
var actions = [function () { return initAction; }]; | ||
function iterator() { | ||
@@ -34,8 +53,8 @@ if (actionCursor >= actions.length) { | ||
} | ||
const action = actions[actionCursor](); | ||
const promises = []; | ||
watchers.forEach(watcher => { | ||
const actionName = watcher.get(action.type); | ||
var action = actions[actionCursor](); | ||
var promises = []; | ||
watchers.forEach(function (watcher) { | ||
var actionName = watcher.get(action.type); | ||
if (actionName) { | ||
const controller = watcher.instance(reduxStore); | ||
var controller = watcher.instance(reduxStore); | ||
promises.push(controller[actionName](action)); | ||
@@ -46,5 +65,5 @@ } | ||
return { | ||
value: Promise.all(promises).then(() => { | ||
if (isAction(action) && !action.stopPropagation) { | ||
actions.splice(actionCursor, 0, ...action.getActions()); | ||
value: Promise.all(promises).then(function () { | ||
if (types_1.isAction(action) && !action.stopPropagation) { | ||
actions.splice.apply(actions, tslib_1.__spreadArrays([actionCursor, 0], action.getActions())); | ||
} | ||
@@ -55,12 +74,11 @@ }), | ||
} | ||
return { | ||
[Symbol.iterator]() { | ||
return _a = {}, | ||
_a[Symbol.iterator] = function () { | ||
return this; | ||
}, | ||
next() { | ||
_a.next = function () { | ||
return iterator(); | ||
}, | ||
}; | ||
_a; | ||
} | ||
export { controllerMiddleware }; | ||
//# sourceMappingURL=controllerMiddleware.js.map |
@@ -1,5 +0,8 @@ | ||
export * from './ControllerBase'; | ||
export * from './Controller'; | ||
export * from './controllerMiddleware'; | ||
export * from './Watcher'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./ControllerBase"), exports); | ||
tslib_1.__exportStar(require("./Controller"), exports); | ||
tslib_1.__exportStar(require("./controllerMiddleware"), exports); | ||
tslib_1.__exportStar(require("./Watcher"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -5,7 +5,7 @@ import { Store } from 'redux'; | ||
import { ControllerBase } from './ControllerBase'; | ||
export declare type Watcher<TState, TController extends Controller = any> = { | ||
export declare type Watcher<TState, TController extends Controller> = { | ||
has: (actionType: string) => boolean; | ||
get: (actionType: string) => keyof TController | undefined; | ||
get: (actionType: string) => (keyof TController) | undefined; | ||
instance: (reduxStore: Store<TState, Action>) => ControllerBase<TState>; | ||
}; | ||
export declare function watcher<TState, TController extends Controller = any>(Controller: new (reduxStore: Store<TState, Action>) => ControllerBase<TState>, watchList: [string, keyof TController][]): Watcher<TState, TController>; | ||
export declare function watcher<TState, TController extends Controller>(Controller: new (reduxStore: Store<TState, Action>) => ControllerBase<TState>, watchList: [string, keyof TController][]): Watcher<TState, TController>; |
@@ -1,9 +0,13 @@ | ||
export function watcher(Controller, watchList) { | ||
const map = new Map(watchList); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.watcher = void 0; | ||
function watcher(Controller, watchList) { | ||
var map = new Map(watchList); | ||
return { | ||
has: (actionType) => map.has(actionType), | ||
get: (actionType) => map.get(actionType), | ||
instance: (reduxStore) => new Controller(reduxStore), | ||
has: function (actionType) { return map.has(actionType); }, | ||
get: function (actionType) { return map.get(actionType); }, | ||
instance: function (reduxStore) { return new Controller(reduxStore); }, | ||
}; | ||
} | ||
exports.watcher = watcher; | ||
//# sourceMappingURL=Watcher.js.map |
@@ -1,2 +0,2 @@ | ||
import { Action } from "./types"; | ||
import { Action } from './types'; | ||
export declare function createAction(actionType: string, payload?: any): Action; |
@@ -1,6 +0,11 @@ | ||
import { AppAction } from "./types/AppAction"; | ||
export function createAction(actionType, payload = {}) { | ||
let _payload; | ||
if (typeof payload === "object" && !Array.isArray(payload)) { | ||
_payload = Object.assign({}, payload); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createAction = void 0; | ||
var tslib_1 = require("tslib"); | ||
var AppAction_1 = require("./types/AppAction"); | ||
function createAction(actionType, payload) { | ||
if (payload === void 0) { payload = {}; } | ||
var _payload; | ||
if (typeof payload === 'object' && !Array.isArray(payload)) { | ||
_payload = tslib_1.__assign({}, payload); | ||
} | ||
@@ -10,4 +15,5 @@ else { | ||
} | ||
return new AppAction(actionType, _payload).toPlainObject(); | ||
return new AppAction_1.AppAction(actionType, _payload).toPlainObject(); | ||
} | ||
exports.createAction = createAction; | ||
//# sourceMappingURL=createAction.js.map |
@@ -1,2 +0,2 @@ | ||
import { ActionWithCallback } from "./types"; | ||
import { ActionWithCallback } from './types'; | ||
export declare function createActionWithCallback(actionType: string, payload?: any): ActionWithCallback; |
@@ -1,6 +0,10 @@ | ||
import { createAction } from "./createAction"; | ||
export function createActionWithCallback(actionType, payload = {}) { | ||
const appAction = createAction(actionType, payload); | ||
const actionWithCallback = (callbackAction) => { | ||
if (typeof callbackAction === "function") { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createActionWithCallback = void 0; | ||
var createAction_1 = require("./createAction"); | ||
function createActionWithCallback(actionType, payload) { | ||
if (payload === void 0) { payload = {}; } | ||
var appAction = createAction_1.createAction(actionType, payload); | ||
var actionWithCallback = function (callbackAction) { | ||
if (typeof callbackAction === 'function') { | ||
appAction.callbackAction = callbackAction; | ||
@@ -12,2 +16,3 @@ } | ||
} | ||
exports.createActionWithCallback = createActionWithCallback; | ||
//# sourceMappingURL=createActionWithCallback.js.map |
@@ -1,2 +0,2 @@ | ||
import { Reducer, ReducersMapObject } from "redux"; | ||
import { Reducer, ReducersMapObject } from 'redux'; | ||
export declare function createReducers<TReducers>(getReducers: (...params: any) => ReducersMapObject<TReducers, any>, ...params: any): Reducer<TReducers>; |
@@ -1,6 +0,14 @@ | ||
import { combineReducers } from "redux"; | ||
export function createReducers(getReducers, ...params) { | ||
const reducers = getReducers.apply(null, params); | ||
return combineReducers(reducers); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createReducers = void 0; | ||
var redux_1 = require("redux"); | ||
function createReducers(getReducers) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
var reducers = getReducers.apply(void 0, params); | ||
return redux_1.combineReducers(reducers); | ||
} | ||
exports.createReducers = createReducers; | ||
//# sourceMappingURL=createReducers.js.map |
@@ -1,5 +0,5 @@ | ||
export * from "./controller"; | ||
export * from "./createAction"; | ||
export * from "./createActionWithCallback"; | ||
export * from "./createReducers"; | ||
export * from "./types"; | ||
export * from './controller'; | ||
export * from './createAction'; | ||
export * from './createActionWithCallback'; | ||
export * from './createReducers'; | ||
export * from './types'; |
@@ -1,6 +0,9 @@ | ||
export * from "./controller"; | ||
export * from "./createAction"; | ||
export * from "./createActionWithCallback"; | ||
export * from "./createReducers"; | ||
export * from "./types"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./controller"), exports); | ||
tslib_1.__exportStar(require("./createAction"), exports); | ||
tslib_1.__exportStar(require("./createActionWithCallback"), exports); | ||
tslib_1.__exportStar(require("./createReducers"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,4 @@ | ||
import { Action as ReduxAction } from "redux"; | ||
import { CallbackAction } from "./CallbackAction"; | ||
export interface Action<TPayload = {}> extends ReduxAction { | ||
import { Action as ReduxAction } from 'redux'; | ||
import { CallbackAction } from './CallbackAction'; | ||
export interface Action<TPayload = any> extends ReduxAction { | ||
payload: TPayload; | ||
@@ -5,0 +5,0 @@ callbackAction?: CallbackAction; |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=Action.js.map |
@@ -1,3 +0,3 @@ | ||
import { Action } from "./Action"; | ||
import { CallbackAction } from "./CallbackAction"; | ||
import { Action } from './Action'; | ||
import { CallbackAction } from './CallbackAction'; | ||
export declare type ActionWithCallback = (callbackAction: CallbackAction) => Action; |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ActionWithCallback.js.map |
@@ -1,4 +0,4 @@ | ||
import { Action } from "./Action"; | ||
import { CallbackAction } from "./CallbackAction"; | ||
export declare class AppAction<TPayload = {}> implements Action<TPayload> { | ||
import { Action } from './Action'; | ||
import { CallbackAction } from './CallbackAction'; | ||
export declare class AppAction<TPayload = any> implements Action<TPayload> { | ||
type: any; | ||
@@ -5,0 +5,0 @@ payload: TPayload; |
@@ -1,3 +0,6 @@ | ||
export class AppAction { | ||
constructor(type, payload) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AppAction = void 0; | ||
var AppAction = /** @class */ (function () { | ||
function AppAction(type, payload) { | ||
this.type = type; | ||
@@ -8,30 +11,30 @@ this.payload = payload; | ||
} | ||
static stop(appAction) { | ||
AppAction.stop = function (appAction) { | ||
appAction.stopPropagation = true; | ||
} | ||
static getActions(appAction) { | ||
const actions = []; | ||
if (typeof appAction.callbackAction === "function") { | ||
}; | ||
AppAction.getActions = function (appAction) { | ||
var actions = []; | ||
if (typeof appAction.callbackAction === 'function') { | ||
actions.push(appAction.callbackAction); | ||
} | ||
if (Array.isArray(appAction.actions) && appAction.actions.length > 0) { | ||
appAction.actions.forEach((action) => { | ||
actions.push(() => action); | ||
appAction.actions.forEach(function (action) { | ||
actions.push(function () { return action; }); | ||
}); | ||
} | ||
return actions; | ||
} | ||
stop() { | ||
}; | ||
AppAction.prototype.stop = function () { | ||
AppAction.stop(this); | ||
} | ||
getActions() { | ||
}; | ||
AppAction.prototype.getActions = function () { | ||
return AppAction.getActions(this); | ||
} | ||
toPlainObject() { | ||
const keys = Object.keys(this); | ||
const plainObject = {}; | ||
keys.forEach((key) => { | ||
if (key !== "toPlainObject") { | ||
// @ts-ignore | ||
plainObject[key] = this[key]; | ||
}; | ||
AppAction.prototype.toPlainObject = function () { | ||
var _this = this; | ||
var keys = Object.keys(this); | ||
var plainObject = {}; | ||
keys.forEach(function (key) { | ||
if (key !== 'toPlainObject') { | ||
plainObject[key] = _this[key]; | ||
} | ||
@@ -46,4 +49,6 @@ }); | ||
return plainObject; | ||
} | ||
} | ||
}; | ||
return AppAction; | ||
}()); | ||
exports.AppAction = AppAction; | ||
//# sourceMappingURL=AppAction.js.map |
@@ -1,2 +0,2 @@ | ||
import { Action } from "./Action"; | ||
import { Action } from './Action'; | ||
export declare type CallbackAction = () => Action; |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=CallbackAction.js.map |
@@ -1,5 +0,5 @@ | ||
export * from "./ActionWithCallback"; | ||
export * from "./Action"; | ||
export * from "./CallbackAction"; | ||
export * from "./isAction"; | ||
export * from "./Reducer"; | ||
export * from './ActionWithCallback'; | ||
export * from './Action'; | ||
export * from './CallbackAction'; | ||
export * from './isAction'; | ||
export * from './Reducer'; |
@@ -1,6 +0,9 @@ | ||
export * from "./ActionWithCallback"; | ||
export * from "./Action"; | ||
export * from "./CallbackAction"; | ||
export * from "./isAction"; | ||
export * from "./Reducer"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./ActionWithCallback"), exports); | ||
tslib_1.__exportStar(require("./Action"), exports); | ||
tslib_1.__exportStar(require("./CallbackAction"), exports); | ||
tslib_1.__exportStar(require("./isAction"), exports); | ||
tslib_1.__exportStar(require("./Reducer"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,5 @@ | ||
export function isAction(action) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAction = void 0; | ||
function isAction(action) { | ||
return 'payload' in action | ||
@@ -8,2 +11,3 @@ && 'actions' in action | ||
} | ||
exports.isAction = isAction; | ||
//# sourceMappingURL=isAction.js.map |
@@ -1,3 +0,3 @@ | ||
import { Action } from "./Action"; | ||
import { Action } from './Action'; | ||
declare function Reducer<TStore>(initialStore: TStore, updateActionType: string): (store: TStore | undefined, action: Action) => TStore; | ||
export { Reducer }; |
@@ -0,3 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Reducer = void 0; | ||
var tslib_1 = require("tslib"); | ||
function Reducer(initialStore, updateActionType) { | ||
return (store = initialStore, action) => { | ||
return function (store, action) { | ||
if (store === void 0) { store = initialStore; } | ||
if (action.type !== updateActionType) { | ||
@@ -7,8 +12,8 @@ return store; | ||
if (typeof action.payload === 'object') { | ||
return Object.assign(Object.assign({}, store), action.payload); | ||
return tslib_1.__assign(tslib_1.__assign({}, store), action.payload); | ||
} | ||
return Object.assign({}, store); | ||
return tslib_1.__assign({}, store); | ||
}; | ||
} | ||
export { Reducer }; | ||
exports.Reducer = Reducer; | ||
//# sourceMappingURL=Reducer.js.map |
{ | ||
"name": "app-redux-utils", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Helpful utils for redux", | ||
@@ -15,4 +15,6 @@ "contributors": [ | ||
"prepublishOnly": "npm run lint", | ||
"prepublish": "tsc", | ||
"build": "tsc", | ||
"lint": "tslint -p tsconfig.json", | ||
"lint": "eslint src", | ||
"lint:fix": "eslint src --fix", | ||
"test": "jest" | ||
@@ -29,8 +31,10 @@ }, | ||
"devDependencies": { | ||
"@types/jest": "26.0.14", | ||
"jest": "26.4.2", | ||
"ts-jest": "26.4.1", | ||
"tslint": "6.0.0", | ||
"tslint-eslint-rules": "5.4.0", | ||
"typescript": "4.0.3" | ||
"@types/jest": "26.0.19", | ||
"@typescript-eslint/eslint-plugin": "^4.11.0", | ||
"@typescript-eslint/parser": "^4.11.0", | ||
"eslint": "7.16.0", | ||
"eslint-plugin-sonarjs": "^0.5.0", | ||
"jest": "26.6.3", | ||
"ts-jest": "26.4.4", | ||
"typescript": "4.1.3" | ||
}, | ||
@@ -37,0 +41,0 @@ "repository": { |
@@ -1,2 +0,1 @@ | ||
# | ||
* [install](#Installation) | ||
@@ -3,0 +2,0 @@ * [usage](#How to use) |
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
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
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
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
32842
343
8
361
1