Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

♻️ higher-order reducer to ignore redux actions

License

NotificationsYou must be signed in to change notification settings

omnidan/redux-ignore

Repository files navigation

NPM version (>=1.2)Build StatusDependenciesjs-standard-stylehttps://paypal.me/DanielBugl/10https://gratipay.com/~omnidan/

higher-order reducer to ignore redux actions

can be used to avoid performance problems in large apps by skipping reducer subtrees

Installation

npm install --save redux-ignore

API

import{ignoreActions,filterActions}from'redux-ignore';ignoreActions(reducer,[ARRAY_OF_ACTIONS])ignoreActions(reducer,(action)=>!action.valid)filterActions(reducer,[ARRAY_OF_ACTIONS])filterActions(reducer,(action)=>action.valid)

Ignoring Actions

redux-ignore is a reducer enhancer (higher-order reducer), it provides theignoreActions function, which takes an existing reducer and either:

  • An array of actions to be ignored, or...
  • A predicate function for filtering out actions.

Firstly, importredux-ignore:

// Redux utility functionsimport{combineReducers}from'redux';// redux-ignore higher-order reducerimport{ignoreActions}from'redux-ignore';

Then, addignoreActions to your reducer(s) like this:

combineReducers({counter:ignoreActions(counter,[INCREMENT_COUNTER])});

Now you won't be able to increment the counter anymore, because theINCREMENT_COUNTER action is ignored.

Alternatively, you can ignore actions via a predicate function:

combineReducers({counter:ignoreActions(counter,(action)=>action.type===INCREMENT_COUNTER)});

Filtering Actions

You can also usefilterActions to only accept actions that are declared in an array, or that satisfy the predicate function:

import{combineReducers}from'redux';import{filterActions}from'redux-ignore';// pull in the filterActions functionimport{STAY_COOL,KEEP_CHILLIN}from'./actions';import{counter,notACounter}from'./reducers';combineReducers({counter:filterActions(counter,(action)=>action.type.match(/COUNTER$/)),// only run on actions that satisfy the regexnotACounter:filterActions(notACounter,[STAY_COOL,KEEP_CHILLIN])// only run for these specific relaxing actions});

What is this magic? How does it work?

Have a read of theImplementing Undo History recipein the Redux documents, which explains in detail how higher-order reducers work.

License

MIT, seeLICENSE.md for more information.

About

♻️ higher-order reducer to ignore redux actions

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp