collectObservers.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. var _require = require('./observerHandle'),
  3. observersHandle = _require.observersHandle;
  4. function collectObservers(observersObj, options, param) {
  5. var self = this;
  6. var _loop = function _loop(key) {
  7. if (options.observers.hasOwnProperty(key)) {
  8. var keyArr = key.split(',');
  9. var arr = [];
  10. keyArr.forEach(function (its) {
  11. its = its.trim();
  12. var attr = {};
  13. if (its.match(/\./)) {
  14. var _attr = its.split('.');
  15. attr = processChildAttr(self.data, _attr);
  16. } else {
  17. attr = self.data[its];
  18. }
  19. arr.push(attr);
  20. });
  21. keyArr.forEach(function (its) {
  22. its = its.trim();
  23. observersObj[its] = Object.create(null);
  24. observersObj[its].fn = options.observers[key];
  25. observersObj[its].arr = arr;
  26. });
  27. }
  28. };
  29. for (var key in options.observers) {
  30. _loop(key);
  31. }
  32. observersHandle(observersObj, param, self);
  33. }
  34. function processChildAttr(attr, arr) {
  35. var _ = attr;
  36. arr.forEach(function (name) {
  37. _ = _[name];
  38. });
  39. return _;
  40. }
  41. module.exports = collectObservers;