{"_id":"disposables","_rev":"440884","name":"disposables","description":"Disposables let you safely compose resource disposal semantics","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"gaearon","email":""}],"time":{"modified":"2021-08-05T06:34:06.000Z","created":"2015-04-09T14:14:03.439Z","1.0.2":"2018-01-07T12:08:32.167Z","1.0.1":"2015-04-09T14:25:21.585Z","1.0.0":"2015-04-09T14:14:03.439Z"},"users":{"nelix":true},"author":{"name":"Cloud Programmability Team","url":"https://github.com/Reactive-Extensions/RxJS/blob/master/authors.txt"},"repository":{"type":"git","url":"git+https://github.com/gaearon/disposables.git"},"versions":{"1.0.2":{"name":"disposables","version":"1.0.2","description":"Disposables let you safely compose resource disposal semantics","main":"modules/index.js","files":["modules"],"scripts":{"build":"./scripts/build","test":"./scripts/test","test-cov":"./scripts/test-cov","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/gaearon/disposables.git"},"author":{"name":"Cloud Programmability Team","url":"https://github.com/Reactive-Extensions/RxJS/blob/master/authors.txt"},"contributors":[{"name":"Dan Abramov","email":"dan.abramov@me.com"}],"license":"Apache-2.0","bugs":{"url":"https://github.com/gaearon/disposables/issues"},"homepage":"https://github.com/gaearon/disposables","devDependencies":{"babel":"^5.0.10","expect.js":"^0.3.1","istanbul":"~0.3.7","mocha":"^2.0.1"},"gitHead":"32eda716678fae152c67d8347a95bab415d51224","_id":"disposables@1.0.2","_shasum":"36c6a674475f55a2d6913567a601444e487b4b6e","_from":".","_npmVersion":"3.10.10","_nodeVersion":"8.9.1","_npmUser":{"name":"gaearon","email":"dan.abramov@gmail.com"},"dist":{"shasum":"36c6a674475f55a2d6913567a601444e487b4b6e","size":5050,"noattachment":false,"key":"/disposables/-/disposables-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/disposables/download/disposables-1.0.2.tgz"},"maintainers":[{"name":"gaearon","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/disposables-1.0.2.tgz_1515326911284_0.2134415116161108"},"directories":{},"publish_time":1515326912167,"_hasShrinkwrap":false,"_cnpm_publish_time":1515326912167},"1.0.1":{"name":"disposables","version":"1.0.1","description":"Disposables let you safely compose resource disposal semantics","main":"modules/index.js","scripts":{"build":"./scripts/build","test":"./scripts/test","test-cov":"./scripts/test-cov","prepublish":"npm run build"},"repository":{"type":"git","url":"https://github.com/gaearon/disposables.git"},"author":{"name":"Cloud Programmability Team","url":"https://github.com/Reactive-Extensions/RxJS/blob/master/authors.txt"},"contributors":[{"name":"Dan Abramov","email":"dan.abramov@me.com"}],"licenses":[{"type":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"bugs":{"url":"https://github.com/gaearon/disposables/issues"},"homepage":"https://github.com/gaearon/disposables","devDependencies":{"babel":"^5.0.10","expect.js":"^0.3.1","istanbul":"~0.3.7","mocha":"^2.0.1"},"gitHead":"4db84f1de17015d908c9e4e47b01edc59f4ca04d","_id":"disposables@1.0.1","_shasum":"064727a25b54f502bd82b89aa2dfb8df9f1b39e3","_from":".","_npmVersion":"2.7.0","_nodeVersion":"1.5.1","_npmUser":{"name":"gaearon","email":"dan.abramov@gmail.com"},"maintainers":[{"name":"gaearon","email":""}],"dist":{"shasum":"064727a25b54f502bd82b89aa2dfb8df9f1b39e3","size":38633,"noattachment":false,"key":"/disposables/-/disposables-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/disposables/download/disposables-1.0.1.tgz"},"directories":{},"publish_time":1428589521585,"_cnpm_publish_time":1428589521585,"_hasShrinkwrap":false},"1.0.0":{"name":"disposables","version":"1.0.0","description":"Disposables let you safely compose resource disposal semantics","main":"dist-modules/index.js","scripts":{"build":"./scripts/build","test":"./scripts/test","test-cov":"./scripts/test-cov","prepublish":"npm run build"},"repository":{"type":"git","url":"https://github.com/gaearon/disposables.git"},"author":{"name":"Cloud Programmability Team","url":"https://github.com/Reactive-Extensions/RxJS/blob/master/authors.txt"},"licenses":[{"type":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"bugs":{"url":"https://github.com/gaearon/disposables/issues"},"homepage":"https://github.com/gaearon/disposables","devDependencies":{"babel":"^5.0.10","expect.js":"^0.3.1","istanbul":"~0.3.7","mocha":"^2.0.1"},"contributors":[{"name":"Matthew Podwysocki","email":"matthewp@microsoft.com"},{"name":"Bart de Smet","email":"bartde@microsoft.com"},{"name":"Erik Meijer","email":"emeijer@microsoft.com"},{"name":"Dan Abramov","email":"dan.abramov@me.com"}],"gitHead":"31497ef4de9f3eb28a40e0d9a7591d2991f81d81","_id":"disposables@1.0.0","_shasum":"d0b28e6e1ade8fa6f176c12577aadeea73946086","_from":".","_npmVersion":"2.7.0","_nodeVersion":"1.5.1","_npmUser":{"name":"gaearon","email":"dan.abramov@gmail.com"},"maintainers":[{"name":"gaearon","email":""}],"dist":{"shasum":"d0b28e6e1ade8fa6f176c12577aadeea73946086","size":25496,"noattachment":false,"key":"/disposables/-/disposables-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/disposables/download/disposables-1.0.0.tgz"},"directories":{},"publish_time":1428588843439,"_cnpm_publish_time":1428588843439,"_hasShrinkwrap":false}},"readme":"# NOT ACTIVELY MAINTAINED\n\n>**This project works fine but is not actively maintained.**  \n>**For the new code, you might want to try the new official [rx.disposables](https://github.com/Reactive-Extensions/rx.disposables) package instead.**\n\n# disposables [![npm package](https://img.shields.io/npm/v/disposables.svg?style=flat-square)](https://www.npmjs.org/package/disposables)\n\nDisposables let you safely compose resource disposal semantics.  \nThink DOM nodes, event handlers, socket connections.\n\n**This implementation of disposables is extracted from [RxJS](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables).**  \nI took the liberty to tweak the code style to my liking and provide this as a standalone package.\n\nThis tiny package includes several disposables:\n\n* [`Disposable`](https://github.com/gaearon/disposables/blob/master/src/Disposable.js) ensures its `dispose` action runs only once;\n* [`CompositeDisposable`](https://github.com/gaearon/disposables/blob/master/src/CompositeDisposable.js) ensures a group of disposables are disposed together;\n* [`SerialDisposable`](https://github.com/gaearon/disposables/blob/master/src/SerialDisposable.js) switches underlying disposables on the fly and disposes them.\n\nThe API is *mostly* the same as RxJS except stricter in a few places.  \nIt does not strive for 100% API compatibility with RxJS, but generally behavior is the same.\n\nIt's best if you consult the [source](https://github.com/gaearon/disposables/tree/master/src/) and [tests](https://github.com/gaearon/disposables/tree/master/src/__tests__), as classes are small and few.\n\n### Usage\n\n```js\nimport { Disposable, CompositeDisposable, SerialDisposable } from 'disposables';\n\n// or you can import just the ones you need to keep it even tinier\n// import SerialDisposable from 'disposables/modules/SerialDisposable';\n\nfunction attachHandlers(node) {\n\tlet someHandler = ...;\n\tnode.addEventHandler(someHandler);\n\n\t// use Disposable to guarantee single execution\n\treturn new Disposable(() => {\n\t  node.removeEventHandler(someHandler);\n\t});\n}\n\n// CompositeDisposable lets you compose several disposables...\nlet nodes = ...;\nlet compositeDisp = new CompositeDisposable(nodes.map(attachHandlers));\n\n// and more later...\nlet moreNodes = ...\nmoreNodes.map(attachHandlers).forEach(d => compositeDisp.add(d));\n\n// and dispose them at once!\nfunction goodbye() {\n\tcompositeDisp.dispose();\n}\n\n// ... or replace with a bunch of new ones ...\nlet serialDisp = new SerialDisposable();\nserialDisp.setDisposable(compositeDisp);\n\nfunction replaceNodes(newNodes) {\n\tlet nextCompositeDisp = new CompositeDisposable(newNodes.map(attachHandlers));\n\n\t// release all the previous disposables:\n\tserialDisp.setDisposable(nextCompositeDisp);\n}\n\n// with a guarantee of each dispose() called only once.\n```\n\n### License\n\nLike the original RxJS code, it is licensed under Apache 2.0.\n","_attachments":{},"homepage":"https://github.com/gaearon/disposables","bugs":{"url":"https://github.com/gaearon/disposables/issues"},"license":"Apache-2.0"}