Skip to content

Commit

Permalink
Support remove range on collection as part as issue #105
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Feb 16, 2019
1 parent 9ae3678 commit aa5eb18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Neutronium.Core/Binding/GlueObject/JSArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public BridgeUpdater GetMoveUpdater(int oldIndex, int newIndex)
return new BridgeUpdater(viewModelUpdater => MoveJavascriptCollection(viewModelUpdater, item.GetJsSessionValue(), oldIndex, newIndex));
}

public BridgeUpdater GetRemoveUpdater(int index)
public BridgeUpdater GetRemoveUpdater(int index, int count)
{
var bridgeUpdater = new BridgeUpdater(viewModelUpdater => Splice(viewModelUpdater, index, 1));
var bridgeUpdater = new BridgeUpdater(viewModelUpdater => Splice(viewModelUpdater, index, count));
var old = Items[index];
Items.RemoveAt(index);
return CheckForRemove(bridgeUpdater, old);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private BridgeUpdater GetBridgeUpdater(JsArray array)
return array.GetReplaceUpdater(newValue, _Change.NewStartingIndex);

case NotifyCollectionChangedAction.Remove:
return array.GetRemoveUpdater(_Change.OldStartingIndex);
return array.GetRemoveUpdater(_Change.OldStartingIndex, _Change.OldItems.Count);

case NotifyCollectionChangedAction.Reset:
return array.GetResetUpdater(); ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,34 @@ public async Task TwoWay_Collection_Updates_After_InsertRange_Changes()
await RunAsync(test);
}


[Fact]
public async Task TwoWay_Collection_Updates_After_RemoveRange_Changes()
{
var dataContext = new VmWithRangeCollection();
dataContext.List.AddRange(new[] { 1, 2, 3, 4, 5 });
var test = new TestInContextAsync()
{
Bind = (win) => HtmlBinding.Bind(win, dataContext, JavascriptBindingMode.TwoWay),
Test = async (mb) =>
{
var js = mb.JsRootObject;
DoSafeUI(() =>
{
dataContext.List.RemoveRange(1, 3);
});
await Task.Delay(500);
var col = GetCollectionAttribute(js, "List");
col.Should().NotBeNull();
CheckIntCollection(col, new[] { 1, 5 });
}
};

await RunAsync(test);
}

[Fact]
public async Task TwoWay_Collection_Updates_CSharp_From_JS_Update()
{
Expand Down

0 comments on commit aa5eb18

Please sign in to comment.