-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from canjs/add-bindings-symbol
Make addBindings prefer a symbol.
- Loading branch information
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
var canReflect = require("can-reflect"); | ||
var canSymbol = require('can-symbol'); | ||
var viewCallbacks = require("can-view-callbacks"); | ||
|
||
var bindingsSymbol = canSymbol.for('can.stacheBindings'); | ||
var bindingsAdded = new WeakMap(); | ||
|
||
module.exports = function(bindingsMap) { | ||
canReflect.eachKey(bindingsMap, function(callback, exp){ | ||
var map = canReflect.getKeyValue(bindingsMap, bindingsSymbol) || bindingsMap; | ||
|
||
// Only add bindings once. | ||
if(bindingsAdded.has(map)) { | ||
return; | ||
} else { | ||
// Would prefer to use WeakSet but IE11 doesn't support it. | ||
bindingsAdded.set(map, true); | ||
} | ||
|
||
canReflect.eachKey(map, function(callback, exp){ | ||
viewCallbacks.attr(exp, callback); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters