index.js 877B

12345678910111213141516171819202122232425262728
  1. import { behavior } from './behavior';
  2. import { observeProps } from './props';
  3. export function observe(vantOptions, options) {
  4. const { watch, computed } = vantOptions;
  5. options.behaviors.push(behavior);
  6. if (watch) {
  7. const props = options.properties || {};
  8. Object.keys(watch).forEach(key => {
  9. if (key in props) {
  10. let prop = props[key];
  11. if (prop === null || !('type' in prop)) {
  12. prop = { type: prop };
  13. }
  14. prop.observer = watch[key];
  15. props[key] = prop;
  16. }
  17. });
  18. options.properties = props;
  19. }
  20. if (computed) {
  21. options.methods = options.methods || {};
  22. options.methods.$options = () => vantOptions;
  23. if (options.properties) {
  24. observeProps(options.properties);
  25. }
  26. }
  27. }