Skip to content

Commit

Permalink
Added garbage collection for observables to ElementData.clear()
Browse files Browse the repository at this point in the history
Observables used in expressions will now get stored in
``elementData.observables`` before only data-query methods got stored
there.
Fixes astoilkov#90
  • Loading branch information
Joscha Rohmann committed Oct 3, 2015
1 parent 1af735a commit 7db227b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/query/ElementsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
// if element is not defined then treat it as expression
if (!element) {
currentData = data[id] = {
id: id
id: id,
observables: {}
};
} else {
currentData = data[id] = {
Expand Down Expand Up @@ -114,11 +115,21 @@
if (currentData && (!currentData.haveData || force)) {
blocks.each(currentData.observables, function (value) {
for (var i = 0; i < value._elements.length; i++) {
if (value._elements[i].elementId == data.id) {
if (value._elements[i].elementId == currentData.id) {
value._elements.splice(i, 1);
i--;
}
}

if (value._expressionKeys[currentData.id]) {
for (i = 0; i < value._expressions.length; i++) {
if (value._expressions[i].elementId == currentData.id) {
value._expressions.splice(i, 1);
i--;
}
}
value._expressionKeys[currentData.id] = null;
}
});
data[id] = undefined;
if (VirtualElement.Is(element)) {
Expand Down
2 changes: 2 additions & 0 deletions src/query/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ define([
observable._expressionKeys[elementData.id] = true;
observable._expressions.push(expressionObj);
}

elementData.observables[observable.__id__ + (attributeName || 'expression') + '[' + expression + ']'] = observable;
});
}
if (!attributeName) {
Expand Down

0 comments on commit 7db227b

Please sign in to comment.