Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created October 22, 2012 20:31
Show Gist options
  • Save thefringeninja/3933964 to your computer and use it in GitHub Desktop.
Save thefringeninja/3933964 to your computer and use it in GitHub Desktop.
public class Item {
public ReactiveCommand Remove{ get; protected set; }
}
public class MyModel {
public ObservableCollection<Item> Items { get; protected set; }
}
MyModel model = new MyModel{Items = { new Item(), new Item() }};
this.Items = model.Items.CreateDerivedCollection(projectFunction);
// how to wire existing Item's RemoveIt command here?
// I had been enumerating the initial collection but it was ugly
// and was hoping for a better way.
//
// this.Items.ForEach(item => item.RemoveIt.Subscribe(_ => Items.Remove(item)));
this.WhenAny(x => x.Items, x => x.Value)
.Subscribe(c => c.ItemsAdded.Subscribe(item => item.RemoveIt.Subscribe(_ => Items.Remove(item))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment