{"name":"react-addons-update","version":"15.0.2","main":"index.js","repository":{"type":"git","url":"git+https://github.com/facebook/react.git"},"keywords":["react","react-addon"],"license":"BSD-3-Clause","dependencies":{},"peerDependencies":{"react":"^15.0.2"},"description":"This package provides the React updates add-on.","bugs":{"url":"https://github.com/facebook/react/issues"},"homepage":"https://github.com/facebook/react#readme","_id":"react-addons-update@15.0.2","_shasum":"3652a03004a2f65e8449206884d9d10aa75b16ff","_resolved":"file:build/packages/react-addons-update.tgz","_from":"build/packages/react-addons-update.tgz","scripts":{},"_npmVersion":"2.15.1","_nodeVersion":"4.4.3","_npmUser":{"name":"zpao","email":"paul@oshannessy.com"},"maintainers":[{"name":"gaearon","email":"dan.abramov@gmail.com"},{"name":"graue","email":"scott@oceanbase.org"},{"name":"sebmarkbage","email":"sebastian@calyptus.eu"},{"name":"spicyj","email":"ben@benalpert.com"},{"name":"zpao","email":"paul@oshannessy.com"}],"dist":{"shasum":"3652a03004a2f65e8449206884d9d10aa75b16ff","tarball":"http://registry-npm.ywwl.com/react-addons-update/download/react-addons-update-15.0.2.tgz","integrity":"sha512-WaAxwLTgAz6zQqWxfJqVARwhEf3orF3Q9nWDoScBrC/tuS2QSoY3gVnVeNEArtTM7IN9TkLQocGhNIdHtMZg2g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjYTJhb8AcL6AZ2STE57xRj7kzn4ooKrdSEKRi8e1E9AIhAJ2jG7nfAgZ8KLFf4KewFvq/l+Q6CXsFN9VD/e57RlRy"}],"size":2710,"noattachment":false,"key":"/react-addons-update/-/react-addons-update-15.0.2.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/react-addons-update-15.0.2.tgz_1461976696477_0.04183909064158797"},"directories":{},"readme":"# react-addons-update\n\n>**Note:**\n>This is a legacy React addon, and is no longer maintained.\n>\n>We don't encourage using it in new code, but it exists for backwards compatibility.  \n>The recommended migration path is to use [`immutability-helper`](https://github.com/kolodny/immutability-helper). Its version `1.0.0` is a drop-in replacement.\n\n**Importing**\n\n```javascript\nimport update from 'react-addons-update'; // ES6\nvar update = require('react-addons-update'); // ES5 with npm\n```\n\nIf you prefer a `<script>` tag, you can get it from `React.addons.update` with:\n\n```html\n<!-- development version -->\n<script src=\"https://unpkg.com/react-addons-update/react-addons-update.js\"></script>\n\n<!-- production version -->\n<script src=\"https://unpkg.com/react-addons-update/react-addons-update.min.js\"></script>\n```\n\nIn this case, make sure to put the `<script>` tag after React.\n\n## Overview\n\nReact lets you use whatever style of data management you want, including mutation. However, if you can use immutable data in performance-critical parts of your application it's easy to implement a fast [`shouldComponentUpdate()`](https://facebook.github.io/react/docs/react-component.html#shouldcomponentupdate) method to significantly speed up your app.\n\nDealing with immutable data in JavaScript is more difficult than in languages designed for it, like [Clojure](http://clojure.org/). However, we've provided a simple immutability helper, `update()`, that makes dealing with this type of data much easier, *without* fundamentally changing how your data is represented. You can also take a look at Facebook's [Immutable-js](https://facebook.github.io/immutable-js/docs/) and the [Optimizing Performance](https://facebook.github.io/react/docs/optimizing-performance.html) section for more detail on Immutable-js.\n\n### The Main Idea\n\nIf you mutate data like this:\n\n```js\nmyData.x.y.z = 7;\n// or...\nmyData.a.b.push(9);\n```\n\nYou have no way of determining which data has changed since the previous copy has been overwritten. Instead, you need to create a new copy of `myData` and change only the parts of it that need to be changed. Then you can compare the old copy of `myData` with the new one in `shouldComponentUpdate()` using triple-equals:\n\n```js\nconst newData = deepCopy(myData);\nnewData.x.y.z = 7;\nnewData.a.b.push(9);\n```\n\nUnfortunately, deep copies are expensive, and sometimes impossible. You can alleviate this by only copying objects that need to be changed and by reusing the objects that haven't changed. Unfortunately, in today's JavaScript this can be cumbersome:\n\n```js\nconst newData = extend(myData, {\n  x: extend(myData.x, {\n    y: extend(myData.x.y, {z: 7}),\n  }),\n  a: extend(myData.a, {b: myData.a.b.concat(9)})\n});\n```\n\nWhile this is fairly performant (since it only makes a shallow copy of `log n` objects and reuses the rest), it's a big pain to write. Look at all the repetition! This is not only annoying, but also provides a large surface area for bugs.\n\n## `update()`\n\n`update()` provides simple syntactic sugar around this pattern to make writing this code easier. This code becomes:\n\n```js\nimport update from 'react-addons-update';\n\nconst newData = update(myData, {\n  x: {y: {z: {$set: 7}}},\n  a: {b: {$push: [9]}}\n});\n```\n\nWhile the syntax takes a little getting used to (though it's inspired by [MongoDB's query language](http://docs.mongodb.org/manual/core/crud-introduction/#query)) there's no redundancy, it's statically analyzable and it's not much more typing than the mutative version.\n\nThe `$`-prefixed keys are called *commands*. The data structure they are \"mutating\" is called the *target*.\n\n## Available Commands\n\n  * `{$push: array}` `push()` all the items in `array` on the target.\n  * `{$unshift: array}` `unshift()` all the items in `array` on the target.\n  * `{$splice: array of arrays}` for each item in `arrays` call `splice()` on the target with the parameters provided by the item.\n  * `{$set: any}` replace the target entirely.\n  * `{$merge: object}` merge the keys of `object` with the target.\n  * `{$apply: function}` passes in the current value to the function and updates it with the new returned value.\n\n## Examples\n\n### Simple push\n\n```js\nconst initialArray = [1, 2, 3];\nconst newArray = update(initialArray, {$push: [4]}); // => [1, 2, 3, 4]\n```\n`initialArray` is still `[1, 2, 3]`.\n\n### Nested collections\n\n```js\nconst collection = [1, 2, {a: [12, 17, 15]}];\nconst newCollection = update(collection, {2: {a: {$splice: [[1, 1, 13, 14]]}}});\n// => [1, 2, {a: [12, 13, 14, 15]}]\n```\nThis accesses `collection`'s index `2`, key `a`, and does a splice of one item starting from index `1` (to remove `17`) while inserting `13` and `14`.\n\n### Updating a value based on its current one\n\n```js\nconst obj = {a: 5, b: 3};\nconst newObj = update(obj, {b: {$apply: function(x) {return x * 2;}}});\n// => {a: 5, b: 6}\n// This is equivalent, but gets verbose for deeply nested collections:\nconst newObj2 = update(obj, {b: {$set: obj.b * 2}});\n```\n\n### (Shallow) Merge\n\n```js\nconst obj = {a: 5, b: 3};\nconst newObj = update(obj, {$merge: {b: 6, c: 7}}); // => {a: 5, b: 6, c: 7}\n```\n","publish_time":1461976698472,"_cnpm_publish_time":1461976698472,"dist-tags":{"15-next":"15.6.0-rc.0","dev":"15.5.0-rc.2","latest":"15.6.3"}}