|
1 | 1 | (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 | + |
3 | 9 | var VueVersion = Number(Vue.version && Vue.version.split('.')[0])
|
4 | 10 | var initHook = VueVersion && VueVersion > 1 ? 'beforeCreate' : 'init'
|
5 | 11 |
|
|
40 | 46 |
|
41 | 47 | Vue.mixin(mixin)
|
42 | 48 |
|
43 |
| - |
44 |
| - Vue.prototype.$watchAsObservable = function (expOrFn,options) { |
45 |
| - var self = this; |
| 49 | + Vue.prototype.$watchAsObservable = function (expOrFn, options) { |
| 50 | + var self = this |
46 | 51 |
|
47 | 52 | var obs$ = Rx.Observable.create(function (observer) {
|
48 | 53 | // Create function to handle old and new Value
|
49 | 54 | function listener (newValue, oldValue) {
|
50 |
| - observer.next({ oldValue: oldValue, newValue: newValue }); |
| 55 | + observer.next({ oldValue: oldValue, newValue: newValue }) |
51 | 56 | }
|
52 | 57 |
|
53 | 58 | // 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)) |
59 | 64 | }
|
60 | 65 |
|
61 |
| - return disposable; |
62 |
| - }).publish().refCount(); |
| 66 | + return disposable |
| 67 | + }).publish().refCount() |
63 | 68 |
|
64 |
| - (self._rxHandles || (self._rxHandles = [])).push(obs$); |
| 69 | + ;(self._rxHandles || (self._rxHandles = [])).push(obs$) |
65 | 70 |
|
66 |
| - return obs$; |
| 71 | + return obs$ |
67 | 72 | }
|
68 |
| - |
69 | 73 | }
|
70 | 74 |
|
71 | 75 | // 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) |
74 | 78 | }
|
75 | 79 |
|
76 |
| - if(typeof exports === 'object' && typeof module === 'object') { |
| 80 | + if (typeof exports === 'object' && typeof module === 'object') { |
77 | 81 | module.exports = VueRx
|
78 |
| - } else if(typeof define === 'function' && define.amd) { |
| 82 | + } else if (typeof define === 'function' && define.amd) { |
79 | 83 | define(function () { return VueRx })
|
80 | 84 | } else if (typeof window !== 'undefined') {
|
81 | 85 | window.VueRx = VueRx
|
|
0 commit comments