RuntimeAttribute CreateRuntimeNodeAttribute(Node node, TemplateNode tnode) { var ra = new RuntimeAttribute(node, tnode); node.Context = ra; return(ra); }
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. } } }
public static Patch Diff(RuntimeAttribute left, RuntimeAttribute right) { var patch = new Patch(left); patch.Walk(left, right); return(patch); }
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); } }
public void AppendChild(RuntimeAttribute ra) { var currentGroup = groupChildren.Count > 0 ? groupChildren.Last.Value : null; var currentTemplate = groupChildren.Count > 0 ? groupChildren.Last.Value.Template : null; if (currentTemplate != ra.template) { currentGroup = new TemplateChildGroup(ra.template); } currentGroup.Append(ra.node); ra.Parent = this; Children.Add(ra); }
static void PatchInsertChildRecursive(RuntimeAttribute attr, Bridge <T> bridge) { Queue <RuntimeAttribute> queue = new Queue <RuntimeAttribute>(); foreach (var child in attr.Children) { queue.Enqueue(child); } while (queue.Count > 0) { var ra = queue.Dequeue(); var pra = ra.Parent; ra.element = bridge.CreateElement(ra.node, ra.template.TagName, ra.StringAttr); pra.element?.OnAddChild(ra.element); foreach (var child in ra.Children) { queue.Enqueue(child); } } }
public PatchOperateRemove(RuntimeAttribute original) { this.vNode = original; }
public PatchOperateChange(RuntimeAttribute original, RuntimeAttribute newborn) { this.vNode = original; this.vPatch = newborn; }
public Patch(RuntimeAttribute original) { Original = original; }
public PatchOperateText(RuntimeAttribute vNode, string text) { this.vNode = vNode; this.text = text; }
public PatchOperateProperties(RuntimeAttribute original, Dictionary <AttributeDataBindExpress, object> pd) { this.vNode = original; this.PropertiesDiff = pd; }
public PatchOperateInsert(RuntimeAttribute parent, RuntimeAttribute newborn) { this.vNodePrent = parent; this.vPatch = newborn; }