Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reducer-composer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reducer-composer - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/createBatchHandler.d.ts

7

dist/createReducerCrudHandlers.d.ts

@@ -7,2 +7,9 @@ export declare function createReducerCrudHandlers<Entity, EntityPayload, KeyPayload>(entitySelector: (payload: EntityPayload) => [string, Entity], keySelector: (payload: KeyPayload) => string): {

discard: (record: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: KeyPayload) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
batch: {
create: (state: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: EntityPayload[]) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
update: (state: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: EntityPayload[]) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
delete: (state: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: KeyPayload[]) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
upsert: (state: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: EntityPayload[]) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
discard: (state: import("./utility").DeepReadonlyObject<Record<string, Entity>>, payload: EntityPayload[]) => import("./utility").DeepReadonlyObject<Record<string, Entity>>;
};
};

65

dist/createReducerCrudHandlers.js

@@ -23,2 +23,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var createBatchHandler_1 = require("./createBatchHandler");
function createReducerCrudHandlers(entitySelector, keySelector) {

@@ -32,34 +33,46 @@ var withEntity = function (f) { return function (record, payload) {

}; };
return {
create: withEntity(function (state, key, entity) {
var _a;
if (Object.prototype.hasOwnProperty.call(state, key)) {
throw new Error();
}
return __assign({}, state, (_a = {}, _a[key] = entity, _a));
}),
update: withEntity(function (state, key, entity) {
var _a;
if (Object.prototype.hasOwnProperty.call(state, key)) {
return __assign({}, state, (_a = {}, _a[key] = entity, _a));
}
var create = withEntity(function (state, key, entity) {
var _a;
if (Object.prototype.hasOwnProperty.call(state, key)) {
throw new Error();
}),
delete: withKey(function (state, key) {
if (Object.prototype.hasOwnProperty.call(state, key)) {
var _a = key, removed = state[_a], rest = __rest(state, [typeof _a === "symbol" ? _a : _a + ""]);
return rest;
}
throw new Error();
}),
upsert: withEntity(function (state, key, entity) {
var _a;
}
return __assign({}, state, (_a = {}, _a[key] = entity, _a));
});
var update = withEntity(function (state, key, entity) {
var _a;
if (Object.prototype.hasOwnProperty.call(state, key)) {
return __assign({}, state, (_a = {}, _a[key] = entity, _a));
}),
discard: withKey(function (state, key) {
}
throw new Error();
});
var delet = withKey(function (state, key) {
if (Object.prototype.hasOwnProperty.call(state, key)) {
var _a = key, removed = state[_a], rest = __rest(state, [typeof _a === "symbol" ? _a : _a + ""]);
return rest;
})
}
throw new Error();
});
var upsert = withEntity(function (state, key, entity) {
var _a;
return __assign({}, state, (_a = {}, _a[key] = entity, _a));
});
var discard = withKey(function (state, key) {
var _a = key, removed = state[_a], rest = __rest(state, [typeof _a === "symbol" ? _a : _a + ""]);
return rest;
});
return {
create: create,
update: update,
delete: delet,
upsert: upsert,
discard: discard,
batch: {
create: createBatchHandler_1.createBatchHandler(create),
update: createBatchHandler_1.createBatchHandler(update),
delete: createBatchHandler_1.createBatchHandler(delet),
upsert: createBatchHandler_1.createBatchHandler(upsert),
discard: createBatchHandler_1.createBatchHandler(upsert)
}
};
}
exports.createReducerCrudHandlers = createReducerCrudHandlers;

2

dist/index.d.ts

@@ -9,2 +9,4 @@ export { createReducer } from "./createReducer";

export { createReducerCrudHandlers } from "./createReducerCrudHandlers";
export { createBatchHandler } from "./createBatchHandler";
export { withInitialState } from "./withInitialState";
export * from "./utility";

@@ -22,2 +22,6 @@ "use strict";

exports.createReducerCrudHandlers = createReducerCrudHandlers_1.createReducerCrudHandlers;
var createBatchHandler_1 = require("./createBatchHandler");
exports.createBatchHandler = createBatchHandler_1.createBatchHandler;
var withInitialState_1 = require("./withInitialState");
exports.withInitialState = withInitialState_1.withInitialState;
__export(require("./utility"));

@@ -117,3 +117,4 @@ "use strict";

CAR_UPDATE: carCrud.update,
CAR_DESTROY: carCrud.discard
CAR_DESTROY: carCrud.discard,
CAR_ADD_MANY: reducer_composer_1.createBatchHandler(carCrud.create)
});

@@ -209,3 +210,4 @@ var rentReducer = reducer_composer_1.createReducer()({

USER_CHANGE_BIRTH: reducer_composer_1.ignore,
USER_CHANGE_NAME: reducer_composer_1.ignore
USER_CHANGE_NAME: reducer_composer_1.ignore,
CAR_ADD_MANY: reducer_composer_1.ignore
});

@@ -212,0 +214,0 @@ var safeCarRentCompanyReducer = reducer_composer_1.createReducerSequence(precondition, carRentCompanyReducer, postCondition);

@@ -11,3 +11,3 @@ {

],
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",

@@ -14,0 +14,0 @@ "author": "Frederik Batuna",

import { DeepReadonly } from "./utility";
import { createBatchHandler } from "./createBatchHandler";

@@ -27,30 +28,42 @@ export function createReducerCrudHandlers<Entity, EntityPayload, KeyPayload>(

f(record, keySelector(payload));
return {
create: withEntity((state, key, entity) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
throw new Error();
}
return { ...state, [key]: entity };
}),
update: withEntity((state, key, entity) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
return { ...state, [key]: entity };
}
const create = withEntity((state, key, entity) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
throw new Error();
}),
delete: withKey((state, key) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
const { [key]: removed, ...rest } = state;
return rest as DeepReadonly<Record<string, Entity>>;
}
throw new Error();
}),
upsert: withEntity((state, key, entity) => {
}
return { ...state, [key]: entity };
});
const update = withEntity((state, key, entity) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
return { ...state, [key]: entity };
}),
discard: withKey((state, key) => {
}
throw new Error();
});
const delet = withKey((state, key) => {
if (Object.prototype.hasOwnProperty.call(state, key)) {
const { [key]: removed, ...rest } = state;
return rest as DeepReadonly<Record<string, Entity>>;
})
}
throw new Error();
});
const upsert = withEntity((state, key, entity) => {
return { ...state, [key]: entity };
});
const discard = withKey((state, key) => {
const { [key]: removed, ...rest } = state;
return rest as DeepReadonly<Record<string, Entity>>;
});
return {
create,
update,
delete: delet,
upsert,
discard,
batch: {
create: createBatchHandler(create),
update: createBatchHandler(update),
delete: createBatchHandler(delet),
upsert: createBatchHandler(upsert),
discard: createBatchHandler(upsert)
}
};
}

@@ -9,2 +9,4 @@ export { createReducer } from "./createReducer";

export { createReducerCrudHandlers } from "./createReducerCrudHandlers";
export { createBatchHandler } from "./createBatchHandler";
export { withInitialState } from "./withInitialState";
export * from "./utility";

@@ -12,3 +12,4 @@ import {

ignore,
createReducerCrudHandlers
createReducerCrudHandlers,
createBatchHandler
} from "reducer-composer";

@@ -173,3 +174,4 @@

CAR_UPDATE: carCrud.update,
CAR_DESTROY: carCrud.discard
CAR_DESTROY: carCrud.discard,
CAR_ADD_MANY: createBatchHandler(carCrud.create)
});

@@ -280,3 +282,4 @@

USER_CHANGE_BIRTH: ignore,
USER_CHANGE_NAME: ignore
USER_CHANGE_NAME: ignore,
CAR_ADD_MANY: ignore
});

@@ -283,0 +286,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc