app-redux-utils
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -5,5 +5,5 @@ import { Dispatch, Store } from 'redux'; | ||
export declare abstract class ControllerBase<TState> implements Controller { | ||
constructor(reduxStore: Store<TState, Action>); | ||
protected readonly dispatch: Dispatch<Action>; | ||
protected readonly getState: () => TState; | ||
constructor(reduxStore: Store<TState, Action>); | ||
} |
"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) { | ||
class ControllerBase { | ||
constructor(reduxStore) { | ||
if (new.target === ControllerBase) { | ||
throw new Error('Cannot construct ControllerBase instance directly'); | ||
} | ||
this.dispatch = reduxStore.dispatch; | ||
this.getState = function () { return reduxStore.getState(); }; | ||
this.getState = () => reduxStore.getState(); | ||
} | ||
return ControllerBase; | ||
}()); | ||
} | ||
exports.ControllerBase = ControllerBase; | ||
//# sourceMappingURL=ControllerBase.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.controllerMiddleware = void 0; | ||
var tslib_1 = require("tslib"); | ||
var types_1 = require("../types"); | ||
const tslib_1 = require("tslib"); | ||
const types_1 = require("../types"); | ||
function controllerMiddleware(watchers) { | ||
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*/]; | ||
return (reduxStore) => (next) => (action) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
next(action); | ||
if (!types_1.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); | ||
} | ||
} | ||
}); | ||
}); }; }; }; | ||
} while (!iterator.done); | ||
}); | ||
} | ||
exports.controllerMiddleware = controllerMiddleware; | ||
function controllerGenerator(watchers, reduxStore, initAction) { | ||
var _a; | ||
var actionCursor = 0; | ||
var actions = [function () { return initAction; }]; | ||
let actionCursor = 0; | ||
const actions = [() => initAction]; | ||
function iterator() { | ||
@@ -53,8 +38,8 @@ if (actionCursor >= actions.length) { | ||
} | ||
var action = actions[actionCursor](); | ||
var promises = []; | ||
watchers.forEach(function (watcher) { | ||
var actionName = watcher.get(action.type); | ||
const action = actions[actionCursor](); | ||
const promises = []; | ||
watchers.forEach(watcher => { | ||
const actionName = watcher.get(action.type); | ||
if (actionName) { | ||
var controller = watcher.instance(reduxStore); | ||
const controller = watcher.instance(reduxStore); | ||
promises.push(controller[actionName](action)); | ||
@@ -65,5 +50,5 @@ } | ||
return { | ||
value: Promise.all(promises).then(function () { | ||
value: Promise.all(promises).then(() => { | ||
if (types_1.isAction(action) && !action.stopPropagation) { | ||
actions.splice.apply(actions, tslib_1.__spreadArrays([actionCursor, 0], action.getActions())); | ||
actions.splice(actionCursor, 0, ...action.getActions()); | ||
} | ||
@@ -74,11 +59,11 @@ }), | ||
} | ||
return _a = {}, | ||
_a[Symbol.iterator] = function () { | ||
return { | ||
[Symbol.iterator]() { | ||
return this; | ||
}, | ||
_a.next = function () { | ||
next() { | ||
return iterator(); | ||
}, | ||
_a; | ||
}; | ||
} | ||
//# sourceMappingURL=controllerMiddleware.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./ControllerBase"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./Controller"), exports); |
@@ -5,3 +5,3 @@ import { Store } from 'redux'; | ||
import { ControllerBase } from './ControllerBase'; | ||
export declare type Watcher<TState, TController extends Controller> = { | ||
declare type Watcher<TState, TController extends Controller> = { | ||
has: (actionType: string) => boolean; | ||
@@ -11,2 +11,4 @@ get: (actionType: string) => (keyof TController) | undefined; | ||
}; | ||
export declare function watcher<TState, TController extends Controller>(Controller: new (reduxStore: Store<TState, Action>) => ControllerBase<TState>, watchList: [string, keyof TController][]): Watcher<TState, TController>; | ||
declare function watcher<TState, TController extends Controller>(Controller: new (reduxStore: Store<TState, Action>) => ControllerBase<TState>, watchList: [string, keyof TController][]): Watcher<TState, TController>; | ||
export { watcher }; | ||
export type { Watcher }; |
@@ -5,7 +5,7 @@ "use strict"; | ||
function watcher(Controller, watchList) { | ||
var map = new Map(watchList); | ||
const map = new Map(watchList); | ||
return { | ||
has: function (actionType) { return map.has(actionType); }, | ||
get: function (actionType) { return map.get(actionType); }, | ||
instance: function (reduxStore) { return new Controller(reduxStore); }, | ||
has: (actionType) => map.has(actionType), | ||
get: (actionType) => map.get(actionType), | ||
instance: (reduxStore) => new Controller(reduxStore), | ||
}; | ||
@@ -12,0 +12,0 @@ } |
"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; | ||
const AppAction_1 = require("./types/AppAction"); | ||
function createAction(actionType, payload = {}) { | ||
let _payload; | ||
if (typeof payload === 'object' && !Array.isArray(payload)) { | ||
_payload = tslib_1.__assign({}, payload); | ||
_payload = Object.assign({}, payload); | ||
} | ||
@@ -12,0 +10,0 @@ else { |
"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) { | ||
const createAction_1 = require("./createAction"); | ||
function createActionWithCallback(actionType, payload = {}) { | ||
const appAction = createAction_1.createAction(actionType, payload); | ||
const actionWithCallback = (callbackAction) => { | ||
if (typeof callbackAction === 'function') { | ||
@@ -10,0 +9,0 @@ appAction.callbackAction = callbackAction; |
import { Reducer, ReducersMapObject } from 'redux'; | ||
export declare function createReducers<TReducers>(getReducers: (...params: any) => ReducersMapObject<TReducers, any>, ...params: any): Reducer<TReducers>; | ||
export declare function createReducers<TReducers>(getReducers: (...params: any[]) => ReducersMapObject<TReducers, any>, ...params: any[]): Reducer<TReducers>; |
"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); | ||
const redux_1 = require("redux"); | ||
function createReducers(getReducers, ...params) { | ||
const reducers = getReducers(...params); | ||
return redux_1.combineReducers(reducers); | ||
@@ -12,0 +8,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./controller"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./createAction"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AppAction = void 0; | ||
var AppAction = /** @class */ (function () { | ||
function AppAction(type, payload) { | ||
class AppAction { | ||
constructor(type, payload) { | ||
this.type = type; | ||
@@ -11,7 +11,7 @@ this.payload = payload; | ||
} | ||
AppAction.stop = function (appAction) { | ||
static stop(appAction) { | ||
appAction.stopPropagation = true; | ||
}; | ||
AppAction.getActions = function (appAction) { | ||
var actions = []; | ||
} | ||
static getActions(appAction) { | ||
const actions = []; | ||
if (typeof appAction.callbackAction === 'function') { | ||
@@ -21,21 +21,20 @@ actions.push(appAction.callbackAction); | ||
if (Array.isArray(appAction.actions) && appAction.actions.length > 0) { | ||
appAction.actions.forEach(function (action) { | ||
actions.push(function () { return action; }); | ||
appAction.actions.forEach(action => { | ||
actions.push(() => action); | ||
}); | ||
} | ||
return actions; | ||
}; | ||
AppAction.prototype.stop = function () { | ||
} | ||
stop() { | ||
AppAction.stop(this); | ||
}; | ||
AppAction.prototype.getActions = function () { | ||
} | ||
getActions() { | ||
return AppAction.getActions(this); | ||
}; | ||
AppAction.prototype.toPlainObject = function () { | ||
var _this = this; | ||
var keys = Object.keys(this); | ||
var plainObject = {}; | ||
keys.forEach(function (key) { | ||
} | ||
toPlainObject() { | ||
const keys = Object.keys(this); | ||
const plainObject = {}; | ||
keys.forEach(key => { | ||
if (key !== 'toPlainObject') { | ||
plainObject[key] = _this[key]; | ||
plainObject[key] = this[key]; | ||
} | ||
@@ -50,6 +49,5 @@ }); | ||
return plainObject; | ||
}; | ||
return AppAction; | ||
}()); | ||
} | ||
} | ||
exports.AppAction = AppAction; | ||
//# sourceMappingURL=AppAction.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./ActionWithCallback"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./Action"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Reducer = void 0; | ||
var tslib_1 = require("tslib"); | ||
function Reducer(initialStore, updateActionType) { | ||
return function (store, action) { | ||
if (store === void 0) { store = initialStore; } | ||
return (store = initialStore, action) => { | ||
if (action.type !== updateActionType) { | ||
@@ -12,5 +10,5 @@ return store; | ||
if (typeof action.payload === 'object') { | ||
return tslib_1.__assign(tslib_1.__assign({}, store), action.payload); | ||
return Object.assign(Object.assign({}, store), action.payload); | ||
} | ||
return tslib_1.__assign({}, store); | ||
return Object.assign({}, store); | ||
}; | ||
@@ -17,0 +15,0 @@ } |
{ | ||
"name": "app-redux-utils", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Helpful utils for redux", | ||
@@ -27,13 +27,13 @@ "contributors": [ | ||
"dependencies": { | ||
"redux": "4.0.5" | ||
"redux": "4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@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", | ||
"@types/jest": "26.0.23", | ||
"@typescript-eslint/eslint-plugin": "4.25.0", | ||
"@typescript-eslint/parser": "4.25.0", | ||
"eslint": "7.27.0", | ||
"eslint-plugin-sonarjs": "0.7.0", | ||
"jest": "26.6.3", | ||
"ts-jest": "26.4.4", | ||
"typescript": "4.1.3" | ||
"ts-jest": "26.5.6", | ||
"typescript": "4.2.4" | ||
}, | ||
@@ -40,0 +40,0 @@ "repository": { |
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
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
0
31155
317
+ Added@babel/runtime@7.26.0(transitive)
+ Addedredux@4.1.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedredux@4.0.5(transitive)
- Removedsymbol-observable@1.2.0(transitive)
Updatedredux@4.1.0