{"_id":"@daotl/vue-next-rx","_rev":"1-fa33c14b985bb06cf03ecbdca988c265","name":"@daotl/vue-next-rx","dist-tags":{"latest":"1.0.12"},"versions":{"1.0.12":{"name":"@daotl/vue-next-rx","version":"1.0.12","description":"RxJs for Vue 3","author":{"name":"Boucham Amine"},"license":"MIT","bugs":{"url":"https://github.com/NOPR9D/vue-next-rx/issues"},"homepage":"https://github.com/NOPR9D/vue-next-rx#readme","main":"dist/vue-next-rx.js","module":"dist/vue-next-rx.esm.js","sideEffects":false,"typings":"types/index.d.ts","scripts":{"dev":"rollup -c rollup.config.js -w","build":"rollup -c rollup.config.js","publish":"npm publish --access public","lint":"eslint src test example","dev:test":"jest --watch","test":"jest"},"devDependencies":{"@rollup/plugin-alias":"^3.1.1","@rollup/plugin-buble":"^0.21.3","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","@vue/eslint-config-typescript":"^7.0.0","@vue/test-utils":"^2.0.0-beta.12","buble":"^0.20.0","eslint":"^7.2.0","eslint-plugin-vue":"^7.2.0","jest":"^26.6.3","mocha":"^8.2.1","nyc":"^15.1.0","prettier":"^2.2.1","rollup":"^2.34.2","rxjs":"^7.0.0","typescript":"^2.8.2","vue":"^3.2.0"},"peerDependencies":{"rxjs":"^7.0.0","vue":"^3.0.0"},"repository":{"type":"git","url":"git+https://github.com/NOPR9D/vue-next-rx.git"},"keywords":["vue","vue 3","vue3","vue next","rx","rxjs","composition-api","composition","pure","hooks","store","support"],"gitHead":"3a142d633cdf1de02593a0639ea4887afa237234","_id":"@daotl/vue-next-rx@1.0.12","_nodeVersion":"18.9.0","_npmVersion":"8.19.1","dist":{"integrity":"sha512-kP9ugkEvxrPBV/fBgUmPygVMbGXykAD8SHwp8rX9XrwPqRSTpbTCWPegZ3eHTfu5Cl6TKzFHf31Okj2Lt3H35Q==","shasum":"619bb91b39d051217cea97ea755f140bdf0f4550","tarball":"https://registry.npmjs.org/@daotl/vue-next-rx/-/vue-next-rx-1.0.12.tgz","fileCount":5,"unpackedSize":23704,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEoq2QF93lNa1yXJB030Lu7om+sxdP6WbXCnS5IeVZmbAiEArFbl/oLOKfSIUoy407TQhPAnFb3Ca8aw/OLTbIA52uc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjWA6wACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpWCQ/5AexZDbW+yA8RjPqqGzcn03TE2jGlMgfudoD3tsHQiC5iPOjb\r\nEozRV1UZIzx4tE/4jRVVLA1dpBbWpYAobnonAIBS029hpmnenQ3vQraua99R\r\n5s/fKLm2M6UyzGnq/X2zf2f3emw2DzUD0tkkTEmfGEdbUBTkTmkIsubST7S7\r\ntEl1cPR+8QUUA3YoXFaMQcFCuO3bMoW+2lOmvkSK/fZXVjn1RmVuI9CRss4P\r\navI5hMqKOQ3phOSoKdM4tJQftvU4tnVlqvHBI5TBAN4CZ7uiGcdsAJPZyE2T\r\nO41ByTVyuekbhXDnWa2Jy+INeCtJ7RgYFwQWKZS+3CAY8JOs9LSe5rLeQ4dk\r\n2RhOSbNKKYTYY3kWPuLuejuEtF3Oq/6TibXaoBHBJpr3V+33MRwhN/jpCFoB\r\nZccqlHzNwg1SVGMczZYBlJ5OLYOI5eF5Tfesd90Mu3jwk2bibVi1xndGBVOF\r\nyPptdZV7HkbSd3BOhvRfQDvIKuPL8BWbiqYVBI0R9T3ery3DhUgRBMgCa8lp\r\nZlzGRzpaPlW9kbGPcxHEsSH8yUIjCPnoDcDEr1SqUqeWRGXJYBYhfSbYFBct\r\n+R7GYQdORujHjEdDj3Qy04UbYtE8m1ZmIN4NivgjiOAgWaWw4h9doq+qfcJQ\r\nCVSfZDpLDwdiYmLtSGJgoHprUQC9fzm64pI=\r\n=b0gl\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nex","email":"nexzhu@gmail.com"},"directories":{},"maintainers":[{"name":"nex","email":"nexzhu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vue-next-rx_1.0.12_1666715312552_0.6249029758086859"},"_hasShrinkwrap":false}},"time":{"created":"2022-10-25T16:28:32.446Z","1.0.12":"2022-10-25T16:28:32.743Z","modified":"2023-05-18T09:55:30.450Z"},"maintainers":[{"email":"zwjCheer@163.com","name":"zwj_cheer"},{"email":"nexzhu@gmail.com","name":"nex"}],"description":"RxJs for Vue 3","homepage":"https://github.com/NOPR9D/vue-next-rx#readme","keywords":["vue","vue 3","vue3","vue next","rx","rxjs","composition-api","composition","pure","hooks","store","support"],"repository":{"type":"git","url":"git+https://github.com/NOPR9D/vue-next-rx.git"},"author":{"name":"Boucham Amine"},"bugs":{"url":"https://github.com/NOPR9D/vue-next-rx/issues"},"license":"MIT","readme":"# vue-next-rx\n\n<div align=\"center\">\n<img src=\"https://i.ibb.co/q5267TX/maxresdefault-2.jpg\" width=\"25%\" />\n</div>\n\n### [RxJS v7](https://github.com/ReactiveX/rxjs) integration for [Vue next]()\n\n</br>\n\n![](https://img.shields.io/github/license/NOPR9D/vue-next-rx)\n![](https://gitlab.com/nopr3d/vue-next-rx/badges/main/pipeline.svg)\n\n<br>\n\n> **NOTE**\n>\n> - vue-next-rx only works with RxJS v6+ by default. If you want to keep using RxJS v5 style code, install `rxjs-compat`.\n\n---\n\n# Installation\n\n#### NPM + ES2015 or more\n\n**`rxjs` is required as a peer dependency.**\n\n```bash\nnpm install vue @nopr3d/vue-next-rx rxjs --save\n```\n\n```js\nimport Vue from \"vue\";\nimport VueNextRx from \"@nopr3d/vue-next-rx\";\n\nVue.use(VueNextRx);\n```\n\n<br />\n\nWhen bundling via webpack, `dist/vue-next-rx.esm.js` is used by default. It imports the minimal amount of Rx operators and ensures small bundle sizes.\n\nTo use in a browser environment, use the UMD build `dist/vue-next-rx.js`. When in a browser environment, the UMD build assumes `window.rxjs` to be already present, so make sure to include `vue-next-rx.js` after Vue.js and RxJS. It also installs itself automatically if `window.Vue` is present.\n\nExample:\n\n```html\n<script src=\"https://unpkg.com/rxjs@^7/dist/bundles/rxjs.umd.min.js\"></script>\n<script src=\"https://unpkg.com/vue@next\"></script>\n<script src=\"../dist/vue-next-rx.js\"></script>\n<div id=\"app\">\n  <div class=\"home\">\n    <button v-stream:click=\"click$\">Click Me</button>\n  </div>\n</div>\n<script>\n  const { Subject, Observable, BehaviorSubject } = rxjs;\n  const { map, startWith, scan } = rxjs.operators;\n  const { ref, watch } = VueNextRx; // Use VueNextRx\n\n  const app = Vue.createApp({\n    domStreams: [\"click$\"],\n    subscriptions() {\n      this.click$.pipe(map(() => \"Click Event\")).subscribe(console.log); // On click will print \"Click Event\"\n    },\n  }).use(VueNextRx);\n  app.mount(\"#app\");\n</script>\n```\n\n<br />\n\n---\n\n# Usage\n\n<br />\n\n# Subscriptions\n\n```js\n// Expose `Subject` with domStream, use them in subscriptions functions\nexport default defineComponent({\n  name: \"Home\",\n   domStreams: [\"click$\"],\n    subscriptions() {\n      return {\n        count: this.click$.pipe(\n          map(() => 1),\n          startWith(0),\n          scan((total, change) => total + change)\n        ),\n      };\n});\n```\n\n```html\n<div>\n  <button v-stream:click=\"click$\">Click Me</button>\n</div>\n\n<div>{{count}}</div>\n<!-- On click will show 0, 1 ,2 ,3... -->\n```\n\n### Or\n\n</br>\n\n```js\n// Expose `Subject` with domStream, use them in subscriptions functions\nexport default defineComponent({\n  name: \"Home\",\n  domStreams: [\"action$\"],\n  subscriptions() {\n    this.action$.pipe(map(() => \"Click Event !\")).subscribe(console.log);\n    // On click will print \"Click Event\"\n  },\n});\n```\n\n## Tips\n\nYou can get the data by simply plucking it from the source stream:\n\n```js\nconst actionData$ = this.action$.pipe(pluck(\"data\"));\n```\n\nYou can bind Subject by this way\n\n```html // Bind with stream directives\n<button v-stream:click=\"action$\">Click Me!</button>\nor\n<button v-stream:click=\"{ subject: action$, data: someData }\">+</button>\n```\n\n</br>\n\n---\n\n# Ref\n\n```js\nimport { ref } from \"@nopr3d/vue-next-rx\";\n\n// use ref like an Rx Subject\nexport default defineComponent({\n  name: \"Home\",\n  components: {},\n  setup() {\n    const msg = ref(\"Message exemple\");\n\n    setTimeout(() => {\n      msg.value = \"New message !\";\n    }, 2000);\n\n    msg.subscribe((value) => {\n      console.log(value); // After 2s will print : New message !\n    });\n\n    return { msg };\n  },\n});\n```\n\n```html\n<!-- bind to it normally in templates -->\n<!-- on change DOM is update too -->\n<div>{{ msg }}</div>\n```\n\n---\n\n<br />\n\n# Watch\n\n```js\nimport { ref, watch } from \"@nopr3d/vue-next-rx\";\n\nexport default defineComponent({\n  name: \"Home\",\n  components: {},\n  setup() {\n    const msg = ref(\"Message exemple\");\n\n    watch(msg).subscribe((val) => {\n      console.log(val); // After 2s will print : New message !\n    });\n\n    setTimeout(() => {\n      msg.value = \"New message !\";\n    }, 2000);\n\n    return { msg };\n  },\n});\n```\n\n```html\n<!-- bind to it normally in templates -->\n<!-- on change DOM is update too -->\n<div>{{ msg }}</div>\n```\n\n---\n\n<br />\n\n# Other API Methods\n\n</br>\n\n## `$watchAsObservable(expOrFn, [options])`\n\nThis is a prototype method added to instances. You can use it to create an observable from a Data. The emitted value is in the format of `{ newValue, oldValue }`:\n\n```js\nimport { ref } from \"@nopr3d/vue-next-rx\";\n\nexport default defineComponent({\n  name: \"Home\",\n  setup() {\n    const msg = ref(\"Old Message\");\n    setTimeout(() => (msg.value = \"New message incomming !\"), 1000);\n    return { msg };\n  },\n  subscriptions() {\n    return {\n      oldMsg: this.$watchAsObservable(\"msg\").pipe(pluck(\"oldValue\")),\n    };\n  },\n});\n```\n\n```html\n<!-- bind to it normally in templates -->\n<!-- on change DOM is update too -->\n<div>{{ msg }}</div>\n<!-- Will display : Old message, after 1 second display \"New Message !\" -->\n<div>{{oldMsg}}</div>\n<!-- wait for value and display \"Old Message\" after 1 second -->\n```\n\n---\n\n## `$subscribeTo(observable, next, error, complete)`\n\nThis is a prototype method added to instances. You can use it to subscribe to an observable, but let VueNextRx manage the dispose/unsubscribe.\n\n```js\nimport { interval } from \"rxjs\";\n\nconst vm = new Vue({\n  mounted() {\n    this.$subscribeTo(interval(1000), function (count) {\n      console.log(count);\n    });\n  },\n});\n```\n\n## `$fromDOMEvent(selector, event)`\n\nThis is a prototype method added to instances. Use it to create an observable from DOM events within the instances' element. This is similar to `Rx.Observable.fromEvent`, but usable inside the `subscriptions` function even before the DOM is actually rendered.\n\n`selector` is for finding descendant nodes under the component root element, if you want to listen to events from root element itself, pass `null` as first argument.\n\n```js\nimport { pluck } from \"rxjs/operators\";\n\nconst vm = new Vue({\n  subscriptions() {\n    return {\n      inputValue: this.$fromDOMEvent(\"input\", \"keyup\").pipe(\n        pluck(\"target\", \"value\")\n      ),\n    };\n  },\n});\n```\n\n```html\n<div><input /></div>\n<div>{{inputValue}}</div>\n```\n\n---\n\n## `$createObservableMethod(methodName)`\n\nConvert function calls to observable sequence which emits the call arguments.\n\nThis is a prototype method added to instances. Use it to create a shared hot observable from a function name. The function will be assigned as a vm method.\n\n```html\n<custom-form :onSubmit=\"submitHandler\"></custom-form>\n```\n\n```js\nconst vm = new Vue({\n  subscriptions() {\n    return {\n      // requires `share` operator\n      formData: this.$createObservableMethod(\"submitHandler\"),\n    };\n  },\n});\n```\n\nYou can use the `observableMethods` option to make it more declarative:\n\n```js\nnew Vue({\n  observableMethods: {\n    submitHandler: \"submitHandler$\",\n    // or with Array shothand: ['submitHandler']\n  },\n});\n```\n\nThe above will automatically create two things on the instance:\n\n1. A `submitHandler` method which can be bound to in template with `v-on`;\n2. A `submitHandler$` observable which will be the stream emitting calls to `submitHandler`.\n\n[example](https://github.com/NOPR9D/vue-next-rx/blob/main/example/createObservableMethod.html)\n\n---\n\n## Example\n\nSee `/examples` for some simple examples.\n\n</br>\n\n---\n\n## Test\n\nTest look goods, feel free to open an issue !\n\n![](https://i.ibb.co/17mtk34/testsPNG.png)\n\n---\n\n### Contributors\n\n<div align=\"center\" style=\"display:flex;\" >\n<div  style=\"display:flex; flex-direction:row;align-items:center;width:50%;\">\n<a href=\"https://github.com/NOPR9D\">\n<img style=\"border-radius:100px; margin:auto;\" src=\"https://avatars.githubusercontent.com/u/75882457?v=4\" width=\"75px\" />\n<div>NOPR9D</div></a>\n</div>\n<div style=\"display:flex; flex-direction:row;align-items:center; width:50%;\" >\n<a href=\"https://github.com/AlvinTCH\">\n<img style=\"border-radius:100px; margin:auto;\" src=\"https://avatars.githubusercontent.com/u/48837852?v=4\" width=\"75px\" />\n<div>AlvinTCH</div>\n</a>\n</div>\n</div>\n\n---\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\n---\n","readmeFilename":"README.md"}