![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Simple RxJS binding for Vue.js. It also supports subscriptions for generic observables that implement the .subscribe
and .unsubscribe
(or .dispose
) interface. For example, you can use it to subscribe to most.js
or Falcor streams, but some features require RxJS to work.
npm install vue vue-rx rxjs --save
import Vue from 'vue'
import Rx from 'rxjs/Rx'
import VueRx from 'vue-rx'
// tada!
Vue.use(VueRx, Rx)
In most cases, you probably don't need the full build of Rx. You can reduce the amount of code included in your bundle by doing the following:
import Vue from 'vue'
import VueRx from 'vue-rx'
import { Observable } from 'rxjs/Observable'
import { Subscription } from 'rxjs/Subscription' // Disposable if using RxJS4
// tada!
Vue.use(VueRx, { Observable, Subscription })
Just make sure to include vue-rx.js
after Vue.js and RxJS. It will be installed automatically.
// provide Rx observables with the `subscriptions` option
new Vue({
el: '#app',
subscriptions: {
msg: messageObservable
}
})
<!-- bind to it normally in templates -->
<div>{{ msg }}</div>
The subscriptions
options can also take a function so that you can return unique observables for each component instance:
Vue.component('foo', {
subscriptions: function () {
return {
msg: Rx.Observable.create(...)
}
}
})
The observables are exposed as vm.$observables
:
var vm = new Vue({
subscriptions: {
msg: messageObservable
}
})
vm.$observables.msg.subscribe(msg => console.log(msg))
$watchAsObservable(expOrFn, [options])
This feature requires RxJS.
This is a prototype method added to instances. You can use it to create an observable from a value watcher. The emitted value is in the format of { newValue, oldValue }
:
var vm = new Vue({
data: {
a: 1
},
subscriptions () {
// declaratively map to another property with Rx operators
return {
aPlusOne: this.$watchAsObservable('a')
.pluck('newValue')
.map(a => a + 1)
}
}
})
// or produce side effects...
vm.$watchAsObservable('a')
.subscribe(
({ newValue, oldValue }) => console.log('stream value', newValue, oldValue),
err => console.error(err),
() => console.log('complete')
)
The optional options
object accepts the same options as vm.$watch
.
$subscribeTo(observable, next, error, complete)
This is a prototype method added to instances. You can use it to subscribe to an observable, but let VueRx manage the dispose/unsubscribe.
var vm = new Vue({
mounted () {
this.$subscribeTo(Rx.Observable.interval(1000), function (count) {
console.log(count)
})
}
})
$fromDOMEvent(selector, event)
This feature requires RxJS.
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.
var vm = new Vue({
subscriptions () {
return {
inputValue: this.$fromDOMEvent('input', 'keyup').pluck('target', 'value')
}
}
})
You cannot use the watch
option to watch subscriptions, because it is processed before the subscriptions are set up. But you can use $watch
in the created
hook instead.
See /examples
for some simple examples.
FAQs
RxJS bindings for Vue
We found that vue-rx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.