Skip to content

Commit

Permalink
Add comments about domData choices.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Jul 22, 2017
1 parent 6c02fe1 commit c87ad68
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils.domData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ ko.utils.domData = new (function () {

var getDataForNode, clear;
if (!ko.utils.ieVersion) {
// We considered using WeakMap, but it has a problem in IE 11 and Edge that prevents using
// it cross-window, so instead we just store the data directly on the node.
// See https://github.com/knockout/knockout/issues/2141
getDataForNode = function (node, createIfNotFound) {
var dataForNode = node[dataStoreKeyExpandoPropertyName];
if (!dataForNode && createIfNotFound) {
Expand All @@ -16,11 +19,13 @@ ko.utils.domData = new (function () {
clear = function (node) {
if (node[dataStoreKeyExpandoPropertyName]) {
delete node[dataStoreKeyExpandoPropertyName];
return true;
return true; // Exposing "did clean" flag purely so specs can infer whether things have been cleaned up as intended
}
return false;
};
} else {
// Old IE versions have memory issues if you store objects on the node, so we use a
// separate data storage and link to it from the node using a string key.
getDataForNode = function (node, createIfNotFound) {
var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
var hasExistingDataStore = dataStoreKey && (dataStoreKey !== "null") && dataStore[dataStoreKey];
Expand Down

0 comments on commit c87ad68

Please sign in to comment.