示例#1
0
        RuntimeAttribute CreateRuntimeNodeAttribute(Node node, TemplateNode tnode)
        {
            var ra = new RuntimeAttribute(node, tnode);

            node.Context = ra;
            return(ra);
        }
示例#2
0
                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.
                        }
                    }
                }
示例#3
0
                public static Patch Diff(RuntimeAttribute left, RuntimeAttribute right)
                {
                    var patch = new Patch(left);

                    patch.Walk(left, right);
                    return(patch);
                }
示例#4
0
                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);
                    }
                }
示例#5
0
            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);
            }
示例#6
0
            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);
                    }
                }
            }
示例#7
0
 public PatchOperateRemove(RuntimeAttribute original)
 {
     this.vNode = original;
 }
示例#8
0
 public PatchOperateChange(RuntimeAttribute original, RuntimeAttribute newborn)
 {
     this.vNode  = original;
     this.vPatch = newborn;
 }
示例#9
0
 public Patch(RuntimeAttribute original)
 {
     Original = original;
 }
示例#10
0
 public PatchOperateText(RuntimeAttribute vNode, string text)
 {
     this.vNode = vNode;
     this.text  = text;
 }
示例#11
0
 public PatchOperateProperties(RuntimeAttribute original, Dictionary <AttributeDataBindExpress, object> pd)
 {
     this.vNode          = original;
     this.PropertiesDiff = pd;
 }
示例#12
0
 public PatchOperateInsert(RuntimeAttribute parent, RuntimeAttribute newborn)
 {
     this.vNodePrent = parent;
     this.vPatch     = newborn;
 }