private void Update <T>(ObservableArrayArgs <T> arg) { var numOfElement = 0; Context = arg.Element; switch (arg.Action) { case ObservableAction.Push: arg.Renderer.Call(arg.Element, arg.Item, arg.Index); break; case ObservableAction.Add: if (arg.Index == arg.Array.Length - 1) { arg.Renderer.Call(arg.Element, arg.Item, arg.Index); return; } var div = new HTMLDivElement(); Context = div; arg.Renderer.Call(div, arg.Item, arg.Index); AppendChildList(arg.Element, div, arg.Index); break; case ObservableAction.Remove: numOfElement = arg.Element.Children.Length / (arg.Array.Length + 1); RemoveChildList(arg.Element, arg.Index, numOfElement); break; case ObservableAction.Move: numOfElement = arg.Element.Children.Length / arg.Array.Length; var newIndex = arg.Index; var oldIndex = Array.IndexOf(arg.Array, arg.Item); if (newIndex == oldIndex) { return; } var firstOldElementIndex = oldIndex * numOfElement; var nodeToInsert = oldIndex < newIndex ? arg.Element.Children[(newIndex + 1) * numOfElement] : arg.Element.Children[newIndex * numOfElement]; for (var j = 0; j < numOfElement; j++) { arg.Element.InsertBefore(arg.Element.Children[firstOldElementIndex], nodeToInsert); if (oldIndex > newIndex) { firstOldElementIndex++; } } break; case ObservableAction.Render: ClearContextContent(); var length = arg.Array.Length; var i = -1; while (++i < length) { Context = arg.Element; arg.Renderer.Call(arg.Element, arg.Array[i], i); } break; } }
private void NotifyArrayChanged(ObservableArrayArgs <T> arg) { var isBeingExecuted = _exeStack.Contains(this); if (isBeingExecuted) { return; } _exeStack.Add(this); _subscribers.ForEach((subscriber) => { subscriber(arg); }); _dependencies.ForEach((dpc) => { dpc.NotifyChange(); }); _exeStack.Remove(this); }