New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

re-reduced

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

re-reduced - npm Package Compare versions

Comparing version 0.10.4 to 0.11.0

5

examples/Counter/reducers.ts
import { combineReducers } from "redux";
import { handleActions } from "../../src";
import { createReducer } from "../../src";
import actions from "./actions";

@@ -9,3 +10,3 @@ import { State } from "./types";

export const counter = handleActions<number>(
export const counter = createReducer<number>(
[

@@ -12,0 +13,0 @@ actions.increment.reduce(state => state + 1),

22

examples/ToDo/reducers.ts
import { combineReducers } from "redux";
import { dissoc, without, assoc, indexBy } from "ramda";
import { handleActions, match } from "../../src";
import { createReducer, match } from "../../src";

@@ -22,5 +22,5 @@ import actions from "./actions";

export const todos = handleActions<ToDosState>(
export const todos = createReducer<ToDosState>(
[
// fetch handlers
// [fetch] handlers
match(actions.todos.fetch.request, state => ({

@@ -36,8 +36,8 @@ ...state,

})),
// add handlers
actions.todos.add.request.reduce(state => ({
// [add] handlers
match(actions.todos.add.request, state => ({
...state,
isAdding: true
})),
actions.todos.add.success.reduce((state, todo) => ({
match(actions.todos.add.success, (state, todo) => ({
...state,

@@ -48,9 +48,9 @@ byId: assoc(todo.id, todo, state.byId),

})),
// update handlers
actions.todos.update.reduce((state, todo) => ({
// [update] handlers
match(actions.todos.update, (state, todo) => ({
...state,
byId: assoc(todo.id, todo, state.byId)
})),
// delete handlers
actions.todos.delete.reduce((state, id) => ({
// [delete] handlers
match(actions.todos.delete, (state, id) => ({
...state,

@@ -64,3 +64,3 @@ byId: dissoc<ToDoMap>(id, state.byId),

export const tags = handleActions([], INITIAL_STATE.tags);
export const tags = createReducer([], INITIAL_STATE.tags);

@@ -67,0 +67,0 @@ export default combineReducers<State>({

import { ActionCreator, AsyncAction } from "./core";
/**
* returns an action-creator function
*
* @param type - the action identifier, must be unique
* @param namespace - optional namespace string to be prepended to the type
*/
export declare function createAction<TPayload, TMeta = any>(type: string, namespace?: string): ActionCreator<TPayload, TMeta>;
/**
* return a composite action-creator with nested action-creators for request, success and failure
*
* @param type - the action identifier, must be unique
* @param namespace - optional namespace string to be prepended to the type
*/
export declare function createAsyncAction<TRun, TSuccess, TFailure = Error>(type: string, namespace?: string): AsyncAction<TRun, TSuccess, TFailure>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* returns an action-creator function
*
* @param type - the action identifier, must be unique
* @param namespace - optional namespace string to be prepended to the type
*/
function createAction(type, namespace) {

@@ -18,2 +24,8 @@ const $type = namespace ? `${namespace}/${type}` : type;

exports.createAction = createAction;
/**
* return a composite action-creator with nested action-creators for request, success and failure
*
* @param type - the action identifier, must be unique
* @param namespace - optional namespace string to be prepended to the type
*/
function createAsyncAction(type, namespace) {

@@ -20,0 +32,0 @@ const asyncAction = createAction(type, namespace);

@@ -25,6 +25,13 @@ import { Reducer } from "redux";

}) => ReducerConfig<TActions, TState>;
export declare function handleActions<TState>(handlers: ActionReducerMap<TState> | Array<ActionReducerMap<TState>>, initialState: TState): Reducer<TState>;
export declare function createReducer<TState>(handlers: ActionReducerMap<TState> | Array<ActionReducerMap<TState>>, initialState: TState): Reducer<TState>;
export declare const handleActions: typeof createReducer;
/**
* registers a reducer handler for a given action
*
* @param action
* @param reducer
*/
export declare function match<TPayload, TState>(action: ActionCreator<TPayload>, reducer: ActionReducer<TState, TPayload>): {
[key: string]: ActionReducer<TState, TPayload>;
};
export declare const createReducer: <TActions, TState>(functor: ReducerFunctor<TActions, TState>, defaultInitialState: TState) => ReducerFactory<TActions, TState>;
export declare const createReducerFactory: <TActions, TState>(functor: ReducerFunctor<TActions, TState>, defaultInitialState: TState) => ReducerFactory<TActions, TState>;

@@ -7,3 +7,3 @@ "use strict";

exports.reducerConfigWithState = (config) => (Object.assign({}, config, { idKey: "" }));
function handleActions(handlers, initialState) {
function createReducer(handlers, initialState) {
const $handlers = Array.isArray(handlers)

@@ -20,3 +20,11 @@ ? ramda_1.mergeAll(handlers)

}
exports.handleActions = handleActions;
exports.createReducer = createReducer;
// temporary alias for createReducer
exports.handleActions = createReducer;
/**
* registers a reducer handler for a given action
*
* @param action
* @param reducer
*/
function match(action, reducer) {

@@ -30,3 +38,3 @@ return action.reduce(reducer);

};
exports.createReducer = (functor, defaultInitialState) => {
exports.createReducerFactory = (functor, defaultInitialState) => {
const finalFunctor = (Array.isArray(functor)

@@ -41,3 +49,3 @@ ? combineFunctors(functor)

const handlers = ramda_1.merge(finalFunctor(Object.assign({}, config, { initialState })), customHandlers);
return handleActions(handlers, initialState);
return createReducer(handlers, initialState);
};

@@ -44,0 +52,0 @@ reducerFactory.functor = finalFunctor;

{
"name": "re-reduced",
"version": "0.10.4",
"version": "0.11.0",
"description": "A utility toolbelt that reduces boilerplate from your react/redux app",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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