├── .babelrc ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE.md ├── README.md ├── package.json ├── src ├── FilterMonitor.js ├── index.js └── reducers.js └── test └── index.spec.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015-loose", "stage-0", "react"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | lib 2 | **/node_modules 3 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-airbnb", 3 | "env": { 4 | "browser": true, 5 | "mocha": true, 6 | "node": true 7 | }, 8 | "rules": { 9 | "react/jsx-uses-react": 2, 10 | "react/jsx-uses-vars": 2, 11 | "react/react-in-jsx-scope": 2, 12 | "no-console": 0, 13 | // Temporarily disabled due to babel-eslint issues: 14 | "block-scoped-var": 0, 15 | "padded-blocks": 0, 16 | }, 17 | "plugins": [ 18 | "react" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | lib 5 | coverage 6 | .idea 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "iojs" 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | See all notable changes on [Releases](https://github.com/zalmoxisus/redux-devtools-filter-actions/releases) page. 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dan Abramov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Redux DevTools Filter Actions 2 | ============================== 3 | 4 | A composable monitor for [Redux DevTools](https://github.com/gaearon/redux-devtools) with the ability to specify actions to be hidden (blacklisted) or shown (whitelisted). 5 | 6 | ### Installation 7 | 8 | ``` 9 | npm install --save-dev redux-devtools-filter-actions 10 | ``` 11 | 12 | ### Usage 13 | 14 | Wrap any other Redux DevTools monitor in `FilterMonitor`. For example, you can use it together with [`LogMonitor`](https://github.com/gaearon/redux-devtools-log-monitor): 15 | 16 | ##### `containers/DevTools.js` 17 | 18 | ```js 19 | import React from 'react'; 20 | import { createDevTools } from 'redux-devtools'; 21 | import FilterMonitor from 'redux-devtools-filter-actions'; 22 | import LogMonitor from 'redux-devtools-log-monitor'; 23 | 24 | // Stripping big data which slows down DevTools Monitor 25 | const actionsFilter = (action) => ( 26 | action.type === 'FILE_DOWNLOAD_SUCCESS' && action.data ? 27 | { ...action, data: '<>' } : action 28 | ); 29 | 30 | export default createDevTools( 31 | state.data ? { ...state, data: '<>' } : state} 35 | > 36 | 37 | 38 | ); 39 | ``` 40 | 41 | Also, you can wrap it into the [`DockMonitor`](https://github.com/gaearon/redux-devtools-dock-monitor) to make it dockable. 42 | 43 | [Read how to start using Redux DevTools.](https://github.com/gaearon/redux-devtools) 44 | 45 | ### Props 46 | 47 | Name | Description 48 | ------------- | ------------- 49 | `blacklist` | An array of actions (regex as string) to be hidden in the child monitor. 50 | `whitelist` | An array of actions (regex as string) to be shown. If specified, other than those actions will be hidden (the 'blacklist' parameter will be ignored). 51 | `actionsFilter` | Function which takes `action` object and id number as arguments, and should return `action` object back. See the example above. 52 | `statesFilter` | Function which takes `state` object and index as arguments, and should return `state` object back. See the example above. 53 | 54 | ### License 55 | 56 | MIT 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redux-devtools-filter-actions", 3 | "version": "1.2.2", 4 | "description": "A composable monitor for Redux DevTools with the ability to filter actions.", 5 | "main": "lib/index.js", 6 | "files": [ 7 | "lib" 8 | ], 9 | "scripts": { 10 | "clean": "rimraf lib", 11 | "build": "babel src --out-dir lib", 12 | "lint": "eslint src test", 13 | "test": "NODE_ENV=test mocha --compilers js:babel-core/register --recursive", 14 | "test:watch": "NODE_ENV=test mocha --compilers js:babel-core/register --recursive --watch", 15 | "prepublish": "npm run lint && npm run test && npm run clean && npm run build" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/zalmoxisus/redux-devtools-filter-actions.git" 20 | }, 21 | "keywords": [ 22 | "redux", 23 | "devtools", 24 | "flux", 25 | "react", 26 | "hot reloading", 27 | "time travel", 28 | "live edit" 29 | ], 30 | "author": "Mihail Diordiev (https://github.com/zalmoxisus)", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/zalmoxisus/redux-devtools-filter-actions/issues" 34 | }, 35 | "homepage": "https://github.com/zalmoxisus/redux-devtools-filter-actions", 36 | "devDependencies": { 37 | "babel-cli": "^6.3.15", 38 | "babel-core": "^6.1.20", 39 | "babel-eslint": "^5.0.0-beta4", 40 | "babel-loader": "^6.2.0", 41 | "babel-preset-es2015-loose": "^6.1.3", 42 | "babel-preset-react": "^6.3.13", 43 | "babel-preset-stage-0": "^6.3.13", 44 | "eslint": "^0.23", 45 | "eslint-config-airbnb": "0.0.6", 46 | "eslint-plugin-react": "^3.6.3", 47 | "expect": "^1.6.0", 48 | "mocha": "^2.2.5", 49 | "mocha-jsdom": "^1.0.0", 50 | "prop-types": "^15.5.8", 51 | "rimraf": "^2.3.4", 52 | "webpack": "^1.11.0" 53 | }, 54 | "peerDependencies": { 55 | "react": "^0.14.9 || ^15.3.0", 56 | "redux-devtools": "^3.4.0" 57 | }, 58 | "dependencies": { 59 | "lodash": "^4.12.0" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/FilterMonitor.js: -------------------------------------------------------------------------------- 1 | import { cloneElement, Component } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import mapValues from 'lodash/mapValues'; 4 | import reducer from './reducers'; 5 | 6 | export default class FilterMonitor extends Component { 7 | static update = reducer; 8 | 9 | static propTypes = { 10 | children: PropTypes.element, 11 | whitelist: PropTypes.array, 12 | blacklist: PropTypes.array 13 | }; 14 | 15 | isNotFiltered(actionType) { 16 | const type = actionType || ''; 17 | return ( 18 | this.props.whitelist && type.match(this.props.whitelist.join('|')) || 19 | this.props.blacklist && !type.match(this.props.blacklist.join('|')) 20 | ); 21 | } 22 | 23 | render() { 24 | let { 25 | whitelist, blacklist, actionsFilter, statesFilter, 26 | monitorState, children, actionsById, stagedActionIds, computedStates, 27 | ...rest 28 | } = this.props; 29 | let filteredStagedActionIds = []; 30 | let filteredComputedStates = []; 31 | let filteredActionsById = {}; 32 | 33 | if (whitelist || blacklist) { 34 | stagedActionIds.forEach((id, idx) => { 35 | if (this.isNotFiltered(actionsById[id].action.type)) { 36 | filteredStagedActionIds.push(id); 37 | filteredComputedStates.push( 38 | statesFilter ? 39 | { ...computedStates[idx], state: statesFilter(computedStates[idx].state, idx) } : 40 | computedStates[idx] 41 | ); 42 | filteredActionsById[id] = ( 43 | actionsFilter ? 44 | { ...actionsById[id], action: actionsFilter(actionsById[id].action, id) } : 45 | actionsById[id] 46 | ); 47 | } 48 | }); 49 | 50 | rest = { 51 | ...rest, 52 | actionsById: filteredActionsById, 53 | stagedActionIds: filteredStagedActionIds, 54 | computedStates: filteredComputedStates 55 | }; 56 | } else { 57 | if (actionsFilter) { 58 | filteredActionsById = mapValues(actionsById, (action, id) => ( 59 | { ...action, action: actionsFilter(action.action, id) } 60 | )); 61 | } else filteredActionsById = actionsById; 62 | 63 | if (statesFilter) { 64 | filteredComputedStates = computedStates.map((state, idx) => ( 65 | { ...state, state: statesFilter(state.state, idx) } 66 | )); 67 | } else filteredComputedStates = computedStates; 68 | 69 | rest = { 70 | ...rest, 71 | stagedActionIds, 72 | actionsById: filteredActionsById, 73 | computedStates: filteredComputedStates 74 | }; 75 | } 76 | 77 | const childProps = { 78 | ...rest, 79 | monitorState: monitorState.childMonitorState || {} 80 | }; 81 | return cloneElement(children, childProps); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export default from './FilterMonitor'; 2 | -------------------------------------------------------------------------------- /src/reducers.js: -------------------------------------------------------------------------------- 1 | function childMonitorState(props, state, action) { 2 | const child = props.children; 3 | return child.type.update(child.props, state, action); 4 | } 5 | 6 | export default function reducer(props, state = {}, action) { 7 | return { 8 | childMonitorState: childMonitorState(props, state.childMonitorState, action) 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /test/index.spec.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zalmoxisus/redux-devtools-filter-actions/93ba603b8d96f8384d976f26507129231421c10b/test/index.spec.js --------------------------------------------------------------------------------