ReplaceValueDependency.js 533 B

12345678910111213141516171819202122
  1. const { set } = require('../../utils/objectUtils');
  2. const Dependency = require('./Dependency');
  3. class ReplaceValueDependency extends Dependency {
  4. constructor(node, path, refProp, inverse) {
  5. super(node);
  6. this.path = path.slice();
  7. this.refProp = refProp;
  8. this.inverse = inverse;
  9. }
  10. resolve(model) {
  11. if (!this.inverse) {
  12. set(model, this.path, this.node.model[this.refProp]);
  13. } else {
  14. set(this.node.model, this.path, model[this.refProp]);
  15. }
  16. }
  17. }
  18. module.exports = ReplaceValueDependency;