{"_id":"@asielick/knockout-projections","name":"@asielick/knockout-projections","dist-tags":{"latest":"1.1.0"},"versions":{"1.1.0":{"name":"@asielick/knockout-projections","version":"1.1.0","description":"Knockout.js observable arrays get smarter","main":"dist/knockout-projections.js","directories":{"test":"test"},"dependencies":{"knockout":"^3.0.0","jasmine-reporters":"~0.2.1"},"devDependencies":{"grunt":"~0.4.1","grunt-contrib-jshint":"~0.4.3","grunt-contrib-uglify":"~0.2.0","grunt-contrib-concat":"~0.3.0","grunt-contrib-watch":"~0.4.3","grunt-jasmine-node":"~0.1.0","grunt-string-replace":"~0.2.7"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":"","author":{"name":"Microsoft Corporation"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"gitHead":"2cc7e187d29c17d483c924d0d1e63906f5bba0d3","_id":"@asielick/knockout-projections@1.1.0","_nodeVersion":"16.15.1","_npmVersion":"9.4.0","dist":{"integrity":"sha512-58yOMWmj7cXzR+1zeXPFVRqlA2rKM0vYwANF1qgkrZX1k6zz2PCmBBYttJus94ACnS6OVgiO4lg3hIRYuq19ow==","shasum":"d3ba3ee5bbcfe22d902ae55e0d2bd297cd109266","tarball":"https://registry.npmjs.org/@asielick/knockout-projections/-/knockout-projections-1.1.0.tgz","fileCount":13,"unpackedSize":98594,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAlSVO4U7E/68mJvjJeqZzUM0Cxe0nYpu7+2Q8ADkdehAiBkl6f5iVZUKzI4TLCEoOtj6dxz+/TrFqyRBQrKMDR3gg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj97/tACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpaxg//QRJXBEHDy0y2ofaK9PUA6oGvJgmACQ+sLX8AW5lb8MOnFx4N\r\nJacbl7oQ9uEkBPUazWik3suTalwCInv1OVri7elgfYQJVGb9JTpcBfXLTG1t\r\nZsFfZ95wVyiEMzqvPca0E7KmitdaatvO3KI5kIO2EwQUm3ITAwIfyEx1jwKa\r\nlm4Bs7cYS/FNcfmK65QiMRxoQB5IeoRT+wzQ35uAC1HC8pGv7o1mTx65fgBY\r\n7v1ZzNjwjox7MW1BI2dMyYDTdUT9SLy3/JUf5FCa8Zh/dvAjFCF4rrc6lInX\r\n1mPKrqWkNhI9v4aKuvaKWUrfWAxDVS381ClCRnDEPdBsxmrn7SO7krSkR4At\r\nbAtZcXS1QaN4Ti/NoPqFqyMxdDEybYmwaqedpJFANclLnVH/Gwf3fJm86gVP\r\nRbmh8mdbIGwUxxMY1vzQZNU/C20YT5YkNjt8OyMVdaYaT35KvD2zTCmCiKzl\r\nH2WVEz8vVSlQfZIp0vrckDdK64r2TC3UtDA1T97Jgk0sMSeJgue7PnBGuFo1\r\nXRZMwZPcnKf2lOcpH2M+iliOoseQTsXS6OEzQ2AN3hKBqFsJ7LkhxsdP2bIb\r\nbHhBqXEKJisqWj/NR6r+3fcgloYhMU2WkZkT6AfBiTKjPTmWlKINCx29dWpA\r\n2HZ8CoBYiSMieFWO5cJm7SLSgmr6wGNeOgQ=\r\n=IhoD\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"asielick","email":"alex@techmilo.com"},"maintainers":[{"name":"asielick","email":"alex@techmilo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/knockout-projections_1.1.0_1677180909278_0.9223679142245382"},"_hasShrinkwrap":false}},"time":{"created":"2023-02-23T19:35:09.206Z","1.1.0":"2023-02-23T19:35:09.497Z","modified":"2023-02-23T19:35:09.635Z"},"maintainers":[{"name":"asielick","email":"alex@techmilo.com"}],"description":"Knockout.js observable arrays get smarter","author":{"name":"Microsoft Corporation"},"readme":"knockout-projections\r\n============\r\n\r\nKnockout.js observable arrays get smarter.\r\n\r\nThis plugin adds observable `map` and `filter` features to observable arrays, so you can transform collections in arbitrary ways and have the results automatically update whenever the underlying source data changes.\r\n\r\nInstallation\r\n============\r\n\r\nDownload a copy of `knockout-projections-x.y.z.js` from [the `dist` directory](https://github.com/SteveSanderson/knockout-projections/tree/master/dist) and reference it in your web application:\r\n\r\n    <script src='knockout-x.y.z.js'></script>              <!-- First reference KO itself -->\r\n    <script src='knockout-projections-x.y.z.js'></script>  <!-- Then reference knockout-projections -->\r\n\r\nBe sure to reference it *after* you reference Knockout itself, and of course replace `x.y.z` with the version number of the file you downloaded.\r\n\r\nUsage\r\n=====\r\n\r\n**Mapping**\r\n\r\nMore info to follow. For now, here's a simple example:\r\n\r\n    var sourceItems = ko.observableArray([1, 2, 3, 4, 5]);\r\n\r\nThere's a plain observable array. Now let's say we want to keep track of the squares of these values:\r\n\r\n    var squares = sourceItems.map(function(x) { return x*x; });\r\n   \r\nNow `squares` is an observable array containing `[1, 4, 9, 16, 25]`. Let's modify the source data:\r\n\r\n    sourceItems.push(6);\r\n    // 'squares' has automatically updated and now contains [1, 4, 9, 16, 25, 36]\r\n    \r\nThis works with any transformation of the source data, e.g.:\r\n\r\n    sourceItems.reverse();\r\n    // 'squares' now contains [36, 25, 16, 9, 4, 1]\r\n    \r\nThe key point of this library is that these transformations are done *efficiently*. Specifically, your callback\r\nfunction that performs the mapping is only called when strictly necessary (usually, that's only for newly-added\r\nitems). When you add new items to the source data, we *don't* need to re-map the existing ones. When you reorder\r\nthe source data, the output order is correspondingly changed *without* remapping anything.\r\n\r\nThis efficiency might not matter much if you're just squaring numbers, but when you are mapping complex nested\r\ngraphs of custom objects, it can be important to perform each mapping update with the minumum of work.\r\n\r\n**Filtering**\r\n\r\nAs well as `map`, this plugin also provides `filter`:\r\n\r\n    var evenSquares = squares.filter(function(x) { return x % 2 === 0; });\r\n    // evenSquares is now an observable containing [36, 16, 4]\r\n\r\n    sourceItems.push(9);\r\n    // This has no effect on evenSquares, because 9*9=81 is odd\r\n\r\n    sourceItems.push(10);\r\n    // evenSquares now contains [36, 16, 4, 100]\r\n\r\nAgain, your `filter` callbacks are only called when strictly necessary. Re-ordering or deleting source items don't\r\nrequire any refiltering - the output is simply updated to match. Only newly-added source items must be subjected\r\nto your `filter` callback.\r\n\r\n**Chaining**\r\n\r\nThe above code also demonstrates that you can chain together successive `map` and `filter` transformations.\r\n\r\nWhen the underlying data changes, the effects will ripple out through the chain of computed arrays with the\r\nminimum necessary invocation of your `map` and `filter` callbacks.\r\n\r\nHow to build from source\r\n========================\r\n\r\nFirst, install [NPM](https://npmjs.org/) if you don't already have it. It comes with Node.js.\r\n\r\nSecond, install Grunt globally, if you don't already have it:\r\n\r\n    npm install -g grunt-cli\r\n\r\nThird, use NPM to download all the dependencies for this module:\r\n\r\n    cd wherever_you_cloned_this_repo\r\n    npm install\r\n\r\nNow you can build the package (linting and running tests along the way):\r\n\r\n    grunt\r\n    \r\nOr you can just run the linting tool and tests:\r\n\r\n    grunt test\r\n    \r\nOr you can make Grunt watch for changes to the sources/specs and auto-rebuild after each change:\r\n    \r\n    grunt watch\r\n    \r\nThe browser-ready output files will be dumped at the following locations:\r\n\r\n * `dist/knockout-projections.js`\r\n * `dist/knockout-projections.min.js`\r\n\r\nLicense - Apache 2.0\r\n====================\r\n\r\nCopyright (c) Microsoft Corporation\r\n\r\nAll rights reserved.\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 \r\n\r\nTHIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions and limitations under the License.\r\n","readmeFilename":"README.md"}