InterpolateValueDependency.js 765 B

123456789101112131415161718192021222324252627
  1. const { get, set } = require('../../utils/objectUtils');
  2. const Dependency = require('./Dependency');
  3. class InterpolateValueDependency extends Dependency {
  4. constructor(node, path, refProp, match, inverse) {
  5. super(node);
  6. this.path = path.slice();
  7. this.refProp = refProp;
  8. this.match = match;
  9. this.inverse = inverse;
  10. }
  11. resolve(model) {
  12. if (!this.inverse) {
  13. let value = get(model, this.path);
  14. value = value.replace(this.match, this.node.model[this.refProp]);
  15. set(model, this.path, value);
  16. } else {
  17. let value = get(this.node.model, this.path);
  18. value = value.replace(this.match, model[this.refProp]);
  19. set(this.node.model, this.path, value);
  20. }
  21. }
  22. }
  23. module.exports = InterpolateValueDependency;