All Projects → mylabz-xyz → vue-next-rx

mylabz-xyz / vue-next-rx

Licence: MIT license
RxJS integration for Vue next

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to vue-next-rx

vuse-rx
Vue 3 + rxjs = ❤
Stars: ✭ 52 (+67.74%)
Mutual labels:  rxjs, vue3, composition-api, vue-next
vue-reuse
基于composition-api的hooks函数库
Stars: ✭ 28 (-9.68%)
Mutual labels:  vue3, vue-hooks, composition-api
vue-cookie-next
A vue 3 plugin for handling browser cookies with typescript support. Load and save cookies within your Vue 3 application
Stars: ✭ 37 (+19.35%)
Mutual labels:  vue3, vue-next
Vueuse
Collection of essential Vue Composition Utilities for Vue 2 and 3
Stars: ✭ 7,290 (+23416.13%)
Mutual labels:  vue3, vue-next
Iconpark
🍎Transform an SVG icon into multiple themes, and generate React icons,Vue icons,svg icons
Stars: ✭ 4,924 (+15783.87%)
Mutual labels:  vue3, vue-next
vue3-demo
💡 vue3新特性示例: 响应式API、组合式API、TodoMVC
Stars: ✭ 114 (+267.74%)
Mutual labels:  vue3, composition-api
vue3-realworld-example-app
Explore the charm of Vue composition API! Vite?
Stars: ✭ 364 (+1074.19%)
Mutual labels:  vue3, composition-api
codemirror-editor-vue3
CodeMirror component for Vue3
Stars: ✭ 22 (-29.03%)
Mutual labels:  vue3, vue-next
vue3-jd-h5
🔥 Based on vue3.0.0, vant3.0.0, vue-router v4.0.0-0, vuex^4.0.0-0, vue-cli3, mockjs, imitating Jingdong Taobao, mobile H5 e-commerce platform! 基于vue3.0.0 ,vant3.0.0,vue-router v4.0.0-0, vuex^4.0.0-0,vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台!
Stars: ✭ 660 (+2029.03%)
Mutual labels:  vue3, vue-next
2019-ncov-vue3-version
新型冠状病毒实时疫情 Vue-Compostion-Api版本 (Vue3 + TypeScript)
Stars: ✭ 55 (+77.42%)
Mutual labels:  vue3, composition-api
vue-data-visualization
基于Vue3.0的“数据可视化大屏”设计与编辑器
Stars: ✭ 84 (+170.97%)
Mutual labels:  vue3, vue-next
bpmn-vue-activiti
基于Vue3.x + Vite + bpmn-js + element-plus + tsx 实现的Activiti流程设计器(Activiti process designer based on Vue3.x + Vite + BPMN-JS + Element-Plus + TSX implementation)
Stars: ✭ 345 (+1012.9%)
Mutual labels:  vue3, vue-next
v-pip
🖼 Tiny vue wrapper for supporting native picture-in-picture mode.
Stars: ✭ 30 (-3.23%)
Mutual labels:  vue3, composition-api
vue3.0-template-admin
本项目基于vue3+ElementPlus+Typescript+Vite搭建一套通用的后台管理模板;并基于常见业务场景,抽象出常见功能组件;包括动态菜单,菜单权限、登录、主题切换、国际化、个人中心、表单页、列表页、复制文本、二维码分享等等
Stars: ✭ 500 (+1512.9%)
Mutual labels:  vue3, vue-next
vue-snippets
Visual Studio Code Syntax Highlighting For Vue3 And Vue2
Stars: ✭ 25 (-19.35%)
Mutual labels:  vue3, composition-api
v-bucket
📦 Fast, Simple, and Lightweight State Manager for Vue 3.0 built with composition API, inspired by Vuex.
Stars: ✭ 42 (+35.48%)
Mutual labels:  vue3, composition-api
vue-magnify
vue-magnify / vue放大镜组件
Stars: ✭ 14 (-54.84%)
Mutual labels:  vue3, vue-hooks
vue3-form-validation
Vue Composition Function for Form Validation
Stars: ✭ 18 (-41.94%)
Mutual labels:  vue3, composition-api
Vue3 News
🔥 Find the latest breaking Vue3、Vue CLI 3+ & Vite News. (2021)
Stars: ✭ 2,416 (+7693.55%)
Mutual labels:  vue3, composition-api
vue-ray
Debug your Vue 2 & 3 code with Ray to fix problems faster
Stars: ✭ 48 (+54.84%)
Mutual labels:  vue-plugin, vue3

vue-next-rx

RxJS v7 integration for Vue next



NOTE

  • vue-next-rx only works with RxJS v6+ by default. If you want to keep using RxJS v5 style code, install rxjs-compat.

Installation

NPM + ES2015 or more

rxjs is required as a peer dependency.

npm install vue @nopr3d/vue-next-rx rxjs --save
import Vue from "vue";
import VueNextRx from "@nopr3d/vue-next-rx";

Vue.use(VueNextRx);

When 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.

To 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.

Example:

<script src="https://unpkg.com/rxjs@^7/dist/bundles/rxjs.umd.min.js"></script>
<script src="https://unpkg.com/vue@next"></script>
<script src="../dist/vue-next-rx.js"></script>
<div id="app">
  <div class="home">
    <button v-stream:click="click$">Click Me</button>
  </div>
</div>
<script>
  const { Subject, Observable, BehaviorSubject } = rxjs;
  const { map, startWith, scan } = rxjs.operators;
  const { ref, watch } = VueNextRx; // Use VueNextRx

  const app = Vue.createApp({
    domStreams: ["click$"],
    subscriptions() {
      this.click$.pipe(map(() => "Click Event")).subscribe(console.log); // On click will print "Click Event"
    },
  }).use(VueNextRx);
  app.mount("#app");
</script>


Usage


Subscriptions

// Expose `Subject` with domStream, use them in subscriptions functions
export default defineComponent({
  name: "Home",
   domStreams: ["click$"],
    subscriptions() {
      return {
        count: this.click$.pipe(
          map(() => 1),
          startWith(0),
          scan((total, change) => total + change)
        ),
      };
});
<div>
  <button v-stream:click="click$">Click Me</button>
</div>

<div>{{count}}</div>
<!-- On click will show 0, 1 ,2 ,3... -->

Or


// Expose `Subject` with domStream, use them in subscriptions functions
export default defineComponent({
  name: "Home",
  domStreams: ["action$"],
  subscriptions() {
    this.action$.pipe(map(() => "Click Event !")).subscribe(console.log);
    // On click will print "Click Event"
  },
});

Tips

You can get the data by simply plucking it from the source stream:

const actionData$ = this.action$.pipe(pluck("data"));

You can bind Subject by this way

<button v-stream:click="action$">Click Me!</button>
or
<button v-stream:click="{ subject: action$, data: someData }">+</button>


Ref

import { ref } from "@nopr3d/vue-next-rx";

// use ref like an Rx Subject
export default defineComponent({
  name: "Home",
  components: {},
  setup() {
    const msg = ref("Message exemple");

    setTimeout(() => {
      msg.value = "New message !";
    }, 2000);

    msg.subscribe((value) => {
      console.log(value); // After 2s will print : New message !
    });

    return { msg };
  },
});
<!-- bind to it normally in templates -->
<!-- on change DOM is update too -->
<div>{{ msg }}</div>


Watch

import { ref, watch } from "@nopr3d/vue-next-rx";

export default defineComponent({
  name: "Home",
  components: {},
  setup() {
    const msg = ref("Message exemple");

    watch(msg).subscribe((val) => {
      console.log(val); // After 2s will print : New message !
    });

    setTimeout(() => {
      msg.value = "New message !";
    }, 2000);

    return { msg };
  },
});
<!-- bind to it normally in templates -->
<!-- on change DOM is update too -->
<div>{{ msg }}</div>


Other API Methods


$watchAsObservable(expOrFn, [options])

This 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 }:

import { ref } from "@nopr3d/vue-next-rx";

export default defineComponent({
  name: "Home",
  setup() {
    const msg = ref("Old Message");
    setTimeout(() => (msg.value = "New message incomming !"), 1000);
    return { msg };
  },
  subscriptions() {
    return {
      oldMsg: this.$watchAsObservable("msg").pipe(pluck("oldValue")),
    };
  },
});
<!-- bind to it normally in templates -->
<!-- on change DOM is update too -->
<div>{{ msg }}</div>
<!-- Will display : Old message, after 1 second display "New Message !" -->
<div>{{oldMsg}}</div>
<!-- wait for value and display "Old Message" after 1 second -->

$subscribeTo(observable, next, error, complete)

This is a prototype method added to instances. You can use it to subscribe to an observable, but let VueNextRx manage the dispose/unsubscribe.

import { interval } from "rxjs";

const vm = new Vue({
  mounted() {
    this.$subscribeTo(interval(1000), function (count) {
      console.log(count);
    });
  },
});

$fromDOMEvent(selector, event)

This 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.

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.

import { pluck } from "rxjs/operators";

const vm = new Vue({
  subscriptions() {
    return {
      inputValue: this.$fromDOMEvent("input", "keyup").pipe(
        pluck("target", "value")
      ),
    };
  },
});
<div><input /></div>
<div>{{inputValue}}</div>

$createObservableMethod(methodName)

Convert function calls to observable sequence which emits the call arguments.

This 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.

<custom-form :onSubmit="submitHandler"></custom-form>
const vm = new Vue({
  subscriptions() {
    return {
      // requires `share` operator
      formData: this.$createObservableMethod("submitHandler"),
    };
  },
});

You can use the observableMethods option to make it more declarative:

new Vue({
  observableMethods: {
    submitHandler: "submitHandler$",
    // or with Array shothand: ['submitHandler']
  },
});

The above will automatically create two things on the instance:

  1. A submitHandler method which can be bound to in template with v-on;
  2. A submitHandler$ observable which will be the stream emitting calls to submitHandler.

example


Example

See /examples for some simple examples.



Test

Test look goods, feel free to open an issue !


Contributors


License

MIT


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].