Skip to content

Commit

Permalink
Store data on the node itself (except in old IE), rather than using W…
Browse files Browse the repository at this point in the history
…eakMap.
  • Loading branch information
mbest committed Jul 22, 2017
1 parent 199fdb2 commit 6c02fe1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/utils.domData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ ko.utils.domData = new (function () {
var dataStore = {};

var getDataForNode, clear;
if (window['WeakMap']) {
if (!ko.utils.ieVersion) {
getDataForNode = function (node, createIfNotFound) {
var ownerDoc = node.ownerDocument,
dataStore = ownerDoc[dataStoreKeyExpandoPropertyName] || (ownerDoc[dataStoreKeyExpandoPropertyName] = new ownerDoc.defaultView['WeakMap']());
if (dataStore['has'](node)) {
return dataStore.get(node);
}
if (createIfNotFound) {
var dataForNode = {};
dataStore.set(node, dataForNode);
return dataForNode;
var dataForNode = node[dataStoreKeyExpandoPropertyName];
if (!dataForNode && createIfNotFound) {
dataForNode = node[dataStoreKeyExpandoPropertyName] = {};
}
return dataForNode;
};
clear = function (node) {
var dataStore = node.ownerDocument[dataStoreKeyExpandoPropertyName];
return dataStore ? dataStore['delete'](node) : false;
if (node[dataStoreKeyExpandoPropertyName]) {
delete node[dataStoreKeyExpandoPropertyName];
return true;
}
return false;
};
} else {
getDataForNode = function (node, createIfNotFound) {
Expand Down

0 comments on commit 6c02fe1

Please sign in to comment.