index.js 855 B

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