You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
877 B
JavaScript
28 lines
877 B
JavaScript
4 months ago
|
import { behavior } from './behavior';
|
||
|
import { observeProps } from './props';
|
||
|
export function observe(vantOptions, options) {
|
||
|
const { watch, computed } = vantOptions;
|
||
|
options.behaviors.push(behavior);
|
||
|
if (watch) {
|
||
|
const props = options.properties || {};
|
||
|
Object.keys(watch).forEach(key => {
|
||
|
if (key in props) {
|
||
|
let prop = props[key];
|
||
|
if (prop === null || !('type' in prop)) {
|
||
|
prop = { type: prop };
|
||
|
}
|
||
|
prop.observer = watch[key];
|
||
|
props[key] = prop;
|
||
|
}
|
||
|
});
|
||
|
options.properties = props;
|
||
|
}
|
||
|
if (computed) {
|
||
|
options.methods = options.methods || {};
|
||
|
options.methods.$options = () => vantOptions;
|
||
|
if (options.properties) {
|
||
|
observeProps(options.properties);
|
||
|
}
|
||
|
}
|
||
|
}
|