props.js 597B

1234567891011121314151617181920212223
  1. export function observeProps(props) {
  2. if (!props) {
  3. return;
  4. }
  5. Object.keys(props).forEach(key => {
  6. let prop = props[key];
  7. if (prop === null || !('type' in prop)) {
  8. prop = { type: prop };
  9. }
  10. let { observer } = prop;
  11. prop.observer = function (...args) {
  12. if (observer) {
  13. if (typeof observer === 'string') {
  14. observer = this[observer];
  15. }
  16. observer.apply(this, args);
  17. }
  18. this.set();
  19. };
  20. props[key] = prop;
  21. });
  22. }