Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "vue-rx", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "RxJS bindings for Vue", | ||
@@ -5,0 +5,0 @@ "main": "vue-rx.js", |
# vue-rx | ||
Simple [RxJS](https://github.com/Reactive-Extensions/RxJS) binding for Vue.js (1.0.0+). | ||
Simple [RxJS](https://github.com/Reactive-Extensions/RxJS) binding for Vue.js. | ||
@@ -29,1 +29,5 @@ ### Usage | ||
See `/example` for a simple example. | ||
### License | ||
[MIT](http://opensource.org/licenses/MIT) |
(function () { | ||
function VueRx (Vue) { | ||
var VueVersion = Number(Vue.version && Vue.version.split('.')[0]) | ||
var initHook = VueVersion && VueVersion > 1 ? 'beforeCreate' : 'init' | ||
var installed = false | ||
function VueRx (Vue, Rx) { | ||
if (installed) { | ||
return | ||
} | ||
if (!Rx) { | ||
if (typeof window !== 'undefined' && window.Rx) { | ||
Rx = window.Rx | ||
} else { | ||
throw new Error( | ||
'Make sure to pass in Rx if it is not available globally: Vue.use(VueRx, Rx)' | ||
) | ||
} | ||
} | ||
installed = true | ||
Vue.mixin({ | ||
init: function () { | ||
var self = this | ||
var dataFn = this.$options.data | ||
if (dataFn) { | ||
this.$options.data = function () { | ||
var raw = dataFn() | ||
Object.keys(raw).forEach(function (key) { | ||
var val = raw[key] | ||
if (val instanceof Rx.Observable) { | ||
raw[key] = null | ||
;(self._rxHandles || (self._rxHandles = [])) | ||
.push(val.subscribe(function (value) { | ||
self[key] = raw[key] = value | ||
})) | ||
} | ||
}) | ||
return raw | ||
} | ||
} | ||
}, | ||
var mixin = { | ||
beforeDestroy: function () { | ||
@@ -50,3 +14,26 @@ if (this._rxHandles) { | ||
} | ||
}) | ||
} | ||
mixin[initHook] = function init () { | ||
var self = this | ||
var dataFn = this.$options.data | ||
if (dataFn) { | ||
this.$options.data = function () { | ||
var raw = dataFn() | ||
Object.keys(raw).forEach(function (key) { | ||
var val = raw[key] | ||
if (val.subscribe instanceof Function) { | ||
raw[key] = null | ||
;(self._rxHandles || (self._rxHandles = [])) | ||
.push(val.subscribe(function (value) { | ||
self[key] = raw[key] = value | ||
})) | ||
} | ||
}) | ||
return raw | ||
} | ||
} | ||
} | ||
Vue.mixin(mixin) | ||
} | ||
@@ -53,0 +40,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3489
4
33
47