Skip to content

Commit

Permalink
Temporarily revert build for fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Mar 21, 2011
1 parent 347fdb3 commit 43eea24
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 81 deletions.
30 changes: 12 additions & 18 deletions build/output/knockout-latest.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunction

// "disposeWhenNodeIsRemoved" option both proactively disposes as soon as the node is removed using ko.removeNode(),
// plus adds a "disposeWhen" callback that, on each evaluation, disposes if the node was removed by some other means.
if ((typeof options["disposeWhenNodeIsRemoved"] == "object") && options["disposeWhenNodeIsRemoved"]) {
if (typeof options["disposeWhenNodeIsRemoved"] == "object") {
var nodeToWatch = options["disposeWhenNodeIsRemoved"];
ko.utils.domNodeDisposal.addDisposeCallback(nodeToWatch, function() {
dependentObservable.dispose();
Expand Down Expand Up @@ -1666,10 +1666,7 @@ ko.exportSymbol('ko.templateRewriting.applyMemoizedBindingsToNextSibling', ko.te

if (targetNodeOrNodeArray) {
var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);

var whenToDispose = function () { return (!firstTargetNode) || !ko.utils.domNodeIsAttachedToDocument(firstTargetNode); }; // Passive disposal (on next evaluation)
var activelyDisposeWhenNodeIsRemoved = (firstTargetNode && renderMode == "replaceNode") ? firstTargetNode.parentNode : firstTargetNode;

var whenToDispose = function () { return (!firstTargetNode) || !ko.utils.domNodeIsAttachedToDocument(firstTargetNode); };
return new ko.dependentObservable( // So the DOM is automatically updated when any dependency changes
function () {
// Support selecting template as a function of the data being rendered
Expand All @@ -1682,7 +1679,7 @@ ko.exportSymbol('ko.templateRewriting.applyMemoizedBindingsToNextSibling', ko.te
}
},
null,
{ 'disposeWhen': whenToDispose, 'disposeWhenNodeIsRemoved': activelyDisposeWhenNodeIsRemoved }
{ 'disposeWhen': whenToDispose }
);
} else {
// We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node
Expand All @@ -1693,6 +1690,8 @@ ko.exportSymbol('ko.templateRewriting.applyMemoizedBindingsToNextSibling', ko.te
};

ko.renderTemplateForEach = function (template, arrayOrObservableArray, options, targetNode) {
var whenToDispose = function () { return !ko.utils.domNodeIsAttachedToDocument(targetNode); };

return new ko.dependentObservable(function () {
var unwrappedArray = ko.utils.unwrapObservable(arrayOrObservableArray) || [];
if (typeof unwrappedArray.length == "undefined") // Coerce single value into array
Expand All @@ -1709,7 +1708,7 @@ ko.exportSymbol('ko.templateRewriting.applyMemoizedBindingsToNextSibling', ko.te

return executeTemplate(null, "ignoreTargetNode", templateName, arrayValue, options);
}, options);
}, null, { 'disposeWhenNodeIsRemoved': targetNode });
}, null, { 'disposeWhen': whenToDispose });
};

var templateSubscriptionDomDataKey = '__ko__templateSubscriptionDomDataKey__';
Expand Down Expand Up @@ -1836,10 +1835,10 @@ ko.exportSymbol('ko.utils.compareArrays', ko.utils.compareArrays);
// so that its children is again the concatenation of the mappings of the array elements, but don't re-map any array elements that we
// previously mapped - retain those nodes, and just insert/delete other ones

function mapNodeAndRefreshWhenChanged(containerNode, mapping, valueToMap) {
function mapNodeAndRefreshWhenChanged(mapping, valueToMap) {
// Map this array value inside a dependentObservable so we re-map when any dependency changes
var mappedNodes = [];
var dependentObservable = ko.dependentObservable(function() {
ko.dependentObservable(function() {
var newMappedNodes = mapping(valueToMap) || [];

// On subsequent evaluations, just replace the previously-inserted DOM nodes
Expand All @@ -1850,8 +1849,8 @@ ko.exportSymbol('ko.utils.compareArrays', ko.utils.compareArrays);
// of which nodes would be deleted if valueToMap was itself later removed
mappedNodes.splice(0, mappedNodes.length);
ko.utils.arrayPushAll(mappedNodes, newMappedNodes);
}, null, { 'disposeWhenNodeIsRemoved': containerNode, 'disposeWhen': function() { return (mappedNodes.length == 0) || !ko.utils.domNodeIsAttachedToDocument(mappedNodes[0]) } });
return { mappedNodes : mappedNodes, dependentObservable : dependentObservable };
}, null, { 'disposeWhen': function() { return (mappedNodes.length == 0) || !ko.utils.domNodeIsAttachedToDocument(mappedNodes[0]) } });
return mappedNodes;
}

ko.utils.setDomNodeChildrenFromArrayMapping = function (domNode, array, mapping, options) {
Expand Down Expand Up @@ -1881,9 +1880,6 @@ ko.exportSymbol('ko.utils.compareArrays', ko.utils.compareArrays);
break;

case "deleted":
// Stop tracking changes to the mapping for these nodes
lastMappingResult[lastMappingResultIndex].dependentObservable.dispose();

// Queue these nodes for later removal
ko.utils.arrayForEach(lastMappingResult[lastMappingResultIndex].domNodes, function (node) {
nodesToDelete.push({
Expand All @@ -1897,11 +1893,9 @@ ko.exportSymbol('ko.utils.compareArrays', ko.utils.compareArrays);
break;

case "added":
var mapData = mapNodeAndRefreshWhenChanged(domNode, mapping, editScript[i].value);
var mappedNodes = mapData.mappedNodes;

var mappedNodes = mapNodeAndRefreshWhenChanged(mapping, editScript[i].value);
// On the first evaluation, insert the nodes at the current insertion point
newMappingResult.push({ arrayEntry: editScript[i].value, domNodes: mappedNodes, dependentObservable: mapData.dependentObservable });
newMappingResult.push({ arrayEntry: editScript[i].value, domNodes: mappedNodes });
for (var nodeIndex = 0, nodeIndexMax = mappedNodes.length; nodeIndex < nodeIndexMax; nodeIndex++) {
var node = mappedNodes[nodeIndex];
nodesAdded.push({
Expand Down
Loading

0 comments on commit 43eea24

Please sign in to comment.