Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.

Commit ad89efe

Browse files
committed
[PERF] Don't Attempt To Sanitive Unsanitizeable
This adds an identity check for falsy values before the value is sanitized. Currently we do work to sanitize things like `undefined`.
1 parent b0994e1 commit ad89efe

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/morph-attr/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ AttrMorph.prototype.setContent = function (value) {
110110
if (this.lastValue === value) { return; }
111111
this.lastValue = value;
112112

113-
if (this.escaped) {
113+
if (this.escaped && value) {
114114
var sanitized = sanitizeAttributeValue(this.domHelper, this.element, this.attrName, value);
115115
this._update(sanitized, this.namespace);
116116
} else {

packages/morph-attr/tests/attr-morph-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ test("can update a dom node", function(){
1717
equal(element.getAttribute('id'), 'twang', 'id attribute is set');
1818
});
1919

20+
test("setting content to undefined calls _update with undefiend", function(){
21+
var element = domHelper.createElement('div');
22+
var morph = domHelper.createAttrMorph(element, 'id');
23+
var update = morph._setContent;
24+
var calledWith;
25+
morph.setContent(undefined);
26+
morph._update = function(value) {
27+
calledWith = value;
28+
return update.apply(morph, arguments);
29+
};
30+
ok(calledWith === undefined);
31+
equal(element.id, '');
32+
});
33+
2034
test("can clear", function(){
2135
expect(0);
2236
var element = domHelper.createElement('div');

0 commit comments

Comments
 (0)