├── .babelrc ├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .npmignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── __tests__ ├── .eslintrc.json ├── debug.spec.js ├── fixtures │ ├── DecoratorComponent.js │ ├── DumbComponent.js │ ├── HighOrderComponent.js │ ├── SmartComponent.js │ ├── TestComponent.js │ └── fakeObjects.js ├── index.spec.js ├── mocks │ └── debug.js └── util.spec.js ├── docs ├── ast │ └── source │ │ ├── debug.js.json │ │ ├── index.js.json │ │ └── util.js.json ├── badge.svg ├── coverage.json ├── css │ ├── prettify-tomorrow.css │ └── style.css ├── dump.json ├── file │ └── src │ │ ├── debug.js.html │ │ ├── index.js.html │ │ └── util.js.html ├── function │ └── index.html ├── identifiers.html ├── image │ ├── badge.svg │ ├── github.png │ └── search.png ├── index.html ├── package.json ├── script │ ├── inherited-summary.js │ ├── inner-link.js │ ├── manual.js │ ├── patch-for-local.js │ ├── prettify │ │ ├── Apache-License-2.0.txt │ │ └── prettify.js │ ├── pretty-print.js │ ├── search.js │ ├── search_index.js │ └── test-summary.js ├── source.html └── typedef │ └── index.html ├── esdoc.json ├── karma.conf.js ├── package.json ├── src ├── .eslintrc.json ├── debug.js ├── index.js └── util.js └── tests.webpack.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react", "es2015", "airbnb"], 3 | "plugins": [ 4 | "transform-decorators-legacy", 5 | "transform-object-rest-spread", 6 | "transform-class-properties", 7 | "add-module-exports" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = space 3 | indent_size = 2 4 | charset = utf-8 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | 8 | [*.md] 9 | trim_trailing_whitespace = false 10 | insert_final_newline = false 11 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "node": true 5 | }, 6 | "extends": "eslint-config-airbnb-base/legacy" 7 | } 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Use only Unix line feeds (LF) 2 | *.txt text eol=lf 3 | *.js text eol=lf 4 | *.json text eol=lf 5 | *.md text eol=lf 6 | *.yml text eol=lf 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | *.log 4 | coverage 5 | lib 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | __tests__ 3 | coverage 4 | docs 5 | esdoc.json 6 | karma.conf.js 7 | src 8 | tests.webpack.js 9 | CONTRIBUTING.md 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5.1" 4 | install: 5 | - npm install 6 | script: 7 | - npm run ci 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guide 2 | 3 | Thank for your interest in contributing with this project. 4 | 5 | This project is small and the rules are simple. 6 | 7 | ## Opening issues 8 | 9 | You can open issues to report bugs, suggest new features, discuss changes or just share your opinion about the project. 10 | 11 | ### Tips when reporting bugs 12 | 13 | Please take a look at three simple steps that help create good bug reports and enable a quick fix. 14 | 15 | #### 1) Conditions to reproduce 16 | 17 | When reporting bugs please state the current condition of your setup that you think might be related to the issue. 18 | 19 | Some examples: 20 | 21 | - Node and npm versions 22 | - React version 23 | - Usage of external libs or plugins (Immutable, debug, etc) and its versions 24 | 25 | #### 2) What is wrong? 26 | 27 | Report what isn't working properly. Explain it the most detailed way possible. 28 | 29 | Things that help: 30 | 31 | - Code snippets 32 | - Tell the steps that lead to bug reproduction 33 | - Screenshots 34 | 35 | #### 3) How can we fix it? (optional) 36 | 37 | This is optional but you can suggest a possible fix or propose a PR submission. 38 | 39 | Before submiting a PR read this. 40 | 41 | ## Working in the project 42 | 43 | You'll need to be familiar with CLI tools, [JS](https://www.javascript.com/), [React](https://facebook.github.io/react/), [Babel](https://babeljs.io/) and [npm](https://www.npmjs.com/) packaging. 44 | 45 | To build the project locally follow the 6 steps: 46 | 47 | 1. Fork and clone this repo to your local workspace. 48 | 2. Run `npm install` 49 | 3. Make your changes 50 | 4. Run `npm run build` 51 | 5. Commit 52 | 6. [Submit a PR](#pr) 53 | 54 | That's it, you don't need to install anything else manually. npm will take care of everything for you. 55 | 56 | ### Contributing with source code 57 | 58 | Changing source code is pretty straight forward. 59 | 60 | Look for the `src` folder, there's where all the source code is. 61 | 62 | Try to stick to the [airbnb styleguide](https://github.com/airbnb/javascript) when coding, [eslint](http://eslint.org/) is configured to check for that. 63 | 64 | If you need to check manually, run `npm run lint`. 65 | 66 | When adding new features please also add tests following the pattern located at the `__tests__` folder and change the inline documentation to properly reflect your changes. 67 | 68 | After any change we suggest you run `npm run build` to see if everything is OK. It will lint, test and output the final code to the `lib` folder. 69 | 70 | #### Tips to speed up development 71 | 72 | - Use an editor or IDE compatible with [eslint](http://eslint.org/) so you have realtime code linting. 73 | - Keep the tests running while you code, you can run `npm run watch-test` to do just that. 74 | 75 | ### Contributing with docs 76 | 77 | As you can see from the source code, the docs are inline and generated by a tool called `esdoc`. 78 | 79 | By running `npm run docs` you'll generate the HTML docs outputting to the `docs` folder. 80 | 81 | Please run the command to update docs before sending a PR. 82 | 83 | ### Contributing with tests 84 | 85 | Tests are located in the `__tests__` folder and follow the BDD pattern. 86 | 87 | When you are done run tests with `npm test`. 88 | 89 | We try to maintain 100% test coverage, but coverage does not guarantee test quality. Any improvement is welcome. 90 | 91 | ## Sending PRs 92 | 93 | Pull requests are cool, you are welcome to submit them. 94 | 95 | Please submit your PRs to master branch. Currently we see no reason to create feature branches in this small project. 96 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Matheus Kautzmann 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-update-helper 2 | 3 | **⚠️ DEPRECATED: This project is no longer useful. Please check alternatives like [React's Pure Component](https://reactjs.org/docs/react-api.html#reactpurecomponent) and [React's Dev Tools](https://github.com/facebook/react-devtools)** 4 | 5 | [![Build]](https://travis-ci.org/mkxml/react-update-helper) [![SemVer]](http://semver.org/) [![Coverage]](https://coveralls.io/github/mkxml/react-update-helper?branch=master) [![License]](LICENSE) 6 | 7 | A [React](https://facebook.github.io/react/) set of helpers to debug and accelerate your component updates. 8 | 9 | It works with [debug](https://github.com/visionmedia/debug) and [Immutable](https://facebook.github.io/immutable-js/). 10 | 11 | ## Goal 12 | 13 | This react kit is a set of two high order components ([HOCs](https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750#.g1hqmwlh4)) that are useful for react app development: 14 | 15 | 1. `withPureRender` is the first enhancer. It helps you prevent useless component updates (even when using deep Immutable.JS objects). 16 | 17 | 2. `withDebugInfo` is the second one. It allows you to check why a component updated in your browser console. 18 | 19 | The idea combines thoughts from [PureRenderMixin](https://facebook.github.io/react/docs/pure-render-mixin.html) and from a [blog post](https://medium.com/@tjholowaychuk/debugging-value-changes-in-react-s-shouldcomponentupdate-ae59b05c5371#.xig19l2nh) about React prop/state change debugging. 20 | 21 | ## Why and when to use these helpers? 22 | 23 | Here are a few common uses: 24 | 25 | - You might want to use `withPureRender` when 26 | - You want to use Immutable objects as your props or state values. 27 | - You use Redux with Immutable state objects 28 | 29 | - You might want to use `withDebugInfo` when: 30 | - You want to debug props and state changes. 31 | - Pairing the component update logging with react-perf-addon to help busting performance issues. 32 | 33 | Still don't know if you need this? Take a look at the [Usage](#usage) section. 34 | 35 | ## Install 36 | 37 | It currently needs three peerDependencies. 38 | 39 | - [React](https://facebook.github.io/react/) 40 | - [debug](https://github.com/visionmedia/debug) 41 | - [Immutable](https://facebook.github.io/immutable-js/) 42 | 43 | This module is currently available only on [npm](https://www.npmjs.com/). 44 | 45 | Install now: 46 | 47 | `npm install react-update-helper --save` 48 | 49 | You are done, check the [Usage](#usage) section to know how to use it. 50 | 51 | **Why those peerDependencies?** 52 | 53 | [React](https://facebook.github.io/react/) dependency is pretty obvious since this is a react plugin. 54 | 55 | [Immutable](https://facebook.github.io/immutable-js/) is an optional choice but you might already be using it so there is no reason to duplicate the versions since this module just need the [is()](https://facebook.github.io/immutable-js/docs/#/is) function of the `immutable` package. 56 | 57 | Even if you are not using Immutable on your own, most modern build systems like `webpack v2` or `rollup` will isolate the tiny bit of code this module need to operate. 58 | 59 | As for [debug](https://github.com/visionmedia/debug), it is optional and will only be [required](https://nodejs.org/api/modules.html) if you use `withDebugInfo`. 60 | 61 | ## Usage 62 | 63 | The package exposes one function and two component enhancers that you can use: 64 | 65 | - `shouldUpdate`, the core update function with Immutable support. You may use it directly in your `shouldComponentUpdate`. Or you can easily switch to the enhancer approach of `withPureRender`. 66 | - `withPureRender`, the easy plug-and-play enhancer HOC for any React component that will run `shouldUpdate` in every update attempt for you. 67 | - `withDebugInfo`, the debug function you may use in development to log out a nice component change feed in the browser console. 68 | 69 | #### withPureRender(Component) 70 | 71 | The easiest way to get all the goods of automatic `shouldUpdate` is using `withPureRender`. 72 | 73 | You can use it as a normal high order component as follows: 74 | 75 | ```javascript 76 | // Use react 77 | import React from 'react'; 78 | 79 | // Use withPureRender 80 | import { withPureRender } from 'react-update-helper'; 81 | 82 | // Create the component 83 | class Greet extends React.Component { 84 | render() { 85 | return
Hello {this.props.greet}!
; 86 | } 87 | } 88 | 89 | // Enhance the Greet with withPureRender and export it 90 | export default withPureRender(Greet); 91 | ``` 92 | 93 | Or you can use it as a ES7 decorator if you support and like that way: 94 | 95 | ```javascript 96 | // Use react 97 | import React from 'react'; 98 | 99 | // Use withPureRender 100 | import { withPureRender } from 'react-update-helper'; 101 | 102 | // Create the enhanced component 103 | @withPureRender 104 | class Greet extends React.Component { 105 | render() { 106 | return
Hello {this.props.greet}!
; 107 | } 108 | } 109 | 110 | // Export the already enhanced Greet 111 | export default Greet; 112 | ``` 113 | 114 | It works with [pure functional components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) too: 115 | 116 | ```javascript 117 | // Use react 118 | import React from 'react'; 119 | 120 | // Use withPureRender 121 | import { withPureRender } from 'react-update-helper'; 122 | 123 | // Create the component 124 | function Greet({ greet }) { 125 | return
Hello {greet}!
; 126 | } 127 | 128 | // Enhance the Greet with withPureRender and export it 129 | export default withPureRender(Greet); 130 | ``` 131 | 132 | #### shouldUpdate(componentContext, nextProps, nextState) 133 | 134 | You can use the `shouldUpdate` function directly if you need to, like if you have more stuff to check when updating your component to improve performance. 135 | 136 | Quick example of dening the greet prop value to change to falsy values while also maintaining the same value check with `shouldUpdate`: 137 | 138 | ```javascript 139 | // Use react 140 | import React from 'react'; 141 | 142 | // Use shouldUpdate 143 | import { shouldUpdate } from 'react-update-helper'; 144 | 145 | // Create the component 146 | class Greet extends React.Component { 147 | 148 | shouldComponentUpdate(nextProps, nextState) { 149 | // Ignore change to falsy value 150 | if (!!nextProps.greet) return false; 151 | // Will only return true when stuff changes, even with Immutable objects 152 | return shouldUpdate(this, nextProps, nextState); 153 | } 154 | 155 | render() { 156 | return
Hello {this.props.greet}!
; 157 | } 158 | } 159 | 160 | // Just export Greet 161 | export default Greet; 162 | ``` 163 | 164 | ### Debugging updates 165 | 166 | Use `withDebugInfo` for that matter: 167 | 168 | ```javascript 169 | // Use react 170 | import React from 'react'; 171 | 172 | // Use withPureRender 173 | import { withDebugInfo } from 'react-update-helper'; 174 | 175 | // Create the component 176 | class Greet extends React.Component { 177 | render() { 178 | return
Hello {this.props.greet}!
; 179 | } 180 | } 181 | 182 | // Enhance the Greet with withDebugInfo and export it 183 | export default withDebugInfo(Greet); 184 | ``` 185 | 186 | We use [debug](https://github.com/visionmedia/debug) internally to log component updates when debugging is enabled. 187 | 188 | You can test this by enabling the namespace `ReactUpdateHelper` in `debug`. 189 | 190 | Or you can just enable all namespaces with `*`. 191 | 192 | In the browser you can do that as follows: 193 | 194 | ```javascript 195 | // Just enabling react-update-helper messages 196 | window.localStorage.debug = 'ReactUpdateHelper'; 197 | 198 | // Enabling all debug-powered logs 199 | window.localStorage.debug = '*'; 200 | ``` 201 | 202 | See more about debug in their [repository page](https://github.com/visionmedia/debug). 203 | 204 | #### Quick Tip: When debugging [Immutable](https://facebook.github.io/immutable-js/) objects use a custom formatter in the console 205 | 206 | This [custom formatter](https://github.com/andrewdavey/immutable-devtools) for Chrome Dev Tools makes `Immutable` object debugging a breeze. It works perfectly with `react-update-helper`! 207 | 208 | ### No debug in production 209 | 210 | As with React warnings, you should disable logs when running in a production environment. 211 | 212 | Just make sure you are conditionally using `withDebugInfo` with an environment variable of sorts (like setting `NODE_ENV` to `production`) and performing dead code elimination. 213 | 214 | The concerns are the same as if you were building React for production usage in the first place. 215 | 216 | If you use [Webpack](https://webpack.github.io/), [here](http://moduscreate.com/optimizing-react-es6-webpack-production-build/) is a nice guide. 217 | 218 | #### Whole documentation 219 | 220 | See the whole docs in the `docs` folder of this repo or [directly online](https://doc.esdoc.org/github.com/mkxml/react-update-helper/). 221 | 222 | ## Compatibility 223 | 224 | Compatibility with [React](https://facebook.github.io/react/), [Immutable](https://facebook.github.io/immutable-js/) and [debug](https://github.com/visionmedia/debug) have been tested and should be maintained. 225 | 226 | Though not tested, it should work with [react-native](https://facebook.github.io/react-native/) since it does not mess with DOM and browser specific APIs. 227 | 228 | It can theorically work with [preact](https://github.com/developit/preact) when using [preact-compat](https://github.com/developit/preact-compat) since it mimics React's API and lifecycle. 229 | 230 | ## Contributing 231 | 232 | This project is welcoming contributions of any kind! 233 | 234 | Please, before filing issues or sending PRs, read the [CONTRIBUTING](CONTRIBUTING.md) guide. 235 | 236 | ## License 237 | 238 | [MIT](LICENSE) 239 | 240 | [Build]: https://img.shields.io/travis/mkxml/react-update-helper.svg 241 | [SemVer]: https://img.shields.io/:semver-%E2%9C%93-brightgreen.svg 242 | [Coverage]: https://img.shields.io/coveralls/mkxml/react-update-helper/master.svg 243 | [Docs]: https://doc.esdoc.org/github.com/mkxml/react-update-helper/badge.svg 244 | [License]: https://img.shields.io/npm/l/react-update-helper.svg 245 | -------------------------------------------------------------------------------- /__tests__/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "node": true 6 | }, 7 | "globals": { 8 | "describe": true, 9 | "it": true, 10 | "expect": true, 11 | "sinon": true, 12 | "before": true, 13 | "after": true, 14 | "beforeEach": true, 15 | "afterEach": true 16 | }, 17 | "extends": "airbnb", 18 | "plugins": [ 19 | "react" 20 | ], 21 | "rules": { 22 | "new-cap": [0], 23 | "import/no-extraneous-dependencies": "off", 24 | "import/prefer-default-export": "off", 25 | "react/jsx-filename-extension": "off", 26 | "react/require-default-props": "off" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /__tests__/debug.spec.js: -------------------------------------------------------------------------------- 1 | import { reportChanges } from '../src/debug'; 2 | import { fakeComponent, newProps, newState } from './fixtures/fakeObjects'; 3 | 4 | // cancel show console output 5 | window.console.log = x => x; 6 | 7 | describe('debug', () => { 8 | it('should return array with changes', () => { 9 | const changes = reportChanges(fakeComponent, newProps, newState); 10 | expect(changes.length).to.eql(3); 11 | }); 12 | it('should detect the component name automatically', () => { 13 | const changes = reportChanges(fakeComponent, newProps, newState); 14 | expect(changes[0].component).to.eql('Test'); 15 | }); 16 | it('should try to log the changes in the console', () => { 17 | // mock a log function, not using debug here 18 | const log = sinon.spy(); 19 | reportChanges(fakeComponent, newProps, newState, log); 20 | expect(log.called).to.eql(true); 21 | }); 22 | it('should detect changes in props', () => { 23 | const changes = reportChanges(fakeComponent, newProps, newState); 24 | expect(changes[0].type).to.eql('props'); 25 | }); 26 | it('should log addition of prop', () => { 27 | const log = sinon.spy(); 28 | const newFake = { ...fakeComponent }; 29 | newFake.props = { t0: 0 }; 30 | const props = { t0: 0, t1: 1 }; 31 | reportChanges(newFake, props, newFake.state, log); 32 | const fnCall = log.getCall(0); 33 | const correctMessage = [ 34 | '%s: changed prop %s from %o to %o', 35 | 'Test', 36 | 't1', 37 | undefined, 38 | 1, 39 | ]; 40 | const messageLogged = fnCall.args; 41 | expect(messageLogged).to.eql(correctMessage); 42 | }); 43 | it('should log removal of prop', () => { 44 | const log = sinon.spy(); 45 | const newFake = { ...fakeComponent }; 46 | newFake.props = { t0: 0, t1: 0 }; 47 | const props = { t0: 0 }; 48 | reportChanges(newFake, props, newFake.state, log); 49 | const fnCall = log.getCall(0); 50 | const correctMessage = [ 51 | '%s: changed prop %s from %o to %o', 52 | 'Test', 53 | 't1', 54 | 0, 55 | undefined, 56 | ]; 57 | const messageLogged = fnCall.args; 58 | expect(messageLogged).to.eql(correctMessage); 59 | }); 60 | it('should handle null props', () => { 61 | const log = sinon.spy(); 62 | const newFake = { ...fakeComponent }; 63 | newFake.props = null; 64 | newFake.state = { t0: 1 }; 65 | reportChanges(newFake, null, newFake.state, log); 66 | expect(log.called).to.eql(false); 67 | }); 68 | it('should detect changes in state', () => { 69 | const changes = reportChanges(fakeComponent, newProps, newState); 70 | expect(changes[2].type).to.eql('state'); 71 | }); 72 | it('should log addition of state key', () => { 73 | const log = sinon.spy(); 74 | const newFake = { ...fakeComponent }; 75 | newFake.state = { t0: 0 }; 76 | const state = { t0: 0, t1: 1 }; 77 | reportChanges(newFake, newFake.props, state, log); 78 | const fnCall = log.getCall(0); 79 | const correctMessage = [ 80 | '%s: changed state key %s from %o to %o', 81 | 'Test', 82 | 't1', 83 | undefined, 84 | 1, 85 | ]; 86 | const messageLogged = fnCall.args; 87 | expect(messageLogged).to.eql(correctMessage); 88 | }); 89 | it('should log removal of state key', () => { 90 | const log = sinon.spy(); 91 | const newFake = { ...fakeComponent }; 92 | newFake.state = { t0: 0, t1: 1 }; 93 | const state = { t0: 0 }; 94 | reportChanges(newFake, newFake.props, state, log); 95 | const fnCall = log.getCall(0); 96 | const correctMessage = [ 97 | '%s: changed state key %s from %o to %o', 98 | 'Test', 99 | 't1', 100 | 1, 101 | undefined, 102 | ]; 103 | const messageLogged = fnCall.args; 104 | expect(messageLogged).to.eql(correctMessage); 105 | }); 106 | it('should handle null state', () => { 107 | const log = sinon.spy(); 108 | const newFake = { ...fakeComponent }; 109 | newFake.props = { t0: 0 }; 110 | newFake.state = null; 111 | reportChanges(newFake, newFake.props, null, log); 112 | expect(log.called).to.eql(false); 113 | }); 114 | it('should format the log of props correctly', () => { 115 | const log = sinon.spy(); 116 | reportChanges(fakeComponent, newProps, newState, log); 117 | const fnCall = log.getCall(0); 118 | const correctMessage = [ 119 | '%s: changed prop %s from %o to %o', 120 | 'Test', 121 | 't1', 122 | 0, 123 | 1, 124 | ]; 125 | const messageLogged = fnCall.args; 126 | expect(messageLogged).to.eql(correctMessage); 127 | }); 128 | it('should format the log of state correctly', () => { 129 | const log = sinon.spy(); 130 | reportChanges(fakeComponent, newProps, newState, log); 131 | const fnCall = log.getCall(2); 132 | const correctMessage = [ 133 | '%s: changed state key %s from %o to %o', 134 | 'Test', 135 | 't1', 136 | undefined, 137 | 0, 138 | ]; 139 | const messageLogged = fnCall.args; 140 | expect(messageLogged).to.eql(correctMessage); 141 | }); 142 | }); 143 | -------------------------------------------------------------------------------- /__tests__/fixtures/DecoratorComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { withPureRender } from '../../src/index'; 3 | 4 | @withPureRender 5 | class DecoratorComponent extends React.Component { 6 | constructor() { 7 | super(); 8 | this.updateCount = 0; 9 | } 10 | 11 | shouldComponentUpdate() { 12 | this.updateCount += 1; 13 | return true; 14 | } 15 | 16 | render() { 17 | return
{this.updateCount}
; 18 | } 19 | } 20 | 21 | DecoratorComponent.propTypes = { 22 | test: React.PropTypes.string, 23 | }; 24 | 25 | export default DecoratorComponent; 26 | -------------------------------------------------------------------------------- /__tests__/fixtures/DumbComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | function DumbComponent({ prop1, prop2 }) { 4 | return
{prop2}
; 5 | } 6 | 7 | DumbComponent.displayName = 'DumbComponent'; 8 | 9 | DumbComponent.propTypes = { 10 | prop1: React.PropTypes.string, 11 | prop2: React.PropTypes.string, 12 | }; 13 | 14 | export default DumbComponent; 15 | -------------------------------------------------------------------------------- /__tests__/fixtures/HighOrderComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { withDebugInfo } from '../../src/index'; 3 | 4 | class HighOrderComponent extends React.Component { 5 | constructor() { 6 | super(); 7 | this.updateCount = 0; 8 | } 9 | 10 | shouldComponentUpdate() { 11 | this.updateCount += 1; 12 | return true; 13 | } 14 | 15 | render() { 16 | return
{this.updateCount}
; 17 | } 18 | } 19 | 20 | HighOrderComponent.propTypes = { 21 | test: React.PropTypes.string, 22 | }; 23 | 24 | export default withDebugInfo(HighOrderComponent); 25 | -------------------------------------------------------------------------------- /__tests__/fixtures/SmartComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import DumbComponent from './DumbComponent'; 3 | 4 | class SmartComponent extends React.Component { 5 | componentDidMount() { 6 | window.console.log('Smart component mounted!'); 7 | } 8 | 9 | render() { 10 | return ; 11 | } 12 | } 13 | 14 | SmartComponent.propTypes = { 15 | prop1: React.PropTypes.string, 16 | prop2: React.PropTypes.string, 17 | }; 18 | 19 | export default SmartComponent; 20 | -------------------------------------------------------------------------------- /__tests__/fixtures/TestComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shouldUpdate } from '../../src/index'; 3 | 4 | class TestComponent extends React.Component { 5 | constructor() { 6 | super(); 7 | this.updateCount = 0; 8 | } 9 | 10 | shouldComponentUpdate(newProps, newState) { 11 | const willUpdate = shouldUpdate(this, newProps, newState); 12 | if (willUpdate) this.updateCount += 1; 13 | return willUpdate; 14 | } 15 | 16 | render() { 17 | return
{this.updateCount}
; 18 | } 19 | } 20 | 21 | TestComponent.propTypes = { 22 | test: React.PropTypes.node, 23 | }; 24 | 25 | export default TestComponent; 26 | -------------------------------------------------------------------------------- /__tests__/fixtures/fakeObjects.js: -------------------------------------------------------------------------------- 1 | import Immutable from 'immutable'; 2 | 3 | export const fakeComponent = { 4 | constructor: { 5 | displayName: 'Test', 6 | propTypes: { 7 | t1: true, 8 | t2: true, 9 | t3: true, 10 | t4: true, 11 | }, 12 | }, 13 | props: { 14 | t1: 0, 15 | t2: 0, 16 | t3: 0, 17 | t4: Immutable.Map({ foo: 'bar' }), 18 | }, 19 | state: null, 20 | }; 21 | 22 | export const newProps = { 23 | t1: 1, 24 | t2: 0, 25 | t3: -1, 26 | t4: Immutable.Map({ foo: 'bar' }), 27 | }; 28 | 29 | export const newState = { 30 | t1: 0, 31 | }; 32 | -------------------------------------------------------------------------------- /__tests__/index.spec.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Immutable from 'immutable'; 3 | import { shallow } from 'enzyme'; 4 | import TestComponent from './fixtures/TestComponent'; 5 | import DecoratorComponent from './fixtures/DecoratorComponent'; 6 | import HighOrderComponent from './fixtures/HighOrderComponent'; 7 | import { shouldUpdate } from '../src/index'; 8 | import { fakeComponent, newProps, newState } from './fixtures/fakeObjects'; 9 | 10 | // cancel show console output 11 | window.console.log = x => x; 12 | 13 | describe('main functionality', () => { 14 | describe('shouldUpdate', () => { 15 | it('should return true when props change', () => { 16 | const result = shouldUpdate(fakeComponent, newProps, null); 17 | expect(result).to.eql(true); 18 | }); 19 | it('should return false when props stay the same', () => { 20 | const newFake = { ...fakeComponent }; 21 | newFake.state = null; 22 | newFake.props = { 23 | t1: 1, 24 | t2: 0, 25 | t3: -1, 26 | t4: Immutable.Map({ foo: 'bar' }), 27 | }; 28 | const result = shouldUpdate(newFake, newProps, null); 29 | expect(result).to.eql(false); 30 | }); 31 | it('should return true when a prop is added', () => { 32 | const props = { ...fakeComponent.props, t5: 1 }; 33 | const result = shouldUpdate(fakeComponent, props, null); 34 | expect(result).to.eql(true); 35 | }); 36 | it('should return true when a prop is removed', () => { 37 | const props = { 38 | t1: 0, 39 | t2: 0, 40 | t3: 0, 41 | }; 42 | const result = shouldUpdate(fakeComponent, props, null); 43 | expect(result).to.eql(true); 44 | }); 45 | it('should return true when a prop changed from null', () => { 46 | const newFake = { ...fakeComponent }; 47 | newFake.props = null; 48 | newFake.state = { t1: 0 }; 49 | const props = { t0: 0 }; 50 | const result = shouldUpdate(newFake, props, newState); 51 | expect(result).to.eql(true); 52 | }); 53 | it('should return true when a prop is removed and other added at the same time', () => { 54 | const newFake = { ...fakeComponent }; 55 | newFake.props = { t0: 0, t1: 0 }; 56 | const props = { t0: 0, t2: 0 }; 57 | const result = shouldUpdate(newFake, props, null); 58 | expect(result).to.eql(true); 59 | }); 60 | it('should return true when state change', () => { 61 | const newFake = { ...fakeComponent }; 62 | newFake.state = { t1: 1 }; 63 | newFake.props = null; 64 | const result = shouldUpdate(newFake, null, newState); 65 | expect(result).to.eql(true); 66 | }); 67 | it('should return false when state does not change', () => { 68 | const newFake = { ...fakeComponent }; 69 | newFake.state = { t1: 0 }; 70 | newFake.props = null; 71 | const result = shouldUpdate(newFake, null, newState); 72 | expect(result).to.eql(false); 73 | }); 74 | it('should return true when a new state key is added', () => { 75 | const newFake = { ...fakeComponent }; 76 | newFake.state = { t1: 0 }; 77 | newFake.props = null; 78 | const state = { t1: 0, t2: 0 }; 79 | const result = shouldUpdate(newFake, null, state); 80 | expect(result).to.eql(true); 81 | }); 82 | it('should return true when a state key is removed', () => { 83 | const newFake = { ...fakeComponent }; 84 | newFake.state = { t1: 0 }; 85 | newFake.props = null; 86 | const state = {}; 87 | const result = shouldUpdate(newFake, null, state); 88 | expect(result).to.eql(true); 89 | }); 90 | it('should return true when state change from null', () => { 91 | const newFake = { ...fakeComponent }; 92 | newFake.props = null; 93 | const result = shouldUpdate(newFake, null, newState); 94 | expect(result).to.eql(true); 95 | }); 96 | it('should return true when a state key is removed and other added at the same time', () => { 97 | const newFake = { ...fakeComponent }; 98 | newFake.state = { t0: 0, t1: 0 }; 99 | newFake.props = null; 100 | const state = { t0: 0, t2: 0 }; 101 | const result = shouldUpdate(newFake, null, state); 102 | expect(result).to.eql(true); 103 | }); 104 | it('should return false when both props and state stay the same', () => { 105 | const props = { ...fakeComponent.props }; // deep copy props object 106 | const state = null; 107 | const result = shouldUpdate(fakeComponent, props, state); 108 | expect(result).to.eql(false); 109 | }); 110 | it('should return false when both props and state are null', () => { 111 | const newFake = { ...fakeComponent }; 112 | newFake.state = null; 113 | newFake.props = null; 114 | const props = null; 115 | const state = null; 116 | const result = shouldUpdate(newFake, props, state); 117 | expect(result).to.eql(false); 118 | }); 119 | it('should ignore the order of the properties', () => { 120 | const props = { t2: 0, t1: 0, t4: Immutable.Map({ foo: 'bar' }), t3: 0 }; 121 | const state = null; 122 | const result = shouldUpdate(fakeComponent, props, state); 123 | expect(result).to.eql(false); 124 | }); 125 | it('should ignore the order of the state keys', () => { 126 | const newFake = { ...fakeComponent }; 127 | newFake.props = null; 128 | newFake.state = { t1: 0, t2: 0 }; 129 | const state = { t2: 0, t1: 0 }; 130 | const result = shouldUpdate(newFake, null, state); 131 | expect(result).to.eql(false); 132 | }); 133 | it('should detect change in nested Immutable objects', () => { 134 | const props = { ...fakeComponent.props, t4: Immutable.Map({ foo: 'baz' }) }; // change t4 135 | const state = null; 136 | const result = shouldUpdate(fakeComponent, props, state); 137 | expect(result).to.eql(true); 138 | }); 139 | it('should check for value equality on Immutable objects', () => { 140 | const props = { ...fakeComponent.props, t4: Immutable.Map({ foo: 'bar' }) }; // same t4 141 | const state = null; 142 | const result = shouldUpdate(fakeComponent, props, state); 143 | expect(result).to.eql(false); 144 | }); 145 | }); 146 | }); 147 | describe('withPureRender', () => { 148 | it('should work as a component decorator', () => { 149 | const renderedComponent = shallow(); 150 | renderedComponent.setProps({ test: 'foo' }); 151 | const updateCount = renderedComponent.html(); 152 | expect(updateCount).to.eql('
0
'); 153 | }); 154 | it('should work as a high order component', () => { 155 | const renderedComponent = shallow(); 156 | renderedComponent.setProps({ test: 'foo' }); 157 | const updateCount = renderedComponent.html(); 158 | expect(updateCount).to.eql('
0
'); 159 | }); 160 | }); 161 | describe('integration', () => { 162 | describe('react', () => { 163 | it('should work with react lifecycle', () => { 164 | const renderedComponent = shallow(); 165 | // changing prop to force update 166 | renderedComponent.setProps({ test: 'bar' }); 167 | const updateCount = renderedComponent.text(); 168 | expect(updateCount).to.eql('1'); 169 | }); 170 | it('should not perform useless re-renders in practice', () => { 171 | const renderedComponent = shallow(); 172 | // same value, new reference check 173 | renderedComponent.setProps({ test: 'foo' }); 174 | const updateCount = renderedComponent.text(); 175 | expect(updateCount).to.eql('0'); 176 | }); 177 | }); 178 | describe('react + Immutable', () => { 179 | it('should work with immutable prop change', () => { 180 | const renderedComponent = shallow(); 181 | // changing prop to force update 182 | renderedComponent.setProps({ test: Immutable.Map({ test: 'bar' }) }); 183 | const updateCount = renderedComponent.text(); 184 | expect(updateCount).to.eql('1'); 185 | }); 186 | it('should not re-render when immutable value does not change', () => { 187 | const renderedComponent = shallow(); 188 | renderedComponent.setProps({ test: Immutable.Map({ test: 'foo' }) }); 189 | const updateCount = renderedComponent.text(); 190 | expect(updateCount).to.eql('0'); 191 | }); 192 | }); 193 | describe('react + debug', () => { 194 | it('should log changes when using withDebugInfo', () => { 195 | // spy on console log 196 | sinon.spy(window.console, 'log'); 197 | const renderedComponent = shallow(); 198 | // change, causing update 199 | renderedComponent.setProps({ test: 'bar' }); 200 | const called = window.console.log.called; 201 | window.console.log.restore(); 202 | expect(called).to.eql(true); 203 | }); 204 | }); 205 | }); 206 | -------------------------------------------------------------------------------- /__tests__/mocks/debug.js: -------------------------------------------------------------------------------- 1 | module.exports = function debug() { 2 | return function log(string) { 3 | window.console.log(string); 4 | }; 5 | }; 6 | -------------------------------------------------------------------------------- /__tests__/util.spec.js: -------------------------------------------------------------------------------- 1 | import { getComponentName } from '../src/util'; 2 | import SmartComponent from './fixtures/SmartComponent'; 3 | import DumbComponent from './fixtures/DumbComponent'; 4 | 5 | describe('util', () => { 6 | it('should get the name of the SmartComponent', () => { 7 | expect(getComponentName(new SmartComponent())).to.eql('SmartComponent'); 8 | }); 9 | it('should get the name of the DumbComponent', () => { 10 | expect(getComponentName(DumbComponent)).to.eql('DumbComponent'); 11 | }); 12 | it('should get the name from property displayName', () => { 13 | const fake = function Test() {}; 14 | fake.displayName = 'Test'; 15 | expect(getComponentName(fake)).to.eql('Test'); 16 | }); 17 | it('should get the name from property name', () => { 18 | const fake = function Test() {}; 19 | expect(getComponentName(fake)).to.eql('Test'); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/ast/source/util.js.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 351, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 11, 12 | "column": 0 13 | } 14 | }, 15 | "sourceType": "module", 16 | "body": [ 17 | { 18 | "type": "ExportNamedDeclaration", 19 | "start": 216, 20 | "end": 350, 21 | "loc": { 22 | "start": { 23 | "line": 8, 24 | "column": 0 25 | }, 26 | "end": { 27 | "line": 10, 28 | "column": 1 29 | } 30 | }, 31 | "declaration": { 32 | "type": "FunctionDeclaration", 33 | "start": 223, 34 | "end": 350, 35 | "loc": { 36 | "start": { 37 | "line": 8, 38 | "column": 7 39 | }, 40 | "end": { 41 | "line": 10, 42 | "column": 1 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 232, 48 | "end": 248, 49 | "loc": { 50 | "start": { 51 | "line": 8, 52 | "column": 16 53 | }, 54 | "end": { 55 | "line": 8, 56 | "column": 32 57 | } 58 | }, 59 | "name": "getComponentName", 60 | "leadingComments": null 61 | }, 62 | "generator": false, 63 | "expression": false, 64 | "async": false, 65 | "params": [ 66 | { 67 | "type": "Identifier", 68 | "start": 249, 69 | "end": 252, 70 | "loc": { 71 | "start": { 72 | "line": 8, 73 | "column": 33 74 | }, 75 | "end": { 76 | "line": 8, 77 | "column": 36 78 | } 79 | }, 80 | "name": "ctx" 81 | } 82 | ], 83 | "body": { 84 | "type": "BlockStatement", 85 | "start": 254, 86 | "end": 350, 87 | "loc": { 88 | "start": { 89 | "line": 8, 90 | "column": 38 91 | }, 92 | "end": { 93 | "line": 10, 94 | "column": 1 95 | } 96 | }, 97 | "body": [ 98 | { 99 | "type": "ReturnStatement", 100 | "start": 258, 101 | "end": 348, 102 | "loc": { 103 | "start": { 104 | "line": 9, 105 | "column": 2 106 | }, 107 | "end": { 108 | "line": 9, 109 | "column": 92 110 | } 111 | }, 112 | "argument": { 113 | "type": "LogicalExpression", 114 | "start": 265, 115 | "end": 347, 116 | "loc": { 117 | "start": { 118 | "line": 9, 119 | "column": 9 120 | }, 121 | "end": { 122 | "line": 9, 123 | "column": 91 124 | } 125 | }, 126 | "left": { 127 | "type": "LogicalExpression", 128 | "start": 265, 129 | "end": 323, 130 | "loc": { 131 | "start": { 132 | "line": 9, 133 | "column": 9 134 | }, 135 | "end": { 136 | "line": 9, 137 | "column": 67 138 | } 139 | }, 140 | "left": { 141 | "type": "LogicalExpression", 142 | "start": 265, 143 | "end": 311, 144 | "loc": { 145 | "start": { 146 | "line": 9, 147 | "column": 9 148 | }, 149 | "end": { 150 | "line": 9, 151 | "column": 55 152 | } 153 | }, 154 | "left": { 155 | "type": "MemberExpression", 156 | "start": 265, 157 | "end": 292, 158 | "loc": { 159 | "start": { 160 | "line": 9, 161 | "column": 9 162 | }, 163 | "end": { 164 | "line": 9, 165 | "column": 36 166 | } 167 | }, 168 | "object": { 169 | "type": "MemberExpression", 170 | "start": 265, 171 | "end": 280, 172 | "loc": { 173 | "start": { 174 | "line": 9, 175 | "column": 9 176 | }, 177 | "end": { 178 | "line": 9, 179 | "column": 24 180 | } 181 | }, 182 | "object": { 183 | "type": "Identifier", 184 | "start": 265, 185 | "end": 268, 186 | "loc": { 187 | "start": { 188 | "line": 9, 189 | "column": 9 190 | }, 191 | "end": { 192 | "line": 9, 193 | "column": 12 194 | } 195 | }, 196 | "name": "ctx" 197 | }, 198 | "property": { 199 | "type": "Identifier", 200 | "start": 269, 201 | "end": 280, 202 | "loc": { 203 | "start": { 204 | "line": 9, 205 | "column": 13 206 | }, 207 | "end": { 208 | "line": 9, 209 | "column": 24 210 | } 211 | }, 212 | "name": "constructor" 213 | }, 214 | "computed": false 215 | }, 216 | "property": { 217 | "type": "Identifier", 218 | "start": 281, 219 | "end": 292, 220 | "loc": { 221 | "start": { 222 | "line": 9, 223 | "column": 25 224 | }, 225 | "end": { 226 | "line": 9, 227 | "column": 36 228 | } 229 | }, 230 | "name": "displayName" 231 | }, 232 | "computed": false 233 | }, 234 | "operator": "||", 235 | "right": { 236 | "type": "MemberExpression", 237 | "start": 296, 238 | "end": 311, 239 | "loc": { 240 | "start": { 241 | "line": 9, 242 | "column": 40 243 | }, 244 | "end": { 245 | "line": 9, 246 | "column": 55 247 | } 248 | }, 249 | "object": { 250 | "type": "Identifier", 251 | "start": 296, 252 | "end": 299, 253 | "loc": { 254 | "start": { 255 | "line": 9, 256 | "column": 40 257 | }, 258 | "end": { 259 | "line": 9, 260 | "column": 43 261 | } 262 | }, 263 | "name": "ctx" 264 | }, 265 | "property": { 266 | "type": "Identifier", 267 | "start": 300, 268 | "end": 311, 269 | "loc": { 270 | "start": { 271 | "line": 9, 272 | "column": 44 273 | }, 274 | "end": { 275 | "line": 9, 276 | "column": 55 277 | } 278 | }, 279 | "name": "displayName" 280 | }, 281 | "computed": false 282 | } 283 | }, 284 | "operator": "||", 285 | "right": { 286 | "type": "MemberExpression", 287 | "start": 315, 288 | "end": 323, 289 | "loc": { 290 | "start": { 291 | "line": 9, 292 | "column": 59 293 | }, 294 | "end": { 295 | "line": 9, 296 | "column": 67 297 | } 298 | }, 299 | "object": { 300 | "type": "Identifier", 301 | "start": 315, 302 | "end": 318, 303 | "loc": { 304 | "start": { 305 | "line": 9, 306 | "column": 59 307 | }, 308 | "end": { 309 | "line": 9, 310 | "column": 62 311 | } 312 | }, 313 | "name": "ctx" 314 | }, 315 | "property": { 316 | "type": "Identifier", 317 | "start": 319, 318 | "end": 323, 319 | "loc": { 320 | "start": { 321 | "line": 9, 322 | "column": 63 323 | }, 324 | "end": { 325 | "line": 9, 326 | "column": 67 327 | } 328 | }, 329 | "name": "name" 330 | }, 331 | "computed": false 332 | } 333 | }, 334 | "operator": "||", 335 | "right": { 336 | "type": "MemberExpression", 337 | "start": 327, 338 | "end": 347, 339 | "loc": { 340 | "start": { 341 | "line": 9, 342 | "column": 71 343 | }, 344 | "end": { 345 | "line": 9, 346 | "column": 91 347 | } 348 | }, 349 | "object": { 350 | "type": "MemberExpression", 351 | "start": 327, 352 | "end": 342, 353 | "loc": { 354 | "start": { 355 | "line": 9, 356 | "column": 71 357 | }, 358 | "end": { 359 | "line": 9, 360 | "column": 86 361 | } 362 | }, 363 | "object": { 364 | "type": "Identifier", 365 | "start": 327, 366 | "end": 330, 367 | "loc": { 368 | "start": { 369 | "line": 9, 370 | "column": 71 371 | }, 372 | "end": { 373 | "line": 9, 374 | "column": 74 375 | } 376 | }, 377 | "name": "ctx" 378 | }, 379 | "property": { 380 | "type": "Identifier", 381 | "start": 331, 382 | "end": 342, 383 | "loc": { 384 | "start": { 385 | "line": 9, 386 | "column": 75 387 | }, 388 | "end": { 389 | "line": 9, 390 | "column": 86 391 | } 392 | }, 393 | "name": "constructor" 394 | }, 395 | "computed": false 396 | }, 397 | "property": { 398 | "type": "Identifier", 399 | "start": 343, 400 | "end": 347, 401 | "loc": { 402 | "start": { 403 | "line": 9, 404 | "column": 87 405 | }, 406 | "end": { 407 | "line": 9, 408 | "column": 91 409 | } 410 | }, 411 | "name": "name" 412 | }, 413 | "computed": false 414 | } 415 | } 416 | } 417 | ] 418 | }, 419 | "leadingComments": [ 420 | { 421 | "type": "Block", 422 | "value": "*\n * Get the name of the given React component\n * @protected\n * @param {object} ctx - the component context, containing the name, props and state values\n * @return {string} - the component name\n * @since 1.0.0\n ", 423 | "start": 0, 424 | "end": 215, 425 | "loc": { 426 | "start": { 427 | "line": 1, 428 | "column": 0 429 | }, 430 | "end": { 431 | "line": 7, 432 | "column": 3 433 | } 434 | }, 435 | "range": [ 436 | 0, 437 | 215 438 | ] 439 | } 440 | ], 441 | "trailingComments": [] 442 | }, 443 | "specifiers": [], 444 | "source": null, 445 | "leadingComments": [ 446 | { 447 | "type": "Block", 448 | "value": "*\n * Get the name of the given React component\n * @protected\n * @param {object} ctx - the component context, containing the name, props and state values\n * @return {string} - the component name\n * @since 1.0.0\n ", 449 | "start": 0, 450 | "end": 215, 451 | "loc": { 452 | "start": { 453 | "line": 1, 454 | "column": 0 455 | }, 456 | "end": { 457 | "line": 7, 458 | "column": 3 459 | } 460 | }, 461 | "range": [ 462 | 0, 463 | 215 464 | ] 465 | } 466 | ] 467 | } 468 | ] 469 | } -------------------------------------------------------------------------------- /docs/badge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | document 13 | document 14 | 100% 15 | 100% 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/coverage.json: -------------------------------------------------------------------------------- 1 | { 2 | "coverage": "100%", 3 | "expectCount": 5, 4 | "actualCount": 5, 5 | "files": { 6 | "src/util.js": { 7 | "expectCount": 1, 8 | "actualCount": 1, 9 | "undocumentLines": [] 10 | }, 11 | "src/debug.js": { 12 | "expectCount": 1, 13 | "actualCount": 1, 14 | "undocumentLines": [] 15 | }, 16 | "src/index.js": { 17 | "expectCount": 3, 18 | "actualCount": 3, 19 | "undocumentLines": [] 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /docs/css/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /docs/css/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Roboto:400,300,700); 2 | 3 | * { 4 | margin: 0; 5 | padding: 0; 6 | text-decoration: none; 7 | } 8 | 9 | html 10 | { 11 | font-family: 'Roboto', sans-serif; 12 | overflow: auto; 13 | font-size: 14px; 14 | /*color: #4d4e53;*/ 15 | color: rgba(0, 0, 0, .68); 16 | background-color: #fff; 17 | } 18 | 19 | a { 20 | /*color: #0095dd;*/ 21 | /*color:rgb(37, 138, 175);*/ 22 | color: #039BE5; 23 | } 24 | 25 | code a:hover { 26 | text-decoration: underline; 27 | } 28 | 29 | ul, ol { 30 | padding-left: 20px; 31 | } 32 | 33 | ul li { 34 | list-style: disc; 35 | margin: 4px 0; 36 | } 37 | 38 | ol li { 39 | margin: 4px 0; 40 | } 41 | 42 | h1 { 43 | margin-bottom: 10px; 44 | font-size: 34px; 45 | font-weight: 300; 46 | border-bottom: solid 1px #ddd; 47 | } 48 | 49 | h2 { 50 | margin-top: 24px; 51 | margin-bottom: 10px; 52 | font-size: 20px; 53 | border-bottom: solid 1px #ddd; 54 | font-weight: 300; 55 | } 56 | 57 | h3 { 58 | position: relative; 59 | font-size: 16px; 60 | margin-bottom: 12px; 61 | background-color: #E2E2E2; 62 | padding: 4px; 63 | font-weight: 300; 64 | } 65 | 66 | del { 67 | text-decoration: line-through; 68 | } 69 | 70 | p { 71 | margin-bottom: 15px; 72 | line-height: 1.5; 73 | } 74 | 75 | p > code { 76 | background-color: #f5f5f5; 77 | border-radius: 3px; 78 | } 79 | 80 | pre > code { 81 | display: block; 82 | } 83 | 84 | pre.prettyprint, pre > code { 85 | padding: 4px; 86 | margin: 1em 0; 87 | background-color: #f5f5f5; 88 | border-radius: 3px; 89 | } 90 | 91 | pre.prettyprint > code { 92 | margin: 0; 93 | } 94 | 95 | p > code, 96 | li > code { 97 | padding: 0 4px; 98 | border-radius: 3px; 99 | } 100 | 101 | .import-path pre.prettyprint, 102 | .import-path pre.prettyprint code { 103 | margin: 0; 104 | padding: 0; 105 | border: none; 106 | background: white; 107 | } 108 | 109 | .layout-container { 110 | /*display: flex;*/ 111 | /*flex-direction: row;*/ 112 | /*justify-content: flex-start;*/ 113 | /*align-items: stretch;*/ 114 | } 115 | 116 | .layout-container > header { 117 | height: 40px; 118 | line-height: 40px; 119 | font-size: 16px; 120 | padding: 0 10px; 121 | margin: 0; 122 | position: fixed; 123 | width: 100%; 124 | z-index: 1; 125 | background-color: white; 126 | top: 0; 127 | border-bottom: solid 1px #E02130; 128 | } 129 | .layout-container > header > a{ 130 | margin: 0 5px; 131 | } 132 | 133 | .layout-container > header > a.repo-url-github { 134 | font-size: 0; 135 | display: inline-block; 136 | width: 20px; 137 | height: 38px; 138 | background: url("../image/github.png") no-repeat center; 139 | background-size: 20px; 140 | vertical-align: top; 141 | } 142 | 143 | .navigation { 144 | position: fixed; 145 | top: 0; 146 | left: 0; 147 | box-sizing: border-box; 148 | width: 250px; 149 | height: 100%; 150 | padding-top: 40px; 151 | padding-left: 15px; 152 | padding-bottom: 2em; 153 | margin-top:1em; 154 | overflow-x: scroll; 155 | box-shadow: rgba(255, 255, 255, 1) -1px 0 0 inset; 156 | border-right: 1px solid rgba(0, 0, 0, 0.1); 157 | } 158 | 159 | .navigation ul { 160 | padding: 0; 161 | } 162 | 163 | .navigation li { 164 | list-style: none; 165 | margin: 4px 0; 166 | white-space: nowrap; 167 | } 168 | 169 | .navigation .nav-dir-path { 170 | margin-top: 0.7em; 171 | margin-bottom: 0.25em; 172 | font-size: 0.8em; 173 | color: #aaa; 174 | } 175 | 176 | .kind-class, 177 | .kind-interface, 178 | .kind-function, 179 | .kind-typedef, 180 | .kind-variable, 181 | .kind-external { 182 | margin-left: 0.75em; 183 | width: 1.2em; 184 | height: 1.2em; 185 | display: inline-block; 186 | text-align: center; 187 | border-radius: 0.2em; 188 | margin-right: 0.2em; 189 | font-weight: bold; 190 | } 191 | 192 | .kind-class { 193 | color: #009800; 194 | background-color: #bfe5bf; 195 | } 196 | 197 | .kind-interface { 198 | color: #fbca04; 199 | background-color: #fef2c0; 200 | } 201 | 202 | .kind-function { 203 | color: #6b0090; 204 | background-color: #d6bdde; 205 | } 206 | 207 | .kind-variable { 208 | color: #eb6420; 209 | background-color: #fad8c7; 210 | } 211 | 212 | .kind-typedef { 213 | color: #db001e; 214 | background-color: #edbec3; 215 | } 216 | 217 | .kind-external { 218 | color: #0738c3; 219 | background-color: #bbcbea; 220 | } 221 | 222 | h1 .version, 223 | h1 .url a { 224 | font-size: 14px; 225 | color: #aaa; 226 | } 227 | 228 | .content { 229 | margin-top: 40px; 230 | margin-left: 250px; 231 | padding: 10px 50px 10px 20px; 232 | } 233 | 234 | .header-notice { 235 | font-size: 14px; 236 | color: #aaa; 237 | margin: 0; 238 | } 239 | 240 | .expression-extends .prettyprint { 241 | margin-left: 10px; 242 | background: white; 243 | } 244 | 245 | .extends-chain { 246 | border-bottom: 1px solid#ddd; 247 | padding-bottom: 10px; 248 | margin-bottom: 10px; 249 | } 250 | 251 | .extends-chain span:nth-of-type(1) { 252 | padding-left: 10px; 253 | } 254 | 255 | .extends-chain > div { 256 | margin: 5px 0; 257 | } 258 | 259 | .description table { 260 | font-size: 14px; 261 | border-spacing: 0; 262 | border: 0; 263 | border-collapse: collapse; 264 | } 265 | 266 | .description thead { 267 | background: #999; 268 | color: white; 269 | } 270 | 271 | .description table td, 272 | .description table th { 273 | border: solid 1px #ddd; 274 | padding: 4px; 275 | font-weight: normal; 276 | } 277 | 278 | .flat-list ul { 279 | padding-left: 0; 280 | } 281 | 282 | .flat-list li { 283 | display: inline; 284 | list-style: none; 285 | } 286 | 287 | table.summary { 288 | width: 100%; 289 | margin: 10px 0; 290 | border-spacing: 0; 291 | border: 0; 292 | border-collapse: collapse; 293 | } 294 | 295 | table.summary thead { 296 | background: #999; 297 | color: white; 298 | } 299 | 300 | table.summary td { 301 | border: solid 1px #ddd; 302 | padding: 4px 10px; 303 | } 304 | 305 | table.summary tbody td:nth-child(1) { 306 | text-align: right; 307 | white-space: nowrap; 308 | min-width: 64px; 309 | vertical-align: top; 310 | } 311 | 312 | table.summary tbody td:nth-child(2) { 313 | width: 100%; 314 | border-right: none; 315 | } 316 | 317 | table.summary tbody td:nth-child(3) { 318 | white-space: nowrap; 319 | border-left: none; 320 | vertical-align: top; 321 | } 322 | 323 | table.summary td > div:nth-of-type(2) { 324 | padding-top: 4px; 325 | padding-left: 15px; 326 | } 327 | 328 | table.summary td p { 329 | margin-bottom: 0; 330 | } 331 | 332 | .inherited-summary thead td { 333 | padding-left: 2px; 334 | } 335 | 336 | .inherited-summary thead a { 337 | color: white; 338 | } 339 | 340 | .inherited-summary .summary tbody { 341 | display: none; 342 | } 343 | 344 | .inherited-summary .summary .toggle { 345 | padding: 0 4px; 346 | font-size: 12px; 347 | cursor: pointer; 348 | } 349 | .inherited-summary .summary .toggle.closed:before { 350 | content: "▶"; 351 | } 352 | .inherited-summary .summary .toggle.opened:before { 353 | content: "▼"; 354 | } 355 | 356 | .member, .method { 357 | margin-bottom: 24px; 358 | } 359 | 360 | table.params { 361 | width: 100%; 362 | margin: 10px 0; 363 | border-spacing: 0; 364 | border: 0; 365 | border-collapse: collapse; 366 | } 367 | 368 | table.params thead { 369 | background: #eee; 370 | color: #aaa; 371 | } 372 | 373 | table.params td { 374 | padding: 4px; 375 | border: solid 1px #ddd; 376 | } 377 | 378 | table.params td p { 379 | margin: 0; 380 | } 381 | 382 | .content .detail > * { 383 | margin: 15px 0; 384 | } 385 | 386 | .content .detail > h3 { 387 | color: black; 388 | } 389 | 390 | .content .detail > div { 391 | margin-left: 10px; 392 | } 393 | 394 | .content .detail > .import-path { 395 | margin-top: -8px; 396 | } 397 | 398 | .content .detail + .detail { 399 | margin-top: 30px; 400 | } 401 | 402 | .content .detail .throw td:first-child { 403 | padding-right: 10px; 404 | } 405 | 406 | .content .detail h4 + :not(pre) { 407 | padding-left: 0; 408 | margin-left: 10px; 409 | } 410 | 411 | .content .detail h4 + ul li { 412 | list-style: none; 413 | } 414 | 415 | .return-param * { 416 | display: inline; 417 | } 418 | 419 | .argument-params { 420 | margin-bottom: 20px; 421 | } 422 | 423 | .return-type { 424 | padding-right: 10px; 425 | font-weight: normal; 426 | } 427 | 428 | .return-desc { 429 | margin-left: 10px; 430 | margin-top: 4px; 431 | } 432 | 433 | .return-desc p { 434 | margin: 0; 435 | } 436 | 437 | .deprecated, .experimental, .instance-docs { 438 | border-left: solid 5px orange; 439 | padding-left: 4px; 440 | margin: 4px 0; 441 | } 442 | 443 | tr.listen p, 444 | tr.throw p, 445 | tr.emit p{ 446 | margin-bottom: 10px; 447 | } 448 | 449 | .version, .since { 450 | color: #aaa; 451 | } 452 | 453 | h3 .right-info { 454 | position: absolute; 455 | right: 4px; 456 | font-size: 14px; 457 | } 458 | 459 | .version + .since:before { 460 | content: '| '; 461 | } 462 | 463 | .see { 464 | margin-top: 10px; 465 | } 466 | 467 | .see h4 { 468 | margin: 4px 0; 469 | } 470 | 471 | .content .detail h4 + .example-doc { 472 | margin: 6px 0; 473 | } 474 | 475 | .example-caption { 476 | position: relative; 477 | bottom: -1px; 478 | display: inline-block; 479 | padding: 4px; 480 | font-style: italic; 481 | background-color: #f5f5f5; 482 | font-weight: bold; 483 | border-radius: 3px; 484 | border-bottom-left-radius: 0; 485 | border-bottom-right-radius: 0; 486 | } 487 | 488 | .example-caption + pre.source-code { 489 | margin-top: 0; 490 | border-top-left-radius: 0; 491 | } 492 | 493 | footer, .file-footer { 494 | text-align: right; 495 | font-style: italic; 496 | font-weight: 100; 497 | font-size: 13px; 498 | margin-right: 50px; 499 | margin-left: 270px; 500 | border-top: 1px solid #ddd; 501 | padding-top: 30px; 502 | margin-top: 20px; 503 | padding-bottom: 10px; 504 | } 505 | 506 | pre.source-code { 507 | background: #f5f5f5; 508 | padding: 4px; 509 | } 510 | 511 | pre.raw-source-code > code { 512 | padding: 0; 513 | margin: 0; 514 | } 515 | 516 | pre.source-code.line-number { 517 | padding: 0; 518 | } 519 | 520 | pre.source-code ol { 521 | background: #eee; 522 | padding-left: 40px; 523 | } 524 | 525 | pre.source-code li { 526 | background: white; 527 | padding-left: 4px; 528 | list-style: decimal; 529 | margin: 0; 530 | } 531 | 532 | pre.source-code.line-number li.active { 533 | background: rgb(255, 255, 150); 534 | } 535 | 536 | pre.source-code.line-number li.error-line { 537 | background: #ffb8bf; 538 | } 539 | 540 | table.files-summary { 541 | width: 100%; 542 | margin: 10px 0; 543 | border-spacing: 0; 544 | border: 0; 545 | border-collapse: collapse; 546 | text-align: right; 547 | } 548 | 549 | table.files-summary tbody tr:hover { 550 | background: #eee; 551 | } 552 | 553 | table.files-summary td:first-child, 554 | table.files-summary td:nth-of-type(2) { 555 | text-align: left; 556 | } 557 | 558 | table.files-summary[data-use-coverage="false"] td.coverage { 559 | display: none; 560 | } 561 | 562 | table.files-summary thead { 563 | background: #999; 564 | color: white; 565 | } 566 | 567 | table.files-summary td { 568 | border: solid 1px #ddd; 569 | padding: 4px 10px; 570 | vertical-align: top; 571 | } 572 | 573 | table.files-summary td.identifiers > span { 574 | display: block; 575 | margin-top: 4px; 576 | } 577 | table.files-summary td.identifiers > span:first-child { 578 | margin-top: 0; 579 | } 580 | 581 | table.files-summary .coverage-count { 582 | font-size: 12px; 583 | color: #aaa; 584 | display: inline-block; 585 | min-width: 40px; 586 | } 587 | 588 | .total-coverage-count { 589 | position: relative; 590 | bottom: 2px; 591 | font-size: 12px; 592 | color: #666; 593 | font-weight: 500; 594 | padding-left: 5px; 595 | } 596 | 597 | table.test-summary thead { 598 | background: #999; 599 | color: white; 600 | } 601 | 602 | table.test-summary thead .test-description { 603 | width: 50%; 604 | } 605 | 606 | table.test-summary { 607 | width: 100%; 608 | margin: 10px 0; 609 | border-spacing: 0; 610 | border: 0; 611 | border-collapse: collapse; 612 | } 613 | 614 | table.test-summary thead .test-count { 615 | width: 3em; 616 | } 617 | 618 | table.test-summary tbody tr:hover { 619 | background-color: #eee; 620 | } 621 | 622 | table.test-summary td { 623 | border: solid 1px #ddd; 624 | padding: 4px 10px; 625 | vertical-align: top; 626 | } 627 | 628 | table.test-summary td p { 629 | margin: 0; 630 | } 631 | 632 | table.test-summary tr.test-describe .toggle { 633 | display: inline-block; 634 | float: left; 635 | margin-right: 4px; 636 | cursor: pointer; 637 | } 638 | 639 | table.test-summary tr.test-describe .toggle.opened:before { 640 | content: '▼'; 641 | } 642 | 643 | table.test-summary tr.test-describe .toggle.closed:before { 644 | content: '▶'; 645 | } 646 | 647 | table.test-summary .test-target > span { 648 | display: block; 649 | margin-top: 4px; 650 | } 651 | table.test-summary .test-target > span:first-child { 652 | margin-top: 0; 653 | } 654 | 655 | .inner-link-active { 656 | background: rgb(255, 255, 150); 657 | } 658 | 659 | /* search box */ 660 | .search-box { 661 | position: absolute; 662 | top: 10px; 663 | right: 50px; 664 | padding-right: 8px; 665 | padding-bottom: 10px; 666 | line-height: normal; 667 | font-size: 12px; 668 | } 669 | 670 | .search-box img { 671 | width: 20px; 672 | vertical-align: top; 673 | } 674 | 675 | .search-input { 676 | display: inline; 677 | visibility: hidden; 678 | width: 0; 679 | padding: 2px; 680 | height: 1.5em; 681 | outline: none; 682 | background: transparent; 683 | border: 1px #0af; 684 | border-style: none none solid none; 685 | vertical-align: bottom; 686 | } 687 | 688 | .search-input-edge { 689 | display: none; 690 | width: 1px; 691 | height: 5px; 692 | background-color: #0af; 693 | vertical-align: bottom; 694 | } 695 | 696 | .search-result { 697 | position: absolute; 698 | display: none; 699 | height: 600px; 700 | width: 100%; 701 | padding: 0; 702 | margin-top: 5px; 703 | margin-left: 24px; 704 | background: white; 705 | box-shadow: 1px 1px 4px rgb(0,0,0); 706 | white-space: nowrap; 707 | overflow-y: scroll; 708 | } 709 | 710 | .search-result-import-path { 711 | color: #aaa; 712 | font-size: 12px; 713 | } 714 | 715 | .search-result li { 716 | list-style: none; 717 | padding: 2px 4px; 718 | } 719 | 720 | .search-result li a { 721 | display: block; 722 | } 723 | 724 | .search-result li.selected { 725 | background: #ddd; 726 | } 727 | 728 | .search-result li.search-separator { 729 | background: rgb(37, 138, 175); 730 | color: white; 731 | } 732 | 733 | .search-box.active .search-input { 734 | visibility: visible; 735 | transition: width 0.2s ease-out; 736 | width: 300px; 737 | } 738 | 739 | .search-box.active .search-input-edge { 740 | display: inline-block; 741 | } 742 | 743 | /* coverage badge */ 744 | .esdoc-coverage { 745 | display: inline-block; 746 | height: 20px; 747 | vertical-align: top; 748 | } 749 | 750 | h1 .esdoc-coverage { 751 | position: relative; 752 | top: -4px; 753 | } 754 | 755 | .esdoc-coverage-wrap { 756 | color: white; 757 | font-size: 12px; 758 | font-weight: 500; 759 | } 760 | 761 | .esdoc-coverage-label { 762 | padding: 3px 4px 3px 6px; 763 | background: linear-gradient(to bottom, #5e5e5e 0%,#4c4c4c 100%); 764 | border-radius: 4px 0 0 4px; 765 | display: inline-block; 766 | height: 20px; 767 | box-sizing: border-box; 768 | line-height: 14px; 769 | } 770 | 771 | .esdoc-coverage-ratio { 772 | padding: 3px 6px 3px 4px; 773 | border-radius: 0 4px 4px 0; 774 | display: inline-block; 775 | height: 20px; 776 | box-sizing: border-box; 777 | line-height: 14px; 778 | } 779 | 780 | .esdoc-coverage-low { 781 | background: linear-gradient(to bottom, #db654f 0%,#c9533d 100%); 782 | } 783 | 784 | .esdoc-coverage-middle { 785 | background: linear-gradient(to bottom, #dab226 0%,#c9a179 100%); 786 | } 787 | 788 | .esdoc-coverage-high { 789 | background: linear-gradient(to bottom, #4fc921 0%,#3eb810 100%); 790 | } 791 | 792 | .github-markdown .manual-toc { 793 | padding-left: 0; 794 | } 795 | 796 | /** manual */ 797 | 798 | .manual-root .navigation { 799 | padding-left: 0; 800 | } 801 | 802 | .navigation .manual-toc-title { 803 | margin: 0; 804 | padding: 0.5em 0 0.5em 1em; 805 | border: none; 806 | font-size: 1em; 807 | font-weight: normal; 808 | } 809 | 810 | .navigation .manual-toc-title:first-child { 811 | margin-top: 0; 812 | } 813 | 814 | .navigation .manual-toc { 815 | display: none; 816 | margin-left: 0.5em; 817 | margin-top: -0.25em; 818 | } 819 | 820 | .github-markdown .manual-toc-title a { 821 | color: inherit; 822 | } 823 | 824 | .manual-breadcrumb-list { 825 | font-size: 0.8em; 826 | margin-bottom: 1em; 827 | } 828 | 829 | .manual-toc-title a:hover { 830 | color: #039BE5; 831 | } 832 | 833 | .manual-toc li { 834 | margin: 0.75em 0; 835 | list-style-type: none; 836 | } 837 | 838 | .manual-toc .indent-h1 { 839 | margin-left: 0; 840 | } 841 | .manual-toc .indent-h2 { 842 | margin-left: 1em; 843 | } 844 | .manual-toc .indent-h3 { 845 | margin-left: 3em; 846 | } 847 | .manual-toc .indent-h4 { 848 | margin-left: 4em; 849 | } 850 | .manual-toc .indent-h5 { 851 | margin-left: 5em; 852 | } 853 | 854 | .manual-nav li { 855 | margin: 0.75em 0; 856 | } 857 | 858 | .manual-dot { 859 | margin-left: 0.75em; 860 | width: 0.6em; 861 | height: 0.6em; 862 | display: inline-block; 863 | border-radius: 0.3em; 864 | margin-right: 0.3em; 865 | background-color: #bfe5bf; 866 | } 867 | 868 | /* github markdown */ 869 | .github-markdown { 870 | font-size: 16px; 871 | } 872 | 873 | .github-markdown h1, 874 | .github-markdown h2, 875 | .github-markdown h3, 876 | .github-markdown h4, 877 | .github-markdown h5 { 878 | margin-top: 1em; 879 | margin-bottom: 16px; 880 | font-weight: bold; 881 | padding: 0; 882 | } 883 | 884 | .github-markdown h1:nth-of-type(1) { 885 | margin-top: 0; 886 | } 887 | 888 | .github-markdown h1 { 889 | font-size: 2em; 890 | padding-bottom: 0.3em; 891 | } 892 | 893 | .github-markdown h2 { 894 | font-size: 1.75em; 895 | padding-bottom: 0.3em; 896 | } 897 | 898 | .github-markdown h3 { 899 | font-size: 1.5em; 900 | background-color: transparent; 901 | } 902 | 903 | .github-markdown h4 { 904 | font-size: 1.25em; 905 | } 906 | 907 | .github-markdown h5 { 908 | font-size: 1em; 909 | } 910 | 911 | .github-markdown ul, .github-markdown ol { 912 | padding-left: 2em; 913 | } 914 | 915 | .github-markdown pre > code { 916 | font-size: 0.85em; 917 | } 918 | 919 | .github-markdown table { 920 | margin-bottom: 1em; 921 | border-collapse: collapse; 922 | border-spacing: 0; 923 | } 924 | 925 | .github-markdown table tr { 926 | background-color: #fff; 927 | border-top: 1px solid #ccc; 928 | } 929 | 930 | .github-markdown table th, 931 | .github-markdown table td { 932 | padding: 6px 13px; 933 | border: 1px solid #ddd; 934 | } 935 | 936 | .github-markdown table tr:nth-child(2n) { 937 | background-color: #f8f8f8; 938 | } 939 | 940 | /** badge(.svg) does not have border */ 941 | .github-markdown img:not([src*=".svg"]) { 942 | max-width: 100%; 943 | box-shadow: 1px 1px 1px rgba(0,0,0,0.5); 944 | } 945 | -------------------------------------------------------------------------------- /docs/file/src/debug.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | src/debug.js | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

src/debug.js

47 |
import debug from 'debug';
 48 | import { is } from 'immutable';
 49 | import union from 'lodash.union';
 50 | import keys from 'lodash.keys';
 51 | import { getComponentName } from './util';
 52 | 
 53 | /**
 54 |  * @typedef {Object} Change
 55 |  * @property {string} component the component name
 56 |  * @property {string} type string containing either 'props' or 'state'
 57 |  * @property {any} from the original value of the change
 58 |  * @property {any} to the new value of the change
 59 |  */
 60 | 
 61 |  /**
 62 |   * The default log funcion to be used
 63 |   * @type {function}
 64 |   * @since 1.0.0
 65 |   */
 66 | const logFunc = debug('ReactUpdateHelper');
 67 | 
 68 | /**
 69 |  * Log and return the changes in a component as they occur to help with debugging
 70 |  * @protected
 71 |  * @param {object} context - the component context
 72 |  * @param {object} context.props - the component props object
 73 |  * @param {object} context.state - the component state object
 74 |  * @param {object} nProps - the next props in the update process
 75 |  * @param {object} nState - the next state in the update process
 76 |  * @param {function} log - the log function to use when logging changes
 77 |  * @return {Array<Change>} - the changes that took place
 78 |  * @since 1.0.0
 79 |  */
 80 | export function reportChanges(context, nProps, nState, log = logFunc) {
 81 |   const props = context.props || {};
 82 |   const state = context.state || {};
 83 |   const newProps = nProps || {};
 84 |   const newState = nState || {};
 85 |   const availableProps = union(keys(props), keys(newProps));
 86 |   const stateKeys = union(keys(state), keys(newState));
 87 |   const name = getComponentName(context);
 88 |   const changes = [];
 89 |   availableProps.forEach((key) => {
 90 |     const oldValue = props[key];
 91 |     const newValue = newProps[key];
 92 |     if (!is(oldValue, newValue)) {
 93 |       changes.push({
 94 |         component: name,
 95 |         type: 'props',
 96 |         from: props[key],
 97 |         to: newProps[key],
 98 |       });
 99 |       log('%s: changed prop %s from %o to %o', name, key, oldValue, newValue);
100 |     }
101 |   });
102 |   stateKeys.forEach((key) => {
103 |     const oldValue = state[key];
104 |     const newValue = newState[key];
105 |     if (!is(oldValue, newValue)) {
106 |       changes.push({
107 |         component: name,
108 |         type: 'state',
109 |         from: state[key],
110 |         to: newState[key],
111 |       });
112 |       log('%s: changed state key %s from %o to %o', name, key, oldValue, newValue);
113 |     }
114 |   });
115 |   return changes;
116 | }
117 | 
118 | 119 |
120 | 121 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/file/src/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | src/index.js | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

src/index.js

47 |
import React from 'react';
 48 | import keys from 'lodash.keys';
 49 | import { is } from 'immutable';
 50 | import { getComponentName } from './util';
 51 | 
 52 | /**
 53 |  * @external {React.Component} https://facebook.github.io/react/docs/component-api.html
 54 |  */
 55 | 
 56 | /**
 57 |  * Simply checks if a component update is needed
 58 |  * @public
 59 |  * @param {object} context - the component context, containing the current props and state values
 60 |  * @param {object} nProps - the next props in the update process
 61 |  * @param {object} nState - the next state in the update process
 62 |  * @return {boolean} - true if should update the component else false
 63 |  * @since 1.0.0
 64 |  */
 65 | export function shouldUpdate({ props, state }, nProps, nState) {
 66 |   const propsKeys = keys(props || {});
 67 |   const stateKeys = keys(state || {});
 68 |   const nPropsKeys = keys(nProps || {});
 69 |   const nStateKeys = keys(nState || {});
 70 |   if (propsKeys.length !== nPropsKeys.length || stateKeys.length !== nStateKeys.length) {
 71 |     return true;
 72 |   }
 73 |   for (let i = 0, l = propsKeys.length; i < l; i += 1) {
 74 |     const key = propsKeys[i];
 75 |     if (!Object.prototype.hasOwnProperty.call(nProps, key)) {
 76 |       return true;
 77 |     }
 78 |     if (!is(props[key], nProps[key])) {
 79 |       return true;
 80 |     }
 81 |   }
 82 |   for (let i = 0, l = stateKeys.length; i < l; i += 1) {
 83 |     const key = stateKeys[i];
 84 |     if (!Object.prototype.hasOwnProperty.call(nState, key)) {
 85 |       return true;
 86 |     }
 87 |     if (!is(state[key], nState[key])) {
 88 |       return true;
 89 |     }
 90 |   }
 91 |   return false;
 92 | }
 93 | 
 94 | /**
 95 |  * Enhances a component with change checks and console logs powered by debugjs
 96 |  * @public
 97 |  * @example
 98 |  * // Usage as a high order component
 99 |  * class MyComponent extends React.Component {
100 |  *  render() { return <p>Hello World!</p>; }
101 |  * }
102 |  * withDebugInfo(MyComponent); // Your enhanced component
103 |  * @param {React.Component} Component - the component to be enhanced
104 |  * @return {React.Component} - the enhanced component
105 |  * @since 2.0.0
106 |  */
107 | export function withDebugInfo(Component) {
108 |   let debug;
109 |   return class extends React.Component {
110 |     static displayName = getComponentName(Component);
111 | 
112 |     static propTypes = Component.propTypes;
113 | 
114 |     shouldComponentUpdate(nextProps, nextState) {
115 |       debug = debug || require('./debug');
116 |       debug.reportChanges(this, nextProps, nextState);
117 |       return shouldUpdate(this, nextProps, nextState);
118 |     }
119 | 
120 |     render() {
121 |       return <Component {...this.props} />;
122 |     }
123 |   };
124 | }
125 | 
126 | /**
127 |  * Encapsulates the shouldUpdate logic as a high order function
128 |  * @public
129 |  * @example
130 |  * // Usage as a high order component
131 |  * class MyComponent extends React.Component {
132 |  *  render() { return <p>Hello World!</p>; }
133 |  * }
134 |  * withPureRender(MyComponent); // Your enhanced component
135 |  * @param {React.Component} PureComponent - the component to be enhanced
136 |  * @return {React.Component} - the enhanced component
137 |  * @since 1.0.0
138 |  */
139 | export function withPureRender(PureComponent) {
140 |   return class extends React.Component {
141 | 
142 |     static displayName = getComponentName(PureComponent);
143 | 
144 |     static propTypes = PureComponent.propTypes;
145 | 
146 |     shouldComponentUpdate(nextProps, nextState) {
147 |       return shouldUpdate(this, nextProps, nextState);
148 |     }
149 | 
150 |     render() {
151 |       return <PureComponent {...this.props} />;
152 |     }
153 |   };
154 | }
155 | 
156 | 157 |
158 | 159 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/file/src/util.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | src/util.js | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

src/util.js

47 |
/**
48 |  * Get the name of the given React component
49 |  * @protected
50 |  * @param {object} ctx - the component context, containing the name, props and state values
51 |  * @return {string} - the component name
52 |  * @since 1.0.0
53 |  */
54 | export function getComponentName(ctx) {
55 |   return ctx.constructor.displayName || ctx.displayName || ctx.name || ctx.constructor.name;
56 | }
57 | 
58 | 59 |
60 | 61 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /docs/function/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Function | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

Function

47 |
48 | 49 | 50 | 51 | 52 | 59 | 72 | 76 | 77 | 78 | 85 | 98 | 102 | 103 | 104 | 111 | 124 | 128 | 129 | 130 |
Static Public Summary
53 | public 54 | 55 | 56 | 57 | 58 | 60 |
61 |

62 | shouldUpdate(context: object, nProps: object, nState: object): boolean 63 |

64 |
65 |
66 | 67 | 68 |

Simply checks if a component update is needed

69 |
70 |
71 |
73 | 74 | since 1.0.0 75 |
79 | public 80 | 81 | 82 | 83 | 84 | 86 |
87 |

88 | withDebugInfo(Component: React.Component): React.Component 89 |

90 |
91 |
92 | 93 | 94 |

Enhances a component with change checks and console logs powered by debugjs

95 |
96 |
97 |
99 | 100 | since 2.0.0 101 |
105 | public 106 | 107 | 108 | 109 | 110 | 112 |
113 |

114 | withPureRender(PureComponent: React.Component): React.Component 115 |

116 |
117 |
118 | 119 | 120 |

Encapsulates the shouldUpdate logic as a high order function

121 |
122 |
123 |
125 | 126 | since 1.0.0 127 |
131 | 132 | 133 | 134 | 135 | 136 | 143 | 156 | 160 | 161 | 162 | 169 | 182 | 186 | 187 | 188 |
Static Protected Summary
137 | protected 138 | 139 | 140 | 141 | 142 | 144 |
145 |

146 | getComponentName(ctx: object): string 147 |

148 |
149 |
150 | 151 | 152 |

Get the name of the given React component

153 |
154 |
155 |
157 | 158 | since 1.0.0 159 |
163 | protected 164 | 165 | 166 | 167 | 168 | 170 |
171 |

172 | reportChanges(context: object, nProps: object, nState: object, log: function): Array<Change> 173 |

174 |
175 |
176 | 177 | 178 |

Log and return the changes in a component as they occur to help with debugging

179 |
180 |
181 |
183 | 184 | since 1.0.0 185 |
189 |
190 |

Static Public

191 | 192 |
193 |

194 | public 195 | 196 | 197 | 198 | 199 | shouldUpdate(context: object, nProps: object, nState: object): boolean 200 | 201 | 202 | since 1.0.0 203 | source 204 | 205 |

206 | 207 |
import {shouldUpdate} from 'react-update-helper/src/index.js'
208 | 209 | 210 |

Simply checks if a component update is needed

211 |
212 | 213 | 214 | 215 |
216 |

Params:

217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 229 | 230 | 231 | 232 | 233 | 234 | 236 | 237 | 238 | 239 | 240 | 241 | 243 | 244 | 245 |
NameTypeAttributeDescription
contextobject

the component context, containing the current props and state values

228 |
nPropsobject

the next props in the update process

235 |
nStateobject

the next state in the update process

242 |
246 |
247 |
248 | 249 |
250 |

Return:

251 | 252 | 253 | 254 | 256 | 257 |
boolean

true if should update the component else false

255 |
258 |
259 |
260 |
261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 |
275 |
276 |

277 | public 278 | 279 | 280 | 281 | 282 | withDebugInfo(Component: React.Component): React.Component 283 | 284 | 285 | since 2.0.0 286 | source 287 | 288 |

289 | 290 |
import {withDebugInfo} from 'react-update-helper/src/index.js'
291 | 292 | 293 |

Enhances a component with change checks and console logs powered by debugjs

294 |
295 | 296 | 297 | 298 |
299 |

Params:

300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 312 | 313 | 314 |
NameTypeAttributeDescription
ComponentReact.Component

the component to be enhanced

311 |
315 |
316 |
317 | 318 |
319 |

Return:

320 | 321 | 322 | 323 | 325 | 326 |
React.Component

the enhanced component

324 |
327 |
328 |
329 |
330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 |
338 |

Example:

339 | 340 |
341 | 342 |
// Usage as a high order component
343 | class MyComponent extends React.Component {
344 |  render() { return <p>Hello World!</p>; }
345 | }
346 | withDebugInfo(MyComponent); // Your enhanced component
347 |
348 |
349 | 350 | 351 | 352 | 353 | 354 |
355 |
356 |

357 | public 358 | 359 | 360 | 361 | 362 | withPureRender(PureComponent: React.Component): React.Component 363 | 364 | 365 | since 1.0.0 366 | source 367 | 368 |

369 | 370 |
import {withPureRender} from 'react-update-helper/src/index.js'
371 | 372 | 373 |

Encapsulates the shouldUpdate logic as a high order function

374 |
375 | 376 | 377 | 378 |
379 |

Params:

380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 392 | 393 | 394 |
NameTypeAttributeDescription
PureComponentReact.Component

the component to be enhanced

391 |
395 |
396 |
397 | 398 |
399 |

Return:

400 | 401 | 402 | 403 | 405 | 406 |
React.Component

the enhanced component

404 |
407 |
408 |
409 |
410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
418 |

Example:

419 | 420 |
421 | 422 |
// Usage as a high order component
423 | class MyComponent extends React.Component {
424 |  render() { return <p>Hello World!</p>; }
425 | }
426 | withPureRender(MyComponent); // Your enhanced component
427 |
428 |
429 | 430 | 431 | 432 | 433 | 434 |
435 |

Static Protected

436 | 437 |
438 |

439 | protected 440 | 441 | 442 | 443 | 444 | getComponentName(ctx: object): string 445 | 446 | 447 | since 1.0.0 448 | source 449 | 450 |

451 | 452 |
import {getComponentName} from 'react-update-helper/src/util.js'
453 | 454 | 455 |

Get the name of the given React component

456 |
457 | 458 | 459 | 460 |
461 |

Params:

462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 474 | 475 | 476 |
NameTypeAttributeDescription
ctxobject

the component context, containing the name, props and state values

473 |
477 |
478 |
479 | 480 |
481 |

Return:

482 | 483 | 484 | 485 | 487 | 488 |
string

the component name

486 |
489 |
490 |
491 |
492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 |
506 |
507 |

508 | protected 509 | 510 | 511 | 512 | 513 | reportChanges(context: object, nProps: object, nState: object, log: function): Array<Change> 514 | 515 | 516 | since 1.0.0 517 | source 518 | 519 |

520 | 521 |
import {reportChanges} from 'react-update-helper/src/debug.js'
522 | 523 | 524 |

Log and return the changes in a component as they occur to help with debugging

525 |
526 | 527 | 528 | 529 |
530 |

Params:

531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 543 | 544 | 545 | 546 | 547 | 548 | 550 | 551 | 552 | 553 | 554 | 555 | 557 | 558 | 559 | 560 | 561 | 562 | 564 | 565 | 566 | 567 | 568 | 569 | 571 | 572 | 573 | 574 | 575 | 576 | 578 | 579 | 580 |
NameTypeAttributeDescription
contextobject

the component context

542 |
context.propsobject

the component props object

549 |
context.stateobject

the component state object

556 |
nPropsobject

the next props in the update process

563 |
nStateobject

the next state in the update process

570 |
logfunction

the log function to use when logging changes

577 |
581 |
582 |
583 | 584 |
585 |

Return:

586 | 587 | 588 | 589 | 591 | 592 |
Array<Change>

the changes that took place

590 |
593 |
594 |
595 |
596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 |
610 |
611 |
612 | 613 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | -------------------------------------------------------------------------------- /docs/identifiers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Index | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

References

47 | 48 | 49 |

Function Summary

50 | 51 | 52 | 53 | 54 | 61 | 74 | 78 | 79 | 80 | 87 | 100 | 104 | 105 | 106 | 113 | 126 | 130 | 131 | 132 |
Static Public Function Summary
55 | public 56 | 57 | 58 | 59 | 60 | 62 |
63 |

64 | shouldUpdate(context: object, nProps: object, nState: object): boolean 65 |

66 |
67 |
68 | 69 | 70 |

Simply checks if a component update is needed

71 |
72 |
73 |
75 | 76 | since 1.0.0 77 |
81 | public 82 | 83 | 84 | 85 | 86 | 88 |
89 |

90 | withDebugInfo(Component: React.Component): React.Component 91 |

92 |
93 |
94 | 95 | 96 |

Enhances a component with change checks and console logs powered by debugjs

97 |
98 |
99 |
101 | 102 | since 2.0.0 103 |
107 | public 108 | 109 | 110 | 111 | 112 | 114 |
115 |

116 | withPureRender(PureComponent: React.Component): React.Component 117 |

118 |
119 |
120 | 121 | 122 |

Encapsulates the shouldUpdate logic as a high order function

123 |
124 |
125 |
127 | 128 | since 1.0.0 129 |
133 | 134 | 135 | 136 | 137 | 138 | 145 | 158 | 162 | 163 | 164 | 171 | 184 | 188 | 189 | 190 |
Static Protected Function Summary
139 | protected 140 | 141 | 142 | 143 | 144 | 146 |
147 |

148 | getComponentName(ctx: object): string 149 |

150 |
151 |
152 | 153 | 154 |

Get the name of the given React component

155 |
156 |
157 |
159 | 160 | since 1.0.0 161 |
165 | protected 166 | 167 | 168 | 169 | 170 | 172 |
173 |

174 | reportChanges(context: object, nProps: object, nState: object, log: function): Array<Change> 175 |

176 |
177 |
178 | 179 | 180 |

Log and return the changes in a component as they occur to help with debugging

181 |
182 |
183 |
185 | 186 | since 1.0.0 187 |
191 |
192 | 193 |

Typedef Summary

194 | 195 | 196 | 197 | 198 | 205 | 217 | 221 | 222 | 223 |
Static Public Typedef Summary
199 | public 200 | 201 | 202 | 203 | 204 | 206 |
207 |

208 | Change: Object 209 |

210 |
211 |
212 | 213 | 214 | 215 |
216 |
218 | 219 | 220 |
224 |
225 |

External Summary

226 | 227 | 228 | 229 | 230 | 237 | 249 | 253 | 254 | 255 |
Static Public External Summary
231 | public 232 | 233 | 234 | 235 | 236 | 238 |
239 |

240 | React.Component 241 |

242 |
243 |
244 | 245 | 246 | 247 |
248 |
250 | 251 | 252 |
256 |
257 |
258 | 259 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /docs/image/badge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | document 13 | document 14 | @ratio@ 15 | @ratio@ 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/image/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkxml/react-update-helper/2a1861118226f8f5c0ca9fd11d9133d6e45267ad/docs/image/github.png -------------------------------------------------------------------------------- /docs/image/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkxml/react-update-helper/2a1861118226f8f5c0ca9fd11d9133d6e45267ad/docs/image/search.png -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
31 | 32 | 45 | 46 |

react-update-helper

47 |

Build SemVer Coverage Docs License

48 |

A React set of helpers to debug and accelerate your component updates.

49 |

It works with debug and Immutable.

50 |

Goal

51 |

This react kit is a set of two high order components (HOCs) that are useful for react app development:

52 |
    53 |
  1. withPureRender is the first enhancer. It helps you prevent useless component updates (even when using deep Immutable.JS objects).

    54 |
  2. 55 |
  3. withDebugInfo is the second one. It allows you to check why a component updated in your browser console.

    56 |
  4. 57 |
58 |

The idea combines thoughts from PureRenderMixin and from a blog post about React prop/state change debugging.

59 |

Why and when to use these helpers?

60 |

Here are a few common uses:

61 |
    62 |
  • You might want to use withPureRender when

    63 |
      64 |
    • You want to use Immutable objects as your props or state values.
    • 65 |
    • You use Redux with Immutable state objects
    • 66 |
    67 |
  • 68 |
  • You might want to use withDebugInfo when:

    69 |
      70 |
    • You want to debug props and state changes.
    • 71 |
    • Pairing the component update logging with react-perf-addon to help busting performance issues.
    • 72 |
    73 |
  • 74 |
75 |

Still don't know if you need this? Take a look at the Usage section.

76 |

Install

77 |

It currently needs three peerDependencies.

78 | 83 |

This module is currently available only on npm.

84 |

Install now:

85 |

npm install react-update-helper --save

86 |

You are done, check the Usage section to know how to use it.

87 |

Why those peerDependencies?

88 |

React dependency is pretty obvious since this is a react plugin.

89 |

Immutable is an optional choice but you might already be using it so there is no reason to duplicate the versions since this module just need the is() function of the immutable package.

90 |

Even if you are not using Immutable on your own, most modern build systems like webpack v2 or rollup will isolate the tiny bit of code this module need to operate.

91 |

As for debug, it is optional and will only be required if you use withDebugInfo.

92 |

Usage

93 |

The package exposes one function and two component enhancers that you can use:

94 |
    95 |
  • shouldUpdate, the core update function with Immutable support. You may use it directly in your shouldComponentUpdate. Or you can easily switch to the enhancer approach of withPureRender.
  • 96 |
  • withPureRender, the easy plug-and-play enhancer HOC for any React component that will run shouldUpdate in every update attempt for you.
  • 97 |
  • withDebugInfo, the debug function you may use in development to log out a nice component change feed in the browser console.
  • 98 |
99 |

withPureRender(Component)

100 |

The easiest way to get all the goods of automatic shouldUpdate is using withPureRender.

101 |

You can use it as a normal high order component as follows:

102 |
// Use react
103 | import React from 'react';
104 | 
105 | // Use withPureRender
106 | import { withPureRender } from 'react-update-helper';
107 | 
108 | // Create the component
109 | class Greet extends React.Component {
110 |   render() {
111 |     return <div>Hello {this.props.greet}!</div>;
112 |   }
113 | }
114 | 
115 | // Enhance the Greet with withPureRender and export it
116 | export default withPureRender(Greet);
117 | 
118 |

Or you can use it as a ES7 decorator if you support and like that way:

119 |
// Use react
120 | import React from 'react';
121 | 
122 | // Use withPureRender
123 | import { withPureRender } from 'react-update-helper';
124 | 
125 | // Create the enhanced component
126 | @withPureRender
127 | class Greet extends React.Component {
128 |   render() {
129 |     return <div>Hello {this.props.greet}!</div>;
130 |   }
131 | }
132 | 
133 | // Export the already enhanced Greet
134 | export default Greet;
135 | 
136 |

It works with pure functional components too:

137 |
// Use react
138 | import React from 'react';
139 | 
140 | // Use withPureRender
141 | import { withPureRender } from 'react-update-helper';
142 | 
143 | // Create the component
144 | function Greet({ greet }) {
145 |   return <div>Hello {greet}!</div>;
146 | }
147 | 
148 | // Enhance the Greet with withPureRender and export it
149 | export default withPureRender(Greet);
150 | 
151 |

shouldUpdate(componentContext, nextProps, nextState)

152 |

You can use the shouldUpdate function directly if you need to, like if you have more stuff to check when updating your component to improve performance.

153 |

Quick example of dening the greet prop value to change to falsy values while also maintaining the same value check with shouldUpdate:

154 |
// Use react
155 | import React from 'react';
156 | 
157 | // Use shouldUpdate
158 | import { shouldUpdate } from 'react-update-helper';
159 | 
160 | // Create the component
161 | class Greet extends React.Component {
162 | 
163 |   shouldComponentUpdate(nextProps, nextState) {
164 |     // Ignore change to falsy value
165 |     if (!!nextProps.greet) return false;
166 |     // Will only return true when stuff changes, even with Immutable objects
167 |     return shouldUpdate(this, nextProps, nextState);
168 |   }
169 | 
170 |   render() {
171 |     return <div>Hello {this.props.greet}!</div>;
172 |   }
173 | }
174 | 
175 | // Just export Greet
176 | export default Greet;
177 | 
178 |

Debugging updates

179 |

Use withDebugInfo for that matter:

180 |
// Use react
181 | import React from 'react';
182 | 
183 | // Use withPureRender
184 | import { withDebugInfo } from 'react-update-helper';
185 | 
186 | // Create the component
187 | class Greet extends React.Component {
188 |   render() {
189 |     return <div>Hello {this.props.greet}!</div>;
190 |   }
191 | }
192 | 
193 | // Enhance the Greet with withDebugInfo and export it
194 | export default withDebugInfo(Greet);
195 | 
196 |

We use debug internally to log component updates when debugging is enabled.

197 |

You can test this by enabling the namespace ReactUpdateHelper in debug.

198 |

Or you can just enable all namespaces with *.

199 |

In the browser you can do that as follows:

200 |
// Just enabling react-update-helper messages
201 | window.localStorage.debug = 'ReactUpdateHelper';
202 | 
203 | // Enabling all debug-powered logs
204 | window.localStorage.debug = '*';
205 | 
206 |

See more about debug in their repository page.

207 |

Quick Tip: When debugging Immutable objects use a custom formatter in the console

208 |

This custom formatter for Chrome Dev Tools makes Immutable object debugging a breeze. It works perfectly with react-update-helper!

209 |

No debug in production

210 |

As with React warnings, you should disable logs when running in a production environment.

211 |

Just make sure you are conditionally using withDebugInfo with an environment variable of sorts (like setting NODE_ENV to production) and performing dead code elimination.

212 |

The concerns are the same as if you were building React for production usage in the first place.

213 |

If you use Webpack, here is a nice guide.

214 |

Whole documentation

215 |

See the whole docs in the docs folder of this repo or directly online.

216 |

Compatibility

217 |

Compatibility with React, Immutable and debug have been tested and should be maintained.

218 |

Though not tested, it should work with react-native since it does not mess with DOM and browser specific APIs.

219 |

It can theorically work with preact when using preact-compat since it mimics React's API and lifecycle.

220 |

Contributing

221 |

This project is welcoming contributions of any kind!

222 |

Please, before filing issues or sending PRs, read the CONTRIBUTING guide.

223 |

License

224 |

MIT

225 |
226 |
227 | 228 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-update-helper", 3 | "version": "2.0.0", 4 | "description": "Precise React re-renders with debug and immutable support", 5 | "scripts": { 6 | "lint": "eslint karma.conf.js tests.webpack.js src __tests__", 7 | "test": "npm run lint && karma start karma.conf.js --single-run", 8 | "compile": "npm run lint && npm run test && babel src -d lib", 9 | "build": "npm run compile && npm run docs", 10 | "watch-test": "karma start karma.conf.js --auto-watch --no-single-run", 11 | "docs": "esdoc -c esdoc.json", 12 | "ci": "npm run test && coveralls < coverage/lcov.info", 13 | "prepublish": "npm run compile" 14 | }, 15 | "author": { 16 | "name": "Matheus Kautzmann", 17 | "email": "mkvchain@gmail.com" 18 | }, 19 | "license": "MIT", 20 | "keywords": [ 21 | "react", 22 | "reactjs", 23 | "react-helper", 24 | "react-update-helper", 25 | "shallow compare", 26 | "immutable", 27 | "debug" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/mkxml/react-update-helper" 32 | }, 33 | "bugs": { 34 | "url": "https://github.com/mkxml/react-update-helper/issues" 35 | }, 36 | "main": "lib/index.js", 37 | "devDependencies": { 38 | "babel-cli": "6.18.0", 39 | "babel-core": "6.21.0", 40 | "babel-eslint": "7.1.1", 41 | "babel-loader": "6.2.10", 42 | "babel-plugin-add-module-exports": "0.2.1", 43 | "babel-plugin-transform-class-properties": "6.19.0", 44 | "babel-plugin-transform-decorators-legacy": "1.3.4", 45 | "babel-plugin-transform-object-rest-spread": "6.20.2", 46 | "babel-preset-airbnb": "2.1.1", 47 | "babel-preset-es2015": "6.18.0", 48 | "babel-preset-react": "6.16.0", 49 | "chai": "3.5.0", 50 | "coveralls": "2.11.15", 51 | "debug": "2.6.0", 52 | "enzyme": "2.7.0", 53 | "esdoc": "0.4.8", 54 | "esdoc-es7-plugin": "0.0.3", 55 | "eslint": "3.13.0", 56 | "eslint-config-airbnb": "14.0.0", 57 | "eslint-config-airbnb-base": "^11.0.1", 58 | "eslint-plugin-import": "^2.0.1", 59 | "eslint-plugin-jsx-a11y": "3.0.2", 60 | "eslint-plugin-react": "6.9.0", 61 | "immutable": "3.8.1", 62 | "isparta-loader": "2.0.0", 63 | "karma": "1.3.0", 64 | "karma-chai": "0.1.0", 65 | "karma-coverage": "1.1.1", 66 | "karma-mocha": "1.3.0", 67 | "karma-mocha-reporter": "2.2.1", 68 | "karma-phantomjs-launcher": "1.0.2", 69 | "karma-sinon": "1.0.5", 70 | "karma-sourcemap-loader": "0.3.7", 71 | "karma-webpack": "1.8.1", 72 | "mocha": "3.2.0", 73 | "node-sass": "4.2.0", 74 | "phantomjs-prebuilt": "2.1.14", 75 | "react": "15.4.2", 76 | "react-addons-test-utils": "15.4.2", 77 | "react-dom": "15.4.2", 78 | "sinon": "1.17.7", 79 | "webpack": "1.14.0" 80 | }, 81 | "peerDependencies": { 82 | "react": ">=0.14.0", 83 | "immutable": ">=3.8.0", 84 | "debug": ">=2.2.0" 85 | }, 86 | "dependencies": { 87 | "lodash.keys": "4.2.0", 88 | "lodash.union": "4.6.0" 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /docs/script/inherited-summary.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | function toggle(ev) { 3 | var button = ev.target; 4 | var parent = ev.target.parentElement; 5 | while(parent) { 6 | if (parent.tagName === 'TABLE' && parent.classList.contains('summary')) break; 7 | parent = parent.parentElement; 8 | } 9 | 10 | if (!parent) return; 11 | 12 | var tbody = parent.querySelector('tbody'); 13 | if (button.classList.contains('opened')) { 14 | button.classList.remove('opened'); 15 | button.classList.add('closed'); 16 | tbody.style.display = 'none'; 17 | } else { 18 | button.classList.remove('closed'); 19 | button.classList.add('opened'); 20 | tbody.style.display = 'block'; 21 | } 22 | } 23 | 24 | var buttons = document.querySelectorAll('.inherited-summary thead .toggle'); 25 | for (var i = 0; i < buttons.length; i++) { 26 | buttons[i].addEventListener('click', toggle); 27 | } 28 | })(); 29 | -------------------------------------------------------------------------------- /docs/script/inner-link.js: -------------------------------------------------------------------------------- 1 | // inner link(#foo) can not correctly scroll, because page has fixed header, 2 | // so, I manually scroll. 3 | (function(){ 4 | var matched = location.hash.match(/errorLines=([\d,]+)/); 5 | if (matched) return; 6 | 7 | function adjust() { 8 | window.scrollBy(0, -55); 9 | var el = document.querySelector('.inner-link-active'); 10 | if (el) el.classList.remove('inner-link-active'); 11 | 12 | // ``[ ] . ' " @`` are not valid in DOM id. so must escape these. 13 | var id = location.hash.replace(/([\[\].'"@$])/g, '\\$1'); 14 | var el = document.querySelector(id); 15 | if (el) el.classList.add('inner-link-active'); 16 | } 17 | 18 | window.addEventListener('hashchange', adjust); 19 | 20 | if (location.hash) { 21 | setTimeout(adjust, 0); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | var els = document.querySelectorAll('[href^="#"]'); 27 | for (var i = 0; i < els.length; i++) { 28 | var el = els[i]; 29 | el.href = location.href + el.getAttribute('href'); // because el.href is absolute path 30 | } 31 | })(); 32 | -------------------------------------------------------------------------------- /docs/script/manual.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | var matched = location.pathname.match(/([^/]*)\.html$/); 3 | if (!matched) return; 4 | 5 | var currentName = matched[1]; 6 | var cssClass = '.navigation [data-toc-name="' + currentName + '"]'; 7 | var styleText = cssClass + ' .manual-toc { display: block; }\n'; 8 | styleText += cssClass + ' .manual-toc-title { background-color: #039BE5; }\n'; 9 | styleText += cssClass + ' .manual-toc-title a { color: white; }\n'; 10 | var style = document.createElement('style'); 11 | style.textContent = styleText; 12 | document.querySelector('head').appendChild(style); 13 | })(); 14 | -------------------------------------------------------------------------------- /docs/script/patch-for-local.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | if (location.protocol === 'file:') { 3 | var elms = document.querySelectorAll('a[href="./"]'); 4 | for (var i = 0; i < elms.length; i++) { 5 | elms[i].href = './index.html'; 6 | } 7 | } 8 | })(); 9 | -------------------------------------------------------------------------------- /docs/script/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/script/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p' + pair[2] + ''); 35 | } 36 | } 37 | 38 | var innerHTML = ''; 39 | for (kind in html) { 40 | var list = html[kind]; 41 | if (!list.length) continue; 42 | innerHTML += '
  • ' + kind + '
  • \n' + list.join('\n'); 43 | } 44 | result.innerHTML = innerHTML; 45 | if (innerHTML) result.style.display = 'block'; 46 | selectedIndex = -1; 47 | }); 48 | 49 | // down, up and enter key are pressed, select search result. 50 | input.addEventListener('keydown', function(ev){ 51 | if (ev.keyCode === 40) { 52 | // arrow down 53 | var current = result.children[selectedIndex]; 54 | var selected = result.children[selectedIndex + 1]; 55 | if (selected && selected.classList.contains('search-separator')) { 56 | var selected = result.children[selectedIndex + 2]; 57 | selectedIndex++; 58 | } 59 | 60 | if (selected) { 61 | if (current) current.classList.remove('selected'); 62 | selectedIndex++; 63 | selected.classList.add('selected'); 64 | } 65 | } else if (ev.keyCode === 38) { 66 | // arrow up 67 | var current = result.children[selectedIndex]; 68 | var selected = result.children[selectedIndex - 1]; 69 | if (selected && selected.classList.contains('search-separator')) { 70 | var selected = result.children[selectedIndex - 2]; 71 | selectedIndex--; 72 | } 73 | 74 | if (selected) { 75 | if (current) current.classList.remove('selected'); 76 | selectedIndex--; 77 | selected.classList.add('selected'); 78 | } 79 | } else if (ev.keyCode === 13) { 80 | // enter 81 | var current = result.children[selectedIndex]; 82 | if (current) { 83 | var link = current.querySelector('a'); 84 | if (link) location.href = link.href; 85 | } 86 | } else { 87 | return; 88 | } 89 | 90 | ev.preventDefault(); 91 | }); 92 | 93 | // select search result when search result is mouse over. 94 | result.addEventListener('mousemove', function(ev){ 95 | var current = result.children[selectedIndex]; 96 | if (current) current.classList.remove('selected'); 97 | 98 | var li = ev.target; 99 | while (li) { 100 | if (li.nodeName === 'LI') break; 101 | li = li.parentElement; 102 | } 103 | 104 | if (li) { 105 | selectedIndex = Array.prototype.indexOf.call(result.children, li); 106 | li.classList.add('selected'); 107 | } 108 | }); 109 | 110 | // clear search result when body is clicked. 111 | document.body.addEventListener('click', function(ev){ 112 | selectedIndex = -1; 113 | result.style.display = 'none'; 114 | result.innerHTML = ''; 115 | }); 116 | 117 | })(); 118 | -------------------------------------------------------------------------------- /docs/script/search_index.js: -------------------------------------------------------------------------------- 1 | window.esdocSearchIndex = [ 2 | [ 3 | "react-update-helper/src/util.js~getcomponentname", 4 | "function/index.html#static-function-getComponentName", 5 | "getComponentName react-update-helper/src/util.js", 6 | "function" 7 | ], 8 | [ 9 | "react-update-helper/src/debug.js~reportchanges", 10 | "function/index.html#static-function-reportChanges", 11 | "reportChanges react-update-helper/src/debug.js", 12 | "function" 13 | ], 14 | [ 15 | "react-update-helper/src/index.js~shouldupdate", 16 | "function/index.html#static-function-shouldUpdate", 17 | "shouldUpdate react-update-helper/src/index.js", 18 | "function" 19 | ], 20 | [ 21 | "react-update-helper/src/index.js~withdebuginfo", 22 | "function/index.html#static-function-withDebugInfo", 23 | "withDebugInfo react-update-helper/src/index.js", 24 | "function" 25 | ], 26 | [ 27 | "react-update-helper/src/index.js~withpurerender", 28 | "function/index.html#static-function-withPureRender", 29 | "withPureRender react-update-helper/src/index.js", 30 | "function" 31 | ], 32 | [ 33 | "builtinexternal/ecmascriptexternal.js~array", 34 | "external/index.html", 35 | "BuiltinExternal/ECMAScriptExternal.js~Array", 36 | "external" 37 | ], 38 | [ 39 | "builtinexternal/ecmascriptexternal.js~arraybuffer", 40 | "external/index.html", 41 | "BuiltinExternal/ECMAScriptExternal.js~ArrayBuffer", 42 | "external" 43 | ], 44 | [ 45 | "builtinexternal/ecmascriptexternal.js~boolean", 46 | "external/index.html", 47 | "BuiltinExternal/ECMAScriptExternal.js~Boolean", 48 | "external" 49 | ], 50 | [ 51 | "builtinexternal/ecmascriptexternal.js~dataview", 52 | "external/index.html", 53 | "BuiltinExternal/ECMAScriptExternal.js~DataView", 54 | "external" 55 | ], 56 | [ 57 | "builtinexternal/ecmascriptexternal.js~date", 58 | "external/index.html", 59 | "BuiltinExternal/ECMAScriptExternal.js~Date", 60 | "external" 61 | ], 62 | [ 63 | "builtinexternal/ecmascriptexternal.js~error", 64 | "external/index.html", 65 | "BuiltinExternal/ECMAScriptExternal.js~Error", 66 | "external" 67 | ], 68 | [ 69 | "builtinexternal/ecmascriptexternal.js~evalerror", 70 | "external/index.html", 71 | "BuiltinExternal/ECMAScriptExternal.js~EvalError", 72 | "external" 73 | ], 74 | [ 75 | "builtinexternal/ecmascriptexternal.js~float32array", 76 | "external/index.html", 77 | "BuiltinExternal/ECMAScriptExternal.js~Float32Array", 78 | "external" 79 | ], 80 | [ 81 | "builtinexternal/ecmascriptexternal.js~float64array", 82 | "external/index.html", 83 | "BuiltinExternal/ECMAScriptExternal.js~Float64Array", 84 | "external" 85 | ], 86 | [ 87 | "builtinexternal/ecmascriptexternal.js~function", 88 | "external/index.html", 89 | "BuiltinExternal/ECMAScriptExternal.js~Function", 90 | "external" 91 | ], 92 | [ 93 | "builtinexternal/ecmascriptexternal.js~generator", 94 | "external/index.html", 95 | "BuiltinExternal/ECMAScriptExternal.js~Generator", 96 | "external" 97 | ], 98 | [ 99 | "builtinexternal/ecmascriptexternal.js~generatorfunction", 100 | "external/index.html", 101 | "BuiltinExternal/ECMAScriptExternal.js~GeneratorFunction", 102 | "external" 103 | ], 104 | [ 105 | "builtinexternal/ecmascriptexternal.js~infinity", 106 | "external/index.html", 107 | "BuiltinExternal/ECMAScriptExternal.js~Infinity", 108 | "external" 109 | ], 110 | [ 111 | "builtinexternal/ecmascriptexternal.js~int16array", 112 | "external/index.html", 113 | "BuiltinExternal/ECMAScriptExternal.js~Int16Array", 114 | "external" 115 | ], 116 | [ 117 | "builtinexternal/ecmascriptexternal.js~int32array", 118 | "external/index.html", 119 | "BuiltinExternal/ECMAScriptExternal.js~Int32Array", 120 | "external" 121 | ], 122 | [ 123 | "builtinexternal/ecmascriptexternal.js~int8array", 124 | "external/index.html", 125 | "BuiltinExternal/ECMAScriptExternal.js~Int8Array", 126 | "external" 127 | ], 128 | [ 129 | "builtinexternal/ecmascriptexternal.js~internalerror", 130 | "external/index.html", 131 | "BuiltinExternal/ECMAScriptExternal.js~InternalError", 132 | "external" 133 | ], 134 | [ 135 | "builtinexternal/ecmascriptexternal.js~json", 136 | "external/index.html", 137 | "BuiltinExternal/ECMAScriptExternal.js~JSON", 138 | "external" 139 | ], 140 | [ 141 | "builtinexternal/ecmascriptexternal.js~map", 142 | "external/index.html", 143 | "BuiltinExternal/ECMAScriptExternal.js~Map", 144 | "external" 145 | ], 146 | [ 147 | "builtinexternal/ecmascriptexternal.js~nan", 148 | "external/index.html", 149 | "BuiltinExternal/ECMAScriptExternal.js~NaN", 150 | "external" 151 | ], 152 | [ 153 | "builtinexternal/ecmascriptexternal.js~number", 154 | "external/index.html", 155 | "BuiltinExternal/ECMAScriptExternal.js~Number", 156 | "external" 157 | ], 158 | [ 159 | "builtinexternal/ecmascriptexternal.js~object", 160 | "external/index.html", 161 | "BuiltinExternal/ECMAScriptExternal.js~Object", 162 | "external" 163 | ], 164 | [ 165 | "builtinexternal/ecmascriptexternal.js~promise", 166 | "external/index.html", 167 | "BuiltinExternal/ECMAScriptExternal.js~Promise", 168 | "external" 169 | ], 170 | [ 171 | "builtinexternal/ecmascriptexternal.js~proxy", 172 | "external/index.html", 173 | "BuiltinExternal/ECMAScriptExternal.js~Proxy", 174 | "external" 175 | ], 176 | [ 177 | "builtinexternal/ecmascriptexternal.js~rangeerror", 178 | "external/index.html", 179 | "BuiltinExternal/ECMAScriptExternal.js~RangeError", 180 | "external" 181 | ], 182 | [ 183 | "builtinexternal/ecmascriptexternal.js~referenceerror", 184 | "external/index.html", 185 | "BuiltinExternal/ECMAScriptExternal.js~ReferenceError", 186 | "external" 187 | ], 188 | [ 189 | "builtinexternal/ecmascriptexternal.js~reflect", 190 | "external/index.html", 191 | "BuiltinExternal/ECMAScriptExternal.js~Reflect", 192 | "external" 193 | ], 194 | [ 195 | "builtinexternal/ecmascriptexternal.js~regexp", 196 | "external/index.html", 197 | "BuiltinExternal/ECMAScriptExternal.js~RegExp", 198 | "external" 199 | ], 200 | [ 201 | "builtinexternal/ecmascriptexternal.js~set", 202 | "external/index.html", 203 | "BuiltinExternal/ECMAScriptExternal.js~Set", 204 | "external" 205 | ], 206 | [ 207 | "builtinexternal/ecmascriptexternal.js~string", 208 | "external/index.html", 209 | "BuiltinExternal/ECMAScriptExternal.js~String", 210 | "external" 211 | ], 212 | [ 213 | "builtinexternal/ecmascriptexternal.js~symbol", 214 | "external/index.html", 215 | "BuiltinExternal/ECMAScriptExternal.js~Symbol", 216 | "external" 217 | ], 218 | [ 219 | "builtinexternal/ecmascriptexternal.js~syntaxerror", 220 | "external/index.html", 221 | "BuiltinExternal/ECMAScriptExternal.js~SyntaxError", 222 | "external" 223 | ], 224 | [ 225 | "builtinexternal/ecmascriptexternal.js~typeerror", 226 | "external/index.html", 227 | "BuiltinExternal/ECMAScriptExternal.js~TypeError", 228 | "external" 229 | ], 230 | [ 231 | "builtinexternal/ecmascriptexternal.js~urierror", 232 | "external/index.html", 233 | "BuiltinExternal/ECMAScriptExternal.js~URIError", 234 | "external" 235 | ], 236 | [ 237 | "builtinexternal/ecmascriptexternal.js~uint16array", 238 | "external/index.html", 239 | "BuiltinExternal/ECMAScriptExternal.js~Uint16Array", 240 | "external" 241 | ], 242 | [ 243 | "builtinexternal/ecmascriptexternal.js~uint32array", 244 | "external/index.html", 245 | "BuiltinExternal/ECMAScriptExternal.js~Uint32Array", 246 | "external" 247 | ], 248 | [ 249 | "builtinexternal/ecmascriptexternal.js~uint8array", 250 | "external/index.html", 251 | "BuiltinExternal/ECMAScriptExternal.js~Uint8Array", 252 | "external" 253 | ], 254 | [ 255 | "builtinexternal/ecmascriptexternal.js~uint8clampedarray", 256 | "external/index.html", 257 | "BuiltinExternal/ECMAScriptExternal.js~Uint8ClampedArray", 258 | "external" 259 | ], 260 | [ 261 | "builtinexternal/ecmascriptexternal.js~weakmap", 262 | "external/index.html", 263 | "BuiltinExternal/ECMAScriptExternal.js~WeakMap", 264 | "external" 265 | ], 266 | [ 267 | "builtinexternal/ecmascriptexternal.js~weakset", 268 | "external/index.html", 269 | "BuiltinExternal/ECMAScriptExternal.js~WeakSet", 270 | "external" 271 | ], 272 | [ 273 | "builtinexternal/ecmascriptexternal.js~boolean", 274 | "external/index.html", 275 | "BuiltinExternal/ECMAScriptExternal.js~boolean", 276 | "external" 277 | ], 278 | [ 279 | "builtinexternal/ecmascriptexternal.js~function", 280 | "external/index.html", 281 | "BuiltinExternal/ECMAScriptExternal.js~function", 282 | "external" 283 | ], 284 | [ 285 | "builtinexternal/ecmascriptexternal.js~null", 286 | "external/index.html", 287 | "BuiltinExternal/ECMAScriptExternal.js~null", 288 | "external" 289 | ], 290 | [ 291 | "builtinexternal/ecmascriptexternal.js~number", 292 | "external/index.html", 293 | "BuiltinExternal/ECMAScriptExternal.js~number", 294 | "external" 295 | ], 296 | [ 297 | "builtinexternal/ecmascriptexternal.js~object", 298 | "external/index.html", 299 | "BuiltinExternal/ECMAScriptExternal.js~object", 300 | "external" 301 | ], 302 | [ 303 | "builtinexternal/ecmascriptexternal.js~string", 304 | "external/index.html", 305 | "BuiltinExternal/ECMAScriptExternal.js~string", 306 | "external" 307 | ], 308 | [ 309 | "builtinexternal/ecmascriptexternal.js~undefined", 310 | "external/index.html", 311 | "BuiltinExternal/ECMAScriptExternal.js~undefined", 312 | "external" 313 | ], 314 | [ 315 | "builtinexternal/webapiexternal.js~audiocontext", 316 | "external/index.html", 317 | "BuiltinExternal/WebAPIExternal.js~AudioContext", 318 | "external" 319 | ], 320 | [ 321 | "builtinexternal/webapiexternal.js~canvasrenderingcontext2d", 322 | "external/index.html", 323 | "BuiltinExternal/WebAPIExternal.js~CanvasRenderingContext2D", 324 | "external" 325 | ], 326 | [ 327 | "builtinexternal/webapiexternal.js~documentfragment", 328 | "external/index.html", 329 | "BuiltinExternal/WebAPIExternal.js~DocumentFragment", 330 | "external" 331 | ], 332 | [ 333 | "builtinexternal/webapiexternal.js~element", 334 | "external/index.html", 335 | "BuiltinExternal/WebAPIExternal.js~Element", 336 | "external" 337 | ], 338 | [ 339 | "builtinexternal/webapiexternal.js~event", 340 | "external/index.html", 341 | "BuiltinExternal/WebAPIExternal.js~Event", 342 | "external" 343 | ], 344 | [ 345 | "builtinexternal/webapiexternal.js~node", 346 | "external/index.html", 347 | "BuiltinExternal/WebAPIExternal.js~Node", 348 | "external" 349 | ], 350 | [ 351 | "builtinexternal/webapiexternal.js~nodelist", 352 | "external/index.html", 353 | "BuiltinExternal/WebAPIExternal.js~NodeList", 354 | "external" 355 | ], 356 | [ 357 | "builtinexternal/webapiexternal.js~xmlhttprequest", 358 | "external/index.html", 359 | "BuiltinExternal/WebAPIExternal.js~XMLHttpRequest", 360 | "external" 361 | ], 362 | [ 363 | "src/debug.js", 364 | "file/src/debug.js.html", 365 | "src/debug.js", 366 | "file" 367 | ], 368 | [ 369 | "src/debug.js~change", 370 | "typedef/index.html#static-typedef-Change", 371 | "src/debug.js~Change", 372 | "typedef" 373 | ], 374 | [ 375 | "src/index.js", 376 | "file/src/index.js.html", 377 | "src/index.js", 378 | "file" 379 | ], 380 | [ 381 | "src/index.js~react.component", 382 | "external/index.html", 383 | "src/index.js~React.Component", 384 | "external" 385 | ], 386 | [ 387 | "src/util.js", 388 | "file/src/util.js.html", 389 | "src/util.js", 390 | "file" 391 | ] 392 | ] -------------------------------------------------------------------------------- /docs/script/test-summary.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | function toggle(ev) { 3 | var button = ev.target; 4 | var parent = ev.target.parentElement; 5 | while(parent) { 6 | if (parent.tagName === 'TR' && parent.classList.contains('test-describe')) break; 7 | parent = parent.parentElement; 8 | } 9 | 10 | if (!parent) return; 11 | 12 | var direction; 13 | if (button.classList.contains('opened')) { 14 | button.classList.remove('opened'); 15 | button.classList.add('closed'); 16 | direction = 'closed'; 17 | } else { 18 | button.classList.remove('closed'); 19 | button.classList.add('opened'); 20 | direction = 'opened'; 21 | } 22 | 23 | var targetDepth = parseInt(parent.dataset.testDepth, 10) + 1; 24 | var nextElement = parent.nextElementSibling; 25 | while (nextElement) { 26 | var depth = parseInt(nextElement.dataset.testDepth, 10); 27 | if (depth >= targetDepth) { 28 | if (direction === 'opened') { 29 | if (depth === targetDepth) nextElement.style.display = ''; 30 | } else if (direction === 'closed') { 31 | nextElement.style.display = 'none'; 32 | var innerButton = nextElement.querySelector('.toggle'); 33 | if (innerButton && innerButton.classList.contains('opened')) { 34 | innerButton.classList.remove('opened'); 35 | innerButton.classList.add('closed'); 36 | } 37 | } 38 | } else { 39 | break; 40 | } 41 | nextElement = nextElement.nextElementSibling; 42 | } 43 | } 44 | 45 | var buttons = document.querySelectorAll('.test-summary tr.test-describe .toggle'); 46 | for (var i = 0; i < buttons.length; i++) { 47 | buttons[i].addEventListener('click', toggle); 48 | } 49 | 50 | var topDescribes = document.querySelectorAll('.test-summary tr[data-test-depth="0"]'); 51 | for (var i = 0; i < topDescribes.length; i++) { 52 | topDescribes[i].style.display = ''; 53 | } 54 | })(); 55 | -------------------------------------------------------------------------------- /docs/source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Source | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
    17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
    31 | 32 | 45 | 46 |

    Source 5/5

    47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |
    FileIdentifierDocumentSizeLinesUpdated
    src/debug.jsreportChanges100 %1/12260 byte702017-01-02 16:10:39 (UTC)
    src/index.jsshouldUpdate 72 | withDebugInfo 73 | withPureRender100 %3/33195 byte1082017-01-02 16:10:39 (UTC)
    src/util.jsgetComponentName100 %1/1351 byte102017-01-02 16:10:39 (UTC)
    89 |
    90 | 91 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /docs/typedef/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Typedef | API Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
    17 | Home 18 | 19 | Reference 20 | Source 21 | 22 | Repository 23 | 30 |
    31 | 32 | 45 | 46 |

    Typedef

    47 |
    48 | 49 | 50 | 51 | 52 | 59 | 71 | 75 | 76 | 77 |
    Static Public Summary
    53 | public 54 | 55 | 56 | 57 | 58 | 60 |
    61 |

    62 | Change: Object 63 |

    64 |
    65 |
    66 | 67 | 68 | 69 |
    70 |
    72 | 73 | 74 |
    78 |
    79 |

    Static Public

    80 | 81 |
    82 |

    83 | public 84 | 85 | 86 | 87 | 88 | Change: Object 89 | 90 | 91 | 92 | source 93 | 94 |

    95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
    104 |

    Properties:

    105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 117 | 118 | 119 | 120 | 121 | 122 | 124 | 125 | 126 | 127 | 128 | 129 | 131 | 132 | 133 | 134 | 135 | 136 | 138 | 139 | 140 |
    NameTypeAttributeDescription
    componentstring

    the component name

    116 |
    typestring

    string containing either 'props' or 'state'

    123 |
    fromany

    the original value of the change

    130 |
    toany

    the new value of the change

    137 |
    141 |
    142 |
    143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 |
    159 |
    160 |
    161 | 162 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /esdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": "./src", 3 | "destination": "./docs", 4 | "plugins": [ 5 | { 6 | "name": "esdoc-es7-plugin" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | 3 | module.exports = function karma(config) { 4 | config.set({ 5 | browsers: ['PhantomJS'], 6 | frameworks: ['mocha', 'chai', 'sinon'], 7 | files: ['tests.webpack.js'], 8 | plugins: [ 9 | 'karma-phantomjs-launcher', 10 | 'karma-mocha', 11 | 'karma-chai', 12 | 'karma-sinon', 13 | 'karma-sourcemap-loader', 14 | 'karma-webpack', 15 | 'karma-coverage', 16 | 'karma-mocha-reporter' 17 | ], 18 | preprocessors: { 19 | 'tests.webpack.js': ['webpack', 'sourcemap'] 20 | }, 21 | reporters: ['mocha', 'coverage'], 22 | webpack: { 23 | devtool: 'inline-source-map', 24 | module: { 25 | preLoaders: [ 26 | { 27 | test: /\.js$/, 28 | exclude: /(__tests__|node_modules)\//, 29 | loader: 'isparta-loader' 30 | } 31 | ], 32 | loaders: [ 33 | { 34 | test: /\.js$/, 35 | loader: 'babel-loader', 36 | exclude: /(node_modules|lib)\// 37 | } 38 | ] 39 | }, 40 | externals: { 41 | cheerio: 'window', 42 | 'react/addons': true, 43 | 'react/lib/ReactContext': true, 44 | 'react/lib/ExecutionEnvironment': true 45 | }, 46 | plugins: [ 47 | new webpack.NormalModuleReplacementPlugin(/^debug$/g, '../__tests__/mocks/debug.js') 48 | ] 49 | }, 50 | webpackServer: { 51 | noInfo: true 52 | }, 53 | coverageReporter: { 54 | reporters: [ 55 | { 56 | type: 'lcovonly', 57 | dir: 'coverage/', 58 | subdir: '.', 59 | file: 'lcov.info' 60 | }, 61 | { 62 | type: 'text-summary' 63 | } 64 | ] 65 | } 66 | }); 67 | }; 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-update-helper", 3 | "version": "2.0.1", 4 | "description": "Precise React re-renders with debug and immutable support", 5 | "scripts": { 6 | "lint": "eslint karma.conf.js tests.webpack.js src __tests__", 7 | "test": "npm run lint && karma start karma.conf.js --single-run", 8 | "compile": "npm run lint && npm run test && babel src -d lib", 9 | "build": "npm run compile && npm run docs", 10 | "watch-test": "karma start karma.conf.js --auto-watch --no-single-run", 11 | "docs": "esdoc -c esdoc.json", 12 | "ci": "npm run test && coveralls < coverage/lcov.info", 13 | "prepublish": "npm run compile" 14 | }, 15 | "author": { 16 | "name": "Matheus Kautzmann", 17 | "email": "mkvchain@gmail.com" 18 | }, 19 | "license": "MIT", 20 | "keywords": [ 21 | "react", 22 | "reactjs", 23 | "react-helper", 24 | "react-update-helper", 25 | "shallow compare", 26 | "immutable", 27 | "debug" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/mkxml/react-update-helper" 32 | }, 33 | "bugs": { 34 | "url": "https://github.com/mkxml/react-update-helper/issues" 35 | }, 36 | "main": "lib/index.js", 37 | "devDependencies": { 38 | "babel-cli": "6.18.0", 39 | "babel-core": "6.21.0", 40 | "babel-eslint": "7.1.1", 41 | "babel-loader": "6.2.10", 42 | "babel-plugin-add-module-exports": "0.2.1", 43 | "babel-plugin-transform-class-properties": "6.19.0", 44 | "babel-plugin-transform-decorators-legacy": "1.3.4", 45 | "babel-plugin-transform-object-rest-spread": "6.20.2", 46 | "babel-preset-airbnb": "2.1.1", 47 | "babel-preset-es2015": "6.18.0", 48 | "babel-preset-react": "6.16.0", 49 | "chai": "3.5.0", 50 | "coveralls": "2.11.15", 51 | "debug": "2.6.0", 52 | "enzyme": "2.7.0", 53 | "esdoc": "0.4.8", 54 | "esdoc-es7-plugin": "0.0.3", 55 | "eslint": "3.13.0", 56 | "eslint-config-airbnb": "14.0.0", 57 | "eslint-config-airbnb-base": "^11.0.1", 58 | "eslint-plugin-import": "^2.0.1", 59 | "eslint-plugin-jsx-a11y": "3.0.2", 60 | "eslint-plugin-react": "6.9.0", 61 | "immutable": "3.8.1", 62 | "isparta-loader": "2.0.0", 63 | "karma": "1.3.0", 64 | "karma-chai": "0.1.0", 65 | "karma-coverage": "1.1.1", 66 | "karma-mocha": "1.3.0", 67 | "karma-mocha-reporter": "2.2.1", 68 | "karma-phantomjs-launcher": "1.0.2", 69 | "karma-sinon": "1.0.5", 70 | "karma-sourcemap-loader": "0.3.7", 71 | "karma-webpack": "1.8.1", 72 | "mocha": "3.2.0", 73 | "node-sass": "4.2.0", 74 | "phantomjs-prebuilt": "2.1.14", 75 | "react": "15.4.2", 76 | "react-addons-test-utils": "15.4.2", 77 | "react-dom": "15.4.2", 78 | "sinon": "1.17.7", 79 | "webpack": "1.14.0" 80 | }, 81 | "peerDependencies": { 82 | "react": ">=0.14.0", 83 | "immutable": ">=3.8.0", 84 | "debug": ">=2.2.0" 85 | }, 86 | "dependencies": { 87 | "lodash.keys": "4.2.0", 88 | "lodash.union": "4.6.0" 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "node": true 6 | }, 7 | "rules": { 8 | "global-require": "off", 9 | "import/prefer-default-export": "off", 10 | "react/jsx-filename-extension": "off", 11 | "react/no-multi-comp": "off" 12 | }, 13 | "extends": "airbnb", 14 | "plugins": [ 15 | "react" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/debug.js: -------------------------------------------------------------------------------- 1 | import debug from 'debug'; 2 | import { is } from 'immutable'; 3 | import union from 'lodash.union'; 4 | import keys from 'lodash.keys'; 5 | import { getComponentName } from './util'; 6 | 7 | /** 8 | * @typedef {Object} Change 9 | * @property {string} component the component name 10 | * @property {string} type string containing either 'props' or 'state' 11 | * @property {any} from the original value of the change 12 | * @property {any} to the new value of the change 13 | */ 14 | 15 | /** 16 | * The default log funcion to be used 17 | * @type {function} 18 | * @since 1.0.0 19 | */ 20 | const logFunc = debug('ReactUpdateHelper'); 21 | 22 | /** 23 | * Log and return the changes in a component as they occur to help with debugging 24 | * @protected 25 | * @param {object} context - the component context 26 | * @param {object} context.props - the component props object 27 | * @param {object} context.state - the component state object 28 | * @param {object} nProps - the next props in the update process 29 | * @param {object} nState - the next state in the update process 30 | * @param {function} log - the log function to use when logging changes 31 | * @return {Array} - the changes that took place 32 | * @since 1.0.0 33 | */ 34 | export function reportChanges(context, nProps, nState, log = logFunc) { 35 | const props = context.props || {}; 36 | const state = context.state || {}; 37 | const newProps = nProps || {}; 38 | const newState = nState || {}; 39 | const availableProps = union(keys(props), keys(newProps)); 40 | const stateKeys = union(keys(state), keys(newState)); 41 | const name = getComponentName(context); 42 | const changes = []; 43 | availableProps.forEach((key) => { 44 | const oldValue = props[key]; 45 | const newValue = newProps[key]; 46 | if (!is(oldValue, newValue)) { 47 | changes.push({ 48 | component: name, 49 | type: 'props', 50 | from: props[key], 51 | to: newProps[key], 52 | }); 53 | log('%s: changed prop %s from %o to %o', name, key, oldValue, newValue); 54 | } 55 | }); 56 | stateKeys.forEach((key) => { 57 | const oldValue = state[key]; 58 | const newValue = newState[key]; 59 | if (!is(oldValue, newValue)) { 60 | changes.push({ 61 | component: name, 62 | type: 'state', 63 | from: state[key], 64 | to: newState[key], 65 | }); 66 | log('%s: changed state key %s from %o to %o', name, key, oldValue, newValue); 67 | } 68 | }); 69 | return changes; 70 | } 71 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import keys from 'lodash.keys'; 3 | import { is } from 'immutable'; 4 | import { getComponentName } from './util'; 5 | 6 | /** 7 | * @external {React.Component} https://facebook.github.io/react/docs/component-api.html 8 | */ 9 | 10 | /** 11 | * Simply checks if a component update is needed 12 | * @public 13 | * @param {object} context - the component context, containing the current props and state values 14 | * @param {object} nProps - the next props in the update process 15 | * @param {object} nState - the next state in the update process 16 | * @return {boolean} - true if should update the component else false 17 | * @since 1.0.0 18 | */ 19 | export function shouldUpdate({ props, state }, nProps, nState) { 20 | const propsKeys = keys(props || {}); 21 | const stateKeys = keys(state || {}); 22 | const nPropsKeys = keys(nProps || {}); 23 | const nStateKeys = keys(nState || {}); 24 | if (propsKeys.length !== nPropsKeys.length || stateKeys.length !== nStateKeys.length) { 25 | return true; 26 | } 27 | for (let i = 0, l = propsKeys.length; i < l; i += 1) { 28 | const key = propsKeys[i]; 29 | if (!Object.prototype.hasOwnProperty.call(nProps, key)) { 30 | return true; 31 | } 32 | if (!is(props[key], nProps[key])) { 33 | return true; 34 | } 35 | } 36 | for (let i = 0, l = stateKeys.length; i < l; i += 1) { 37 | const key = stateKeys[i]; 38 | if (!Object.prototype.hasOwnProperty.call(nState, key)) { 39 | return true; 40 | } 41 | if (!is(state[key], nState[key])) { 42 | return true; 43 | } 44 | } 45 | return false; 46 | } 47 | 48 | /** 49 | * Enhances a component with change checks and console logs powered by debugjs 50 | * @public 51 | * @example 52 | * // Usage as a high order component 53 | * class MyComponent extends React.Component { 54 | * render() { return

    Hello World!

    ; } 55 | * } 56 | * withDebugInfo(MyComponent); // Your enhanced component 57 | * @param {React.Component} Component - the component to be enhanced 58 | * @return {React.Component} - the enhanced component 59 | * @since 2.0.0 60 | */ 61 | export function withDebugInfo(Component) { 62 | let debug; 63 | return class extends React.Component { 64 | static displayName = getComponentName(Component); 65 | 66 | static propTypes = Component.propTypes; 67 | 68 | shouldComponentUpdate(nextProps, nextState) { 69 | debug = debug || require('./debug'); 70 | debug.reportChanges(this, nextProps, nextState); 71 | return shouldUpdate(this, nextProps, nextState); 72 | } 73 | 74 | render() { 75 | return ; 76 | } 77 | }; 78 | } 79 | 80 | /** 81 | * Encapsulates the shouldUpdate logic as a high order function 82 | * @public 83 | * @example 84 | * // Usage as a high order component 85 | * class MyComponent extends React.Component { 86 | * render() { return

    Hello World!

    ; } 87 | * } 88 | * withPureRender(MyComponent); // Your enhanced component 89 | * @param {React.Component} PureComponent - the component to be enhanced 90 | * @return {React.Component} - the enhanced component 91 | * @since 1.0.0 92 | */ 93 | export function withPureRender(PureComponent) { 94 | return class extends React.Component { 95 | 96 | static displayName = getComponentName(PureComponent); 97 | 98 | static propTypes = PureComponent.propTypes; 99 | 100 | shouldComponentUpdate(nextProps, nextState) { 101 | return shouldUpdate(this, nextProps, nextState); 102 | } 103 | 104 | render() { 105 | return ; 106 | } 107 | }; 108 | } 109 | -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Get the name of the given React component 3 | * @protected 4 | * @param {object} ctx - the component context, containing the name, props and state values 5 | * @return {string} - the component name 6 | * @since 1.0.0 7 | */ 8 | export function getComponentName(ctx) { 9 | return ctx.constructor.displayName || ctx.displayName || ctx.name || ctx.constructor.name; 10 | } 11 | -------------------------------------------------------------------------------- /tests.webpack.js: -------------------------------------------------------------------------------- 1 | var context = require.context('./__tests__', true, /\.spec\.js$/); 2 | context.keys().forEach(context); 3 | --------------------------------------------------------------------------------