Skip to content

Commit 164d557

Browse files
committed
style tweak
1 parent 267569d commit 164d557

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

vue-rx.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
(function () {
2-
function VueRx (Vue,Rx) {
2+
function VueRx (Vue, Rx) {
3+
if (!Rx) {
4+
throw new Error(
5+
'vue-rx requires passing the Rx object to Vue.use() as the 2nd argument.'
6+
)
7+
}
8+
39
var VueVersion = Number(Vue.version && Vue.version.split('.')[0])
410
var initHook = VueVersion && VueVersion > 1 ? 'beforeCreate' : 'init'
511

@@ -40,42 +46,40 @@
4046

4147
Vue.mixin(mixin)
4248

43-
44-
Vue.prototype.$watchAsObservable = function (expOrFn,options) {
45-
var self = this;
49+
Vue.prototype.$watchAsObservable = function (expOrFn, options) {
50+
var self = this
4651

4752
var obs$ = Rx.Observable.create(function (observer) {
4853
// Create function to handle old and new Value
4954
function listener (newValue, oldValue) {
50-
observer.next({ oldValue: oldValue, newValue: newValue });
55+
observer.next({ oldValue: oldValue, newValue: newValue })
5156
}
5257

5358
// Returns function which disconnects the $watch expression
54-
var disposable;
55-
if(Rx.Subscription){//Rx5
56-
disposable = new Rx.Subscription(self.$watch(expOrFn,listener,options));
57-
}else{//Rx4
58-
disposable = Rx.Disposable.create(self.$watch(expOrFn,listener,options));
59+
var disposable
60+
if (Rx.Subscription) { // Rx5
61+
disposable = new Rx.Subscription(self.$watch(expOrFn, listener, options))
62+
} else { // Rx4
63+
disposable = Rx.Disposable.create(self.$watch(expOrFn, listener, options))
5964
}
6065

61-
return disposable;
62-
}).publish().refCount();
66+
return disposable
67+
}).publish().refCount()
6368

64-
(self._rxHandles || (self._rxHandles = [])).push(obs$);
69+
;(self._rxHandles || (self._rxHandles = [])).push(obs$)
6570

66-
return obs$;
71+
return obs$
6772
}
68-
6973
}
7074

7175
// auto install
72-
if (typeof Vue !== 'undefined') {
73-
Vue.use(VueRx,Rx)
76+
if (typeof Vue !== 'undefined' && typeof Rx !== 'undefined') {
77+
Vue.use(VueRx, Rx)
7478
}
7579

76-
if(typeof exports === 'object' && typeof module === 'object') {
80+
if (typeof exports === 'object' && typeof module === 'object') {
7781
module.exports = VueRx
78-
} else if(typeof define === 'function' && define.amd) {
82+
} else if (typeof define === 'function' && define.amd) {
7983
define(function () { return VueRx })
8084
} else if (typeof window !== 'undefined') {
8185
window.VueRx = VueRx

0 commit comments

Comments
 (0)