仿互站小程序
This commit is contained in:
37
vant/mixins/observer/behavior.js
Normal file
37
vant/mixins/observer/behavior.js
Normal file
@@ -0,0 +1,37 @@
|
||||
function t(t, e) {
|
||||
return new Promise(function(i) {
|
||||
t.setData(e, i);
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: !0
|
||||
});
|
||||
|
||||
exports.behavior = Behavior({
|
||||
created: function() {
|
||||
var t = this;
|
||||
if (this.$options) {
|
||||
var e = {}, i = this.$options().computed, o = Object.keys(i);
|
||||
this.calcComputed = function() {
|
||||
var n = {};
|
||||
return o.forEach(function(o) {
|
||||
var s = i[o].call(t);
|
||||
e[o] !== s && (e[o] = n[o] = s);
|
||||
}), n;
|
||||
};
|
||||
}
|
||||
},
|
||||
attached: function() {
|
||||
this.set();
|
||||
},
|
||||
methods: {
|
||||
set: function(e, i) {
|
||||
var o = this, n = [];
|
||||
return e && n.push(t(this, e)), this.calcComputed && n.push(t(this, this.calcComputed())),
|
||||
Promise.all(n).then(function(t) {
|
||||
return i && "function" == typeof i && i.call(o), t;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
21
vant/mixins/observer/index.js
Normal file
21
vant/mixins/observer/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: !0
|
||||
}), exports.observe = function(o, t) {
|
||||
var s = o.watch, i = o.computed;
|
||||
if (t.behaviors.push(e.behavior), s) {
|
||||
var p = t.properties || {};
|
||||
Object.keys(s).forEach(function(e) {
|
||||
if (e in p) {
|
||||
var r = p[e];
|
||||
null !== r && "type" in r || (r = {
|
||||
type: r
|
||||
}), r.observer = s[e], p[e] = r;
|
||||
}
|
||||
}), t.properties = p;
|
||||
}
|
||||
i && (t.methods = t.methods || {}, t.methods.$options = function() {
|
||||
return o;
|
||||
}, t.properties && (0, r.observeProps)(t.properties));
|
||||
};
|
||||
|
||||
var e = require("./behavior"), r = require("./props");
|
14
vant/mixins/observer/props.js
Normal file
14
vant/mixins/observer/props.js
Normal file
@@ -0,0 +1,14 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: !0
|
||||
}), exports.observeProps = function(e) {
|
||||
e && Object.keys(e).forEach(function(t) {
|
||||
var r = e[t];
|
||||
null !== r && "type" in r || (r = {
|
||||
type: r
|
||||
});
|
||||
var s = r.observer;
|
||||
r.observer = function() {
|
||||
s && ("string" == typeof s && (s = this[s]), s.apply(this, arguments)), this.set();
|
||||
}, e[t] = r;
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user