void Walk(RuntimeAttribute a, RuntimeAttribute b) { if (a == b) { return; } var group = new PatchGroup(); if (a != null && a.IsThunk && b != null && b.IsThunk) // diff thunk { // TODO: .... //var patchDiff = Diff(a, b); //if (patchDiff.HasPatch) //{ // group.Append(new PatchOperateThunk(patchDiff)); //} } else if (b == null) { group.Append(new PatchOperateRemove(a)); } else if (a.template.TagName == b.template.TagName && a.template.Key == b.template.Key) { //// diff once function //var needToExecute = DiffOnceExpresstion(a.onceExecuteFunc, b.onceExecuteFunc); //if (needToExecute != null) //{ // group.Append(new PatchOperateOnceFunc(a, needToExecute, b.onceExecuteFunc)); //} // diff properties var propsPatch = DiffProperties(a.attributes, b.attributes); if (propsPatch != null && propsPatch.Count > 0) { group.Append(new PatchOperateProperties(a, propsPatch)); } if (a.textDataBindExpressCurrentValue != b.textDataBindExpressCurrentValue) { group.Append(new PatchOperateText(a, b.textDataBindExpressCurrentValue)); } DiffChildren(a, b, group); } else { group.Append(new PatchOperateChange(a, b)); //// change the a & b //// execute once function //group.Append(new PatchOperateOnceFunc(b, b.template.onceExpressList, b.onceExecuteFunc)); } if (group.HasChange) { groupList.AddLast(group); } }
void DiffChildren(RuntimeAttribute a, RuntimeAttribute b, PatchGroup group) { var aChildren = a.Children; var bChildren = b.Children; var aLen = aChildren.Count; var bLen = bChildren.Count; var len = aLen > bLen ? aLen : bLen; var leftIter = aChildren.GetEnumerator(); var rightIter = bChildren.GetEnumerator(); for (int i = 0; i < len; i++) { var leftNode = leftIter.MoveNext() ? leftIter.Current : null; var rightNode = rightIter.MoveNext() ? rightIter.Current : null; if (leftNode == null) { if (rightNode != null) { // Excess nodes in b need to be added group.Append(new PatchOperateInsert(a, rightNode)); //// execute once function //group.Append(new PatchOperateOnceFunc(rightNode, rightNode.template.onceExpressList, rightNode.onceExecuteFunc)); } } else { Walk(leftNode, rightNode); // change it or remove it. } } }