Comparing version 0.6.1 to 0.6.2
@@ -1,2 +0,2 @@ | ||
import { TExportedActionCreator, TDynamicExportedActionCreator, TActionPayloadCreator } from "../types/types"; | ||
import { TExportedActionCreator, TDynamicExportedActionCreator, TActionPayloadCreator, TArgs } from "../types/types"; | ||
import { IActionCreatorBuilder } from "../types/IActionCreatorBuilder"; | ||
@@ -10,6 +10,6 @@ export declare class ActionCreatorBuilder implements IActionCreatorBuilder { | ||
}>(actionTypeCodes: T[]): U; | ||
build<A, P>(actionTypeCode: string, creator?: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P>; | ||
extend<A, P>(action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P>; | ||
buildDynamic<A, P = any>(creator: TDynamicExportedActionCreator<A, P>): TDynamicExportedActionCreator<A, P>; | ||
build<A extends TArgs, P>(actionTypeCode: string, creator?: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P>; | ||
extend<A extends TArgs, P>(action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P>; | ||
buildDynamic<A extends TArgs, P>(creator: TDynamicExportedActionCreator<A, P>): TDynamicExportedActionCreator<A, P>; | ||
private getExportedActionCreator; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class ActionCreatorBuilder { | ||
constructor(reducerCode = '', reducerJoinSymbol = '_') { | ||
var ActionCreatorBuilder = /** @class */ (function () { | ||
function ActionCreatorBuilder(reducerCode, reducerJoinSymbol) { | ||
if (reducerCode === void 0) { reducerCode = ''; } | ||
if (reducerJoinSymbol === void 0) { reducerJoinSymbol = '_'; } | ||
this.actionTypePrefix = (reducerCode) ? reducerCode + reducerJoinSymbol : ''; | ||
} | ||
getConst(actionTypeCode) { | ||
ActionCreatorBuilder.prototype.getConst = function (actionTypeCode) { | ||
return this.actionTypePrefix + actionTypeCode; | ||
} | ||
getConstants(actionTypeCodes) { | ||
const result = {}; | ||
actionTypeCodes.forEach((actionTypeCode) => { | ||
result[actionTypeCode] = this.actionTypePrefix + actionTypeCode; | ||
}; | ||
ActionCreatorBuilder.prototype.getConstants = function (actionTypeCodes) { | ||
var _this = this; | ||
var result = {}; | ||
actionTypeCodes.forEach(function (actionTypeCode) { | ||
result[actionTypeCode] = _this.actionTypePrefix + actionTypeCode; | ||
}); | ||
return result; | ||
} | ||
build(actionTypeCode, creator) { | ||
const typeCode = this.getConst(actionTypeCode); | ||
}; | ||
ActionCreatorBuilder.prototype.build = function (actionTypeCode, creator) { | ||
var typeCode = this.getConst(actionTypeCode); | ||
return this.getExportedActionCreator(typeCode, creator); | ||
} | ||
extend(action, creator) { | ||
const typeCode = action.typeCode; | ||
}; | ||
ActionCreatorBuilder.prototype.extend = function (action, creator) { | ||
var typeCode = action.typeCode; | ||
return this.getExportedActionCreator(typeCode, creator); | ||
} | ||
buildDynamic(creator) { | ||
}; | ||
ActionCreatorBuilder.prototype.buildDynamic = function (creator) { | ||
return creator; | ||
} | ||
getExportedActionCreator(typeCode, creator) { | ||
const actionCreator = function (...args) { | ||
}; | ||
ActionCreatorBuilder.prototype.getExportedActionCreator = function (typeCode, creator) { | ||
var actionCreator = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return { | ||
@@ -37,4 +44,5 @@ type: typeCode, | ||
return actionCreator; | ||
} | ||
} | ||
}; | ||
return ActionCreatorBuilder; | ||
}()); | ||
exports.ActionCreatorBuilder = ActionCreatorBuilder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ActionCreatorBuilder_1 = require("./ActionCreatorBuilder"); | ||
const ReducerBuilder_1 = require("./ReducerBuilder"); | ||
exports.getActionCreator = (reducerCode, joinSymbol = '_') => { | ||
var ActionCreatorBuilder_1 = require("./ActionCreatorBuilder"); | ||
var ReducerBuilder_1 = require("./ReducerBuilder"); | ||
exports.getActionCreator = function (reducerCode, joinSymbol) { | ||
if (joinSymbol === void 0) { joinSymbol = '_'; } | ||
return new ActionCreatorBuilder_1.ActionCreatorBuilder(reducerCode, joinSymbol); | ||
}; | ||
exports.getReducerBuilder = (defaultState) => { | ||
exports.getReducerBuilder = function (defaultState) { | ||
return new ReducerBuilder_1.ReducerBuilder(defaultState); | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class ReducerBuilder { | ||
constructor(defaultState) { | ||
var ReducerBuilder = /** @class */ (function () { | ||
function ReducerBuilder(defaultState) { | ||
this.defaultState = defaultState; | ||
@@ -9,11 +9,12 @@ this.handlers = new Map(); | ||
} | ||
setDefaultState(state) { | ||
ReducerBuilder.prototype.setDefaultState = function (state) { | ||
this.defaultState = state; | ||
return this; | ||
} | ||
copyState() { | ||
}; | ||
ReducerBuilder.prototype.copyState = function () { | ||
this.toCopyState = true; | ||
return this; | ||
} | ||
handle(actionCreators, handler) { | ||
}; | ||
ReducerBuilder.prototype.handle = function (actionCreators, handler) { | ||
var _this = this; | ||
if (typeof handler !== 'function') { | ||
@@ -23,3 +24,3 @@ throw TypeError('Reducer Action Handler should be a function!'); | ||
if (Array.isArray(actionCreators)) { | ||
actionCreators.forEach((actionCreator) => { this.handlers.set(actionCreator.typeCode, handler); }); | ||
actionCreators.forEach(function (actionCreator) { _this.handlers.set(actionCreator.typeCode, handler); }); | ||
} | ||
@@ -30,4 +31,5 @@ else { | ||
return this; | ||
} | ||
handleType(actionTypes, handler) { | ||
}; | ||
ReducerBuilder.prototype.handleType = function (actionTypes, handler) { | ||
var _this = this; | ||
if (typeof handler !== 'function') { | ||
@@ -37,3 +39,3 @@ throw TypeError('Reducer Action Handler should be a function!'); | ||
if (Array.isArray(actionTypes)) { | ||
actionTypes.forEach((actionType) => { this.handlers.set(actionType, handler); }); | ||
actionTypes.forEach(function (actionType) { _this.handlers.set(actionType, handler); }); | ||
} | ||
@@ -44,15 +46,16 @@ else { | ||
return this; | ||
} | ||
build() { | ||
return (state, action) => { | ||
state = state || this.defaultState; | ||
}; | ||
ReducerBuilder.prototype.build = function () { | ||
var _this = this; | ||
return function (state, action) { | ||
state = state || _this.defaultState; | ||
if (!action) { | ||
return state; | ||
} | ||
if (this.handlers.has(action.type)) { | ||
if (this.toCopyState) { | ||
return Object.assign({}, state, Reflect.apply(this.handlers.get(action.type), undefined, [state, action])); | ||
if (_this.handlers.has(action.type)) { | ||
if (_this.toCopyState) { | ||
return Object.assign({}, state, Reflect.apply(_this.handlers.get(action.type), undefined, [state, action])); | ||
} | ||
else { | ||
return Reflect.apply(this.handlers.get(action.type), undefined, [state, action]); | ||
return Reflect.apply(_this.handlers.get(action.type), undefined, [state, action]); | ||
} | ||
@@ -64,4 +67,5 @@ } | ||
}; | ||
} | ||
} | ||
}; | ||
return ReducerBuilder; | ||
}()); | ||
exports.ReducerBuilder = ReducerBuilder; |
{ | ||
"name": "redux-ease", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Reduce Redux boilerplate with ease", | ||
"main": "dist/index.js", | ||
"main": "dist/index", | ||
"types": "dist/index.d.ts", | ||
@@ -11,4 +11,11 @@ "author": "Max Kobozev <quesesr@gmail.com>", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest" | ||
"build": "npm-run-all clear tsc minify", | ||
"build-pack": "npm-run-all build npm:pack", | ||
"watch": "npm-run-all clear tsc-watch", | ||
"test": "jest", | ||
"tsc": "tsc", | ||
"npm:pack": "npm pack", | ||
"tsc-watch": "tsc --watch", | ||
"minify": "uglifyjs --compress --mangle --source-map \"filename='dist/**.js'\" --output dist/index.min.js dist/**.js", | ||
"clear": "rimraf dist" | ||
}, | ||
@@ -18,5 +25,7 @@ "devDependencies": { | ||
"jest": "^24.8.0", | ||
"npm-run-all": "^4.1.5", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.4.5" | ||
"typescript": "^3.4.5", | ||
"uglify-js": "^3.5.14" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { TExportedActionCreator, TOptionalPayloadAction, TDynamicExportedActionCreator, TActionPayloadCreator } from "../types/types"; | ||
import { TExportedActionCreator, TDynamicExportedActionCreator, TActionPayloadCreator, TArgs } from "../types/types"; | ||
import { IActionCreatorBuilder } from "../types/IActionCreatorBuilder"; | ||
@@ -24,3 +24,3 @@ | ||
build <A, P> (actionTypeCode: string, creator?: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> { | ||
build <A extends TArgs, P> (actionTypeCode: string, creator?: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> { | ||
const typeCode = this.getConst(actionTypeCode) | ||
@@ -30,3 +30,3 @@ return this.getExportedActionCreator(typeCode, creator) | ||
extend <A, P> (action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> { | ||
extend <A extends TArgs, P> (action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> { | ||
const typeCode = action.typeCode | ||
@@ -36,10 +36,10 @@ return this.getExportedActionCreator(typeCode, creator) | ||
buildDynamic <A, P = any> (creator: TDynamicExportedActionCreator<A, P>): TDynamicExportedActionCreator<A, P> { | ||
buildDynamic <A extends TArgs, P> (creator: TDynamicExportedActionCreator<A, P>): TDynamicExportedActionCreator<A, P> { | ||
return creator | ||
} | ||
private getExportedActionCreator <A, P> ( | ||
private getExportedActionCreator <A extends TArgs, P> ( | ||
typeCode: string, creator?: TActionPayloadCreator<A, P> | ||
): TExportedActionCreator<A, P> { | ||
const actionCreator = function (...args: A[]) { | ||
const actionCreator = function (...args: A) { | ||
return { | ||
@@ -46,0 +46,0 @@ type: typeCode, |
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"target": "es5", | ||
"module": "commonjs", | ||
"lib": [ "es2018" ], | ||
"declaration": true, | ||
@@ -6,0 +7,0 @@ "outDir": "./dist", |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
182743
25
425
6
3