示例#1
0
        internal NPatch Diff()
        {
            var update = _force || ShouldComponentUpdate(_props, _state, _propsCommitted, _stateCommitted);

            Commit();

            if (!update)
            {
                return(null);
            }

            var oldUI = _ui;
            var newUI = RenderUI();

            var patch = NPropDiffer.Diff(oldUI, ref newUI);

            //if (oldUI is NClass)  // oldUI represented by nested class which is assigned after NPropDiffer anyway
            //  return patch;

            _ui = newUI;

            if (patch == NPatch.AssignNewValue) // Assign New UI
            {
                patch = new NActionPatch(i =>
                {
                    var result = Xaml = newUI.Create();
                    oldUI?.Free();
                    return(result);
                });
            }

            return(patch);
        }
示例#2
0
        void Update(int idx, NElement newE, NElement oldE)
        {
            if (oldE is NClass)
            {
                _target[idx] = oldE; // transfer updated classes
            }
            var p = NPropDiffer.Diff(oldE, ref newE);

            if (p != null)
            {
                Add(new NListPatchEntry {
                    Op = NListPatchOp.Patch, Value = oldE, iFinal = idx, Patch = p
                });
            }
        }
示例#3
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;
            }
        }