{"_id":"@accurat/event-utils","_rev":"20-ffb747d78586c90abe67808b00e97ca4","name":"@accurat/event-utils","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@accurat/event-utils","version":"1.0.0","keywords":["event","utils","react","jsx"],"author":{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},"license":"MIT","_id":"@accurat/event-utils@1.0.0","maintainers":[{"name":"arrayout","email":"arrayout@gmail.com"},{"name":"caesarsol","email":"smilemachine@gmail.com"},{"name":"lucafalasco","email":"falasco.luca@gmail.com"},{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},{"name":"markov00","email":"vettorello.marco@gmail.com"},{"name":"nkint","email":"nootropic.kint@gmail.com"},{"name":"yeasteregg","email":"l.d.mattiazzi@gmail.com"}],"contributors":[{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},{"url":"https://github.com/lucafalasco","name":"Luca Falasco","email":"falasco.luca@gmail.com"},{"url":"https://github.com/caesarsol","name":"Cesare Soldini","email":"cesare.soldini@gmail.com"},{"url":"https://github.com/markov00","name":"Marco Vettorello","email":"marco.vettorello@accurat.it"},{"url":"https://github.com/nkint","name":"nkint","email":"alberto.massa@accurat.it"},{"url":"https://github.com/YeasterEgg","name":"YeasterEgg","email":"l.d.mattiazzi@gmail.com"},{"url":"https://github.com/GabrieleLippi","name":"GabrieleLippi","email":"gabriele.lippi@accurat.it"}],"homepage":"https://github.com/accurat/event-utils#readme","bugs":{"url":"https://github.com/accurat/event-utils/issues"},"dist":{"shasum":"f30110df37070e757b6205870d5d4a1bfd0d4b09","tarball":"https://registry.npmjs.org/@accurat/event-utils/-/event-utils-1.0.0.tgz","fileCount":4,"integrity":"sha512-hLCJoTW4Q2XzlBYFlix52Mp5OZiJwytw5Au8814EUhgpgUAs4l0/qhRyNa/Cpp2qmEWtRPq/qW8AAyrrC/iIkQ==","signatures":[{"sig":"MEQCIHRQ7A7PJ4UZILkDEwPs7CEtar0h5mqunfRZ8jFWXmzbAiARiDqZMRKYL2Ee9I4b2iXecGbm97sPZ+JhkPyyJDiCuQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5088,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa41nSCRA9TVsSAnZWagAApVcP/3gisXa4WwCYVYLSx2ZI\nXVz+xVl/b5xRpXULycRbqY0PDMVyk//a4c8hXIToj2vUiRBb2S7NxYo6Kwse\nhJoaoPTp3vaGwC0OulJyokPpvUd7uPLn/SeSR+fB6pRAts8qiYAwh3P/5GGN\nOYynBMBHJSWdVD6vREvuVGGlzNPPquE+jNF5hOwaOZPv1WWVorTHSTG9xHtU\nJwpYs1NyE1PnuaL5dhfLJ90vHhU8nYnJZQ3ETvZVrlDRV/xbeEF1wmRDhFcd\nZz1OZYnelnDWjlDRK8D7BvfsJKYu86Rcc8n4eux4KK7kzDFeShnWmXW2pQaZ\nqt5OQw1vZxkwXOKEol/e2GBD92y4AboojHl9OejxMlatple6dz4UcEbly3JK\n02IPsVNayof2qlb+q/acLxwTNfqw4PoZmIRuSygZ/bldh0Bz7ASh0klAxZ9k\n4fU1QecCmRUGEdff2yzq18ST1nbUmkcgahPewkQN2cLEtc1bOytT4N4K6jak\nq3wzs6D9L66YDbfzH77doeL+kuds5Wd40uNuuSCSFW+wPv0zTjO+ZkU20IMJ\nABa3i09c6EV6hkzVnrVIS5l99KnMYl3I8oH41r8gyg74CX7mcRqB4/6KpM+U\nKs5gsLQENrCCX99BUPXXm9xFjFdHaAyf31ljHFhuVOueJVVl1pxRwESIDq8F\n13fQ\r\n=eA3B\r\n-----END PGP SIGNATURE-----\r\n"},"files":["index.js"],"engines":{"node":">=6"},"gitHead":"dce11bdcbe4e939165c1dd11ede55de8c1ad505b","private":false,"_npmUser":{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},"repository":{"url":"git+https://github.com/accurat/event-utils.git","type":"git"},"_npmVersion":"5.6.0","description":"High order functions to use in React's JSX when working with events","directories":{},"sideEffects":false,"_nodeVersion":"9.6.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/event-utils_1.0.0_1524849105736_0.8771488713584785","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@accurat/event-utils","version":"1.0.1","keywords":["event","utils","react","jsx"],"author":{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},"license":"MIT","_id":"@accurat/event-utils@1.0.1","maintainers":[{"name":"arrayout","email":"arrayout@gmail.com"},{"name":"caesarsol","email":"smilemachine@gmail.com"},{"name":"lucafalasco","email":"falasco.luca@gmail.com"},{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},{"name":"markov00","email":"vettorello.marco@gmail.com"},{"name":"nkint","email":"nootropic.kint@gmail.com"},{"name":"yeasteregg","email":"l.d.mattiazzi@gmail.com"}],"contributors":[{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},{"url":"https://github.com/lucafalasco","name":"Luca Falasco","email":"falasco.luca@gmail.com"},{"url":"https://github.com/caesarsol","name":"Cesare Soldini","email":"cesare.soldini@gmail.com"},{"url":"https://github.com/markov00","name":"Marco Vettorello","email":"marco.vettorello@accurat.it"},{"url":"https://github.com/nkint","name":"nkint","email":"alberto.massa@accurat.it"},{"url":"https://github.com/YeasterEgg","name":"YeasterEgg","email":"l.d.mattiazzi@gmail.com"},{"url":"https://github.com/GabrieleLippi","name":"GabrieleLippi","email":"gabriele.lippi@accurat.it"}],"dist":{"shasum":"de4fd110d84f3b0f10d4e5c463537a9326abd702","tarball":"https://registry.npmjs.org/@accurat/event-utils/-/event-utils-1.0.1.tgz","fileCount":5,"integrity":"sha512-Y7pfoZNSoCdjGlZbYvbxtQ/CDmOkQjiGIagym95asBqR+zisxj3vl7hJfnuDvwjbXc+DDeagyiDf4cLEpHmmug==","signatures":[{"sig":"MEUCIQCo5+ATSXx9HbE7fFwQ/6XLcrZPtdlOPSqmoFzf5JiCgwIgBfMAGUsNvUsALsCC65DM4E2pS4esCpewoOiBbUOOaAY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5221,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa5uYZCRA9TVsSAnZWagAA/+EP/0NoRWycyu/1KAx94iMO\n6y88mYbzt83qPPNeI/ms6oMkRW6lCckI18eBH8qgAEFAOZp0GRlL+5CDLJiM\nrAdV/UL6AjzNM/JTWGflGIllKIfm0W04JY04GSUGavc/tf9ySFy6i3zWZeMN\n6kjpH+DeKVVlOlW60EHLhiHKIRnhu0seJUBIcjhnnDHYHFbifxiiJCaypDOA\nEx73KecpgAn0nunpP5WhcEE9kG8WdgJaRpzeZM7sqriWece+gjybeU/loxhz\nTrw+97dc1q/UTnyzVRvKrG+0uL9lVcIPJixZ1uD0Ru2RvoJ9eG3BRoBqwVdY\nK2Sd6ozNKj5QalsCDriQRYjJk9ojPftnLjaeirZGBCXR9unaCMZyAJmJxfrx\ngKFsX94aN2OdJaL4kuxbq0k0GD9FBrwKQ+B/BPFlzpeGffwEf/TaKft+4LtH\nC1QNcBWcvjlat4pNdxH1I8AZ67XUTNHD2HP736JGaDwb2fZl6zdNNI4YWR9K\ndEA9AFE+f9S4OagA/2P6sH0k9WMQN1SXHrJyC8EXnash/HZw43Po5h93j6y4\nvKXJUo/n7Pke0669pknowip0vo3Tjr5ny4613F9te+BCb7bR+Uxt7/oSPSc6\nSokyNij2uz/k5AhygAfs8G2wGb+SN+5DddA6A1BivMND0d1xDZABNUFT95cM\nF+Gt\r\n=VGz6\r\n-----END PGP SIGNATURE-----\r\n"},"files":["index.js"],"engines":{"node":">=6"},"_npmUser":{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},"repository":{"url":"https://github.com/accurat/event-utils.git","type":"git"},"description":"High order functions to use in React's JSX when working with events","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2018 Accurat Srl\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","sideEffects":false,"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/event-utils_1.0.1_1525081623730_0.23623456988278901","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@accurat/event-utils","version":"1.0.2","keywords":["event","utils","react","jsx"],"author":{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},"license":"MIT","_id":"@accurat/event-utils@1.0.2","maintainers":[{"name":"arrayout","email":"arrayout@gmail.com"},{"name":"caesarsol","email":"smilemachine@gmail.com"},{"name":"lucafalasco","email":"falasco.luca@gmail.com"},{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},{"name":"markov00","email":"vettorello.marco@gmail.com"},{"name":"nkint","email":"nootropic.kint@gmail.com"},{"name":"yeasteregg","email":"l.d.mattiazzi@gmail.com"}],"contributors":[{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},{"url":"https://github.com/lucafalasco","name":"Luca Falasco","email":"falasco.luca@gmail.com"},{"url":"https://github.com/caesarsol","name":"Cesare Soldini","email":"cesare.soldini@gmail.com"},{"url":"https://github.com/markov00","name":"Marco Vettorello","email":"marco.vettorello@accurat.it"},{"url":"https://github.com/nkint","name":"nkint","email":"alberto.massa@accurat.it"},{"url":"https://github.com/YeasterEgg","name":"YeasterEgg","email":"l.d.mattiazzi@gmail.com"},{"url":"https://github.com/GabrieleLippi","name":"GabrieleLippi","email":"gabriele.lippi@accurat.it"}],"dist":{"shasum":"492ef10e67ff89f2664f55e3ae7f88f166d1b10b","tarball":"https://registry.npmjs.org/@accurat/event-utils/-/event-utils-1.0.2.tgz","fileCount":5,"integrity":"sha512-mO2uBynDiy2B3CoLSRiTJHYi6Tp1JzyDw35awfWsLJlpvArtINv6XBXVPgRAz9nZ79WIc+diUjx5LWeg3Dchzw==","signatures":[{"sig":"MEQCIC1QB4iPzZTW6FfPh+oF4z70kAJHXly3Kz+hWz2+Vfr1AiBKJm+lkn1KoULyiiKx4dqy3N81n7JzC40yJRB2wrAVuA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5872,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa9BnyCRA9TVsSAnZWagAAkjsQAJF6yegMClJgI2lINneV\nVfZlH52F8aUXliTWZDZVATdFsbw5iLcRln51SBv+mW+OLtieX8Yl6Awx4Evh\nRSQo3uDy6bBbWIFAt2wP/9c0b7yXpB3+sevkaQY5uqBM79gRLasKJThhEChu\nag+Y1+chdsldDiAZqnQGwKWoadGik5VbUYnifkLzzPQXV3/qbJ0N1SPOSFF/\n5rlUgv9rx+bcQLMQC5C96BLlNKfTjszzaqTI5PG2wT5HK+K99LEF+RreskPD\nP/2eXi1ta8+QHq1lpOPHc4NGST8p+N+JI6A7DgLhbwJ/TgFtMMeHsXjOYZgd\nBmu8pO4cq1mEgW0ZvKCC2itlzxGIAxwLEv56kUzmHP0FRoeKBXOHzvaEIRfm\ns96PxORxAcRnWDD0bFfOQYhN0d7PodL7/RXDOWHAh4Pgdmfh2U+3nKeooj+l\nwHgQRPG7Zu5a09XJdZh8LhsZf8asCykVtS7j8Zpc7uEuAtnnRQ4xC9lnsEIf\nZ6bR+pn5vr0xZehwwPiEdn88dKDCLBWC4UL+ns/795axB3xeEeO7cCLuV2L6\nxGxyl3Km5O06d5dIi+duZBsiERt11LOl8gEbL1ZSJVhTCzJde59iQirUCSN/\nIB8k9VXH65GL+ZHuKeryargLOa6AEmqvIZNVLFT85ab7PBWo+N3Iu4jscKDy\nfRv2\r\n=JEEu\r\n-----END PGP SIGNATURE-----\r\n"},"files":["index.js"],"engines":{"node":">=6"},"_npmUser":{"name":"marcofugaro","email":"marco.fugaro@gmail.com"},"repository":{"url":"https://github.com/accurat/event-utils.git","type":"git"},"description":"High order functions to use in React's JSX when working with events","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2018 Accurat Srl\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","sideEffects":false,"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/event-utils_1.0.2_1525946865762_0.5804495713570308","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-04-27T17:11:45.663Z","modified":"2024-12-27T21:27:49.139Z","1.0.0":"2018-04-27T17:11:45.862Z","1.0.1":"2018-04-30T09:47:04.707Z","1.0.2":"2018-05-10T10:07:45.951Z"},"author":{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},"license":"MIT","keywords":["event","utils","react","jsx"],"repository":{"url":"https://github.com/accurat/event-utils.git","type":"git"},"description":"High order functions to use in React's JSX when working with events","contributors":[{"url":"https://github.com/marcofugaro","name":"Marco Fugaro","email":"marco.fugaro@gmail.com"},{"url":"https://github.com/lucafalasco","name":"Luca Falasco","email":"falasco.luca@gmail.com"},{"url":"https://github.com/caesarsol","name":"Cesare Soldini","email":"cesare.soldini@gmail.com"},{"url":"https://github.com/markov00","name":"Marco Vettorello","email":"marco.vettorello@accurat.it"},{"url":"https://github.com/nkint","name":"nkint","email":"alberto.massa@accurat.it"},{"url":"https://github.com/YeasterEgg","name":"YeasterEgg","email":"l.d.mattiazzi@gmail.com"},{"url":"https://github.com/GabrieleLippi","name":"GabrieleLippi","email":"gabriele.lippi@accurat.it"}],"maintainers":[{"email":"sgabenza86@gmail.com","name":"sgabenza"},{"email":"smilemachine@gmail.com","name":"caesarsol"},{"email":"arrayout@gmail.com","name":"arrayout"},{"email":"venturini.ila@gmail.com","name":"ilav"},{"email":"ivanross.me@gmail.com","name":"ivanross"},{"email":"vito.latrofa@accurat.it","name":"pi7oux"}],"readme":"# @accurat/event-utils\n\n> High order functions to use in React's JSX when working with events\n\nThe objective of these functions is to reduce the boilerplate code when handling events in react, and to wire up the pure state setters directly to the component.\n\n\n## Install\n\n```\nyarn add @accurat/event-utils\n```\n\n\n## Usage\n\nGiven a basic and functional state setter in react\n```js\nsetName = (name) => {\n  this.setState({ name })\n}\n```\n\nor the equivalent in mobx-state-tree\n```js\nsetName(name) {\n  self.name = name\n}\n```\n\nwith `@accurat/event-utils` you can use the setter directly on the JSX component:\n\n\n```js\nimport { eventValueExtractor } from '@accurat/event-utils'\n\n// ...\n\n<input value={name} onChange={eventValueExtractor(setName)} />\n```\n\nAnother common use case is with links and custom routing:\n\n```js\nimport { preventingDefault } from '@accurat/event-utils'\n\n// ...\n\n<a href={href} onClick={preventingDefault(gotoPage)} />\n```\n\nAlso those functions use the powers of **functional programming** 🌪, so you can combine them!\n\n```js\nimport { preventingDefault, replaceArguments } from '@accurat/event-utils'\n\n// ...\n\n<div>\n  {options.map((option, i) =>\n    <a\n      href=\"\"\n      key={i}\n      onClick={preventingDefault(replaceArguments(setName, option))}\n    >\n      {option}\n    </a>\n  )}\n</div>\n```\n\nThis way you don't have to use anymore the **build pattern** in react, and you can get rid of all those boilerplate methods in the component!\n\nAnother thing you can get rid of is the `onKeyDown` method with the switch case inside that fires a function on a certain `event.key`, you can use an object association instead:\n\n```js\nimport { attachListenersToKeys } from '@accurat/event-utils'\n\n// ...\n\n<input\n  type=\"text\"\n  onKeyDown={attachListenersToKeys({\n    Enter: preventingDefault(state.commit),\n    ArrowDown: state.selectNext,\n    ArrowUp: state.selectPrev,\n  })}\n/>\n```\n\n## API\n\nThe available functions are:\n- **preventingDefault(fn)**\n- **stoppingPropagation(fn)**\n- **eventValueExtractor(fn)**\n- **eventTargetExtractor(fn)**\n- **addArguments(fn, ...args)**\n- **replaceArguments(fn, ...args)** (similar to `lodash.partial`)\n\nIf the names aren't self-explanatory enough, you can check out [the source code](https://github.com/accurat/event-utils/blob/master/index.js), the functions are really simple and straightforward.\n\n\n_Note that react also supports passing `null` to the event binding other than a function, so you will be also able to do_\n```js\n<a href=\"\" onClick={preventingDefault(this.props.onClick)} />\n```\n_allowing the component to receive `null` as the `onClick` prop, thanks to the line_\n```js\nif (fn === null) return null\n```\n","readmeFilename":"README.md"}