Example #1
0
        private async Task _handleSingleEvent(CollectionChanges <T> arg)
        {
            Logger?.Invoke(arg);

            foreach (var change in arg)
            {
                switch (change)
                {
                case IItemAdded <T> c:
                    await _addAt(c.Item, c.Index);

                    break;

                case IItemRemoved <T> c:
                    Target.RemoveAt(c.Index);
                    break;

                case ICleared <T> c:
                    Target.Clear();
                    break;

                case IReset <T> c:
                    Target.Clear();
                    foreach (var item in c.Items.ToArray())
                    {
                        await _addAt(item);
                    }
                    break;

                case IItemReplaced <T> c:
                    var vm = Target[c.Index];
                    await _readModel(c.ToItem, vm);

                    break;

                case IItemMoved <T> c:
                    Target.Move(c.FromIndex, c.ToIndex);
                    break;

                default:
                    break;
                }
            }
        }
Example #2
0
        private async Task _handleLoop()
        {
            CollectionChanges <T> current = null;

            try
            {
                while (true)
                {
                    current = await _handleQueue.ReceiveAsync(_handleCancelSource.Token);
                    await _handleSingleEvent(current);
                }
            }
            catch (TaskCanceledException)
            {
            }
            catch (OperationCanceledException)
            {
            }
        }
Example #3
0
 private Task _onEvent(CollectionChanges <T> arg)
 {
     _handleQueue.Post(arg);
     return(Task.CompletedTask);
 }
Example #4
0
 /// <summary>
 /// Converts a single CollectionChanges struct to an observable of DiffResult records. Note that each
 /// CollectionChanges instance is converted into a collection of DiffResult instances, and they are fired
 /// using the Immediate scheduler, to make sure they all run at the original order even when concatinated to
 /// other DiffResults
 /// </summary>
 public static IObservable <DiffResults <T> > ToDiffResult <T>(this CollectionChanges <T> source)
 {
     return(source
            .Select(change => change.ToDiffResult())
            .ToObservable(Scheduler.Immediate));
 }