Exemplo n.º 1
0
        protected override void DoPatch(NListPatchEntry i)
        {
            var idx = i.iFinal;
            var x   = _target[idx];
            var y   = i.Patch.Apply(x);

            if (!ReferenceEquals(x, y))
            {
                _target[idx] = y;
            }
        }
Exemplo n.º 2
0
        void Add(NListPatchEntry entry)
        {
            if (_tail != null)
            {
                _tail.Next = entry;
            }
            else
            {
                _head = entry;
            }

            _tail = entry;
        }
Exemplo n.º 3
0
        protected override void DoPatch(NListPatchEntry i)
        {
            var idx = i.iFinal;
            var x   = _target[idx];
            var y   = (UIElement)i.Patch.Apply(x);

            if (!ReferenceEquals(x, y))
            {
#if WPF
                _target.RemoveAt(idx);
                _target.Insert(idx, y);
#else
                _target[idx] = y;
#endif
            }
        }
Exemplo n.º 4
0
        protected override void DoMove(NListPatchEntry i)
        {
            var idx = i.iRemove;
            var x   = _target[idx];

            _target.RemoveAt(idx);

            var p = i.Patch;

            if (p != null)
            {
                x = (UIElement)p.Apply(x);
            }

            _target.Insert(i.iInsert, x);
        }
Exemplo n.º 5
0
        public void Run(NListPatchEntry head)
        {
            for (var i = head; i != null; i = i.Next)
            {
                switch (i.Op)
                {
                case NListPatchOp.Insert: DoInsert(i); break;

                case NListPatchOp.Remove: DoRemove(i); break;

                case NListPatchOp.Patch: DoPatch(i); break;

                case NListPatchOp.Move: DoMove(i); break;
                }

                NPatch.Finalize(i.Finalizer);
            }
        }
Exemplo n.º 6
0
        void OptimizeRemove(NListPatchEntry e)
        {
            var delta = 0;
            var oldE  = e.Finalizer;
            var last  = e;

            for (var i = e.Next; i != null; i = i.Next)
            {
                switch (i.Op)
                {
                case NListPatchOp.Insert:
                {
                    var newE = i.Value;

                    if (NPatch.ElementEquals(newE, oldE))
                    {
                        e.Op        = NListPatchOp.Move;                // transform to move
                        e.Finalizer = null;                             // remove finalizer
                        e.iInsert   = i.iInsert + delta;                // correct insert index at the time of move
                        e.iFinal    = i.iFinal;                         // preserve final index
                        e.Patch     = NPropDiffer.Diff(oldE, ref newE); // make patch
                        e.Value     = oldE;                             // preserve moved value

                        last.Next = i.Next;                             // delete insertion
                        return;
                    }
                    delta--;
                }
                break;

                case NListPatchOp.Remove:
                    delta++;
                    break;
                }
                last = i;
            }
        }
Exemplo n.º 7
0
 internal NListPatch(NListPatchEntry head)
 {
     _head = head;
 }
Exemplo n.º 8
0
 protected override void DoRemove(NListPatchEntry i)
 {
     _target.RemoveAt(i.iRemove);
 }
Exemplo n.º 9
0
 protected override void DoInsert(NListPatchEntry i)
 {
     _target.Insert(i.iInsert, (UIElement)i.Value.Create());
 }
Exemplo n.º 10
0
 protected abstract void DoMove(NListPatchEntry i);
Exemplo n.º 11
0
 protected abstract void DoPatch(NListPatchEntry i);
Exemplo n.º 12
0
 protected abstract void DoInsert(NListPatchEntry i);