Skip to content

Commit

Permalink
Merge pull request #44 from canjs/set-element-symbol
Browse files Browse the repository at this point in the history
implementing setElement symbol on SetterObservable
  • Loading branch information
phillipskevin authored Aug 14, 2019
2 parents d05b04c + 2f27888 commit 88867f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions setter/setter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var QUnit = require('steal-qunit');
var SetterObservable = require('./setter');
var SimpleObservable = require('../can-simple-observable');
var canReflect = require('can-reflect');
var Observation = require("can-observation");
var canSymbol = require("can-symbol");

QUnit.module('can-simple-observable/setter');

Expand Down Expand Up @@ -111,3 +113,18 @@ QUnit.test("getValueDependencies", function(assert) {
new Set([value])
);
});

QUnit.test("has setElement Symbol", function(assert) {
var setElementSymbol = canSymbol.for("can.setElement");
var setterObservable = new SetterObservable();
var obs = new Observation();
var el = {};
obs[setElementSymbol] = function(passedEl) {
assert.ok(true, "underlying observation's setElement Symbol is called");
assert.equal(passedEl, el, "observation's setElement is passed element");
};

setterObservable.observation = obs;

setterObservable[setElementSymbol](el);
});
8 changes: 7 additions & 1 deletion setter/setter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ var canReflect = require("can-reflect");
var Observation = require("can-observation");
var SettableObservable = require("../settable/settable");
var valueEventBindings = require("can-event-queue/value/value");
var canSymbol = require("can-symbol");

var setElementSymbol = canSymbol.for("can.setElement");

// SetterObservable's call a function when set. Their getter is backed up by an
// observation.
Expand Down Expand Up @@ -40,7 +43,10 @@ SetterObservable.prototype.hasDependencies = function() {
};
canReflect.assignSymbols(SetterObservable.prototype, {
"can.setValue": SetterObservable.prototype.set,
"can.valueHasDependencies": SetterObservable.prototype.hasDependencies
"can.valueHasDependencies": SetterObservable.prototype.hasDependencies,
"can.setElement": function(el) {
this.observation[setElementSymbol](el);
}
});

module.exports = SetterObservable;

0 comments on commit 88867f8

Please sign in to comment.