Beispiel #1
0
        internal void Flush()
        {
            var patch = Diff();

            if (patch == null)
            {
                return;
            }

            if (patch is NActionPatch) // Assign New UI
            {
#if DEBUG
                Debug.WriteLine("New UI for : " + this);
                Debug.WriteLine(_ui);
            }
            else
            {
                Debug.WriteLine("New UI Patch for : " + this);
                Debug.WriteLine(patch);
#endif
            }

            NPatch.OnUIThread(patch, i =>
            {
                BeginPatching();
                try
                {
                    Xaml = i.Apply(Xaml);
                }
                finally
                {
                    EndPatching();
                }
            });
        }
Beispiel #2
0
 internal virtual void Free()
 {
     for (var i = _props.Head; i != null; i = i.Next)
     {
         NPatch.Finalize(i._value);
     }
 }
Beispiel #3
0
        public static NPatch Diff(NElement oldE, ref NElement newE)
        {
            var oldSet = oldE != null;
            var newSet = newE != null;

            if (oldSet == newSet)
            {
                if (!oldSet)
                {
                    return(null);
                }

                if (NPatch.ElementEquals(oldE, newE))
                {
                    var oldC = oldE as NClass;
                    if (oldC != null)
                    {
                        var newC = (NClass)newE;
                        newE = oldE;
                        return(oldC.Upgrade(newC));
                    }

                    return(new NPropDiffer(oldE, newE).Diff());
                }
            }

            return(NPatch.AssignNewValue);
        }
Beispiel #4
0
        NPatch Diff()
        {
            var cOld = _source.Length;
            var cNew = _target.Length;

            if (cOld == 0 || cNew == 0)
            {
                return(NPatch.AssignNewValue);
            }

            var iOld = 0;
            var iNew = 0;
            var iFix = 0;

            for (;;)
            {
                var oldH = iOld < cOld;
                var oldE = oldH ? _source[iOld] : null;

                var newH = iNew < cNew;
                var newE = newH ? _target[iNew] : null;

                if (oldH)
                {
                    if (newH && NPatch.ElementEquals(oldE, newE))
                    {
                        Update(iOld + iFix, newE, oldE);
                        iNew++;
                    }
                    else
                    {
                        Remove(iOld + iFix, oldE);
                        iFix--;
                    }
                    iOld++;
                }
                else
                {
                    if (newH)
                    {
                        Insert(iOld + iFix, newE);
                        iOld++;
                        iNew++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Optimize();

            TransferClasses();

            return(_head != null ? new NListPatch(_head) : null);
        }
Beispiel #5
0
        internal override void Free()
        {
            Xaml = null;

            for (var i = _propsCommitted.Head; i != null; i = i.Next)
            {
                NPatch.Finalize(i._value);
            }

            for (var i = _stateCommitted.Head; i != null; i = i.Next)
            {
                NPatch.Finalize(i._value);
            }

            _ui?.Free();
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        static void SetRenderElement(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            NPatch.Finalize(args.OldValue);

            var e = (NElement)args.NewValue;

            if (e == null)
            {
                return;
            }

            var cc = d as ContentControl;

            if (cc != null)
            {
                cc.Render(e); return;
            }

            var uc = d as UserControl;

            if (uc != null)
            {
                uc.Render(e); return;
            }

#if !NETFX_CORE
            var w = d as Window;
            if (w != null)
            {
                w.Render(e); return;
            }
#endif

            var b = d as Border;
            if (b != null)
            {
                b.Render(e); return;
            }

            throw new NotSupportedException();
        }
Beispiel #8
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;
            }
        }
Beispiel #9
0
 public NProperty Property <T>(BindableProperty property, Func <object, object> converter = null) where T : BindableObject
 {
     return(Support(typeof(T), (t, v) => NPatch.AssignSingle((BindableObject)t, v, property, converter)));
 }
Beispiel #10
0
 public NProperty List <T>(Func <T, IList> getter /*, Action<T, IList> setter = null*/)
 {
     return(Support(typeof(T), (t, v) => NPatch.AssignList(getter((T)t), v)));
 }
Beispiel #11
0
 public static NProperty CreateRoot() => new NProperty(nameof(NProperties.Root)).
 Property <TableView>((t, v) => NPatch.AssignListT(t.Root, v));