Skip to content

Instantly share code, notes, and snippets.

View anaisbetts's full-sized avatar

Ani Betts anaisbetts

View GitHub Profile
IObservable<byte[]> mockReadBytesAsync()
{
// Wait ten seconds, then return the byte array
return Observable.Return(new byte[] {1,2,3}).Delay(TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler);
}
public class MyCoolViewModel: ReactiveObject
{
// Create a Property to store the results
ObservableAsPropertyHelper<byte[]> _BytesWeHaveRead;
public byte[] BytesWeHaveRead {
get { return _BytesWeHaveRead.Value; }
}
// The command we'll be testing
ReactiveAsyncCommand ReadBytesCommand { get; private set; }
public class NewUserViewModel : ReactiveObject
{
// This is ReactiveUI's version of implementing INotifyPropertyChanged
string _Password;
public string Password {
get { return _Password; }
set { this.RaiseAndSetIfChanged(x => x.Password, value); }
}
string _PasswordConfirmation;
public static void RegisterDepPropCallback(This DependencyObject owner, DependencyProperty property, EventHandler handler)
{
var dpd = DependencyPropertyDescriptor.FromProperty(property, owner.GetType());
dpd.AddValueChanged(owner, handler);
}
mainWindow.RegisterDepPropCallback(MainWindowClass.ViewModelProperty, (o,e) => {
Console.WriteLine("ViewModel changed!");
});
mainWindow.ObservableFromDP(x => x.ViewModel).Subscribe(x => {
Console.WriteLine("ViewModel changed!");
})
// This is Pseudo-Powershell :)
[1,2,3] | someService | someOtherService
// is like this in Rx.NET; the difference though is that we
// never wait anywhere.
new[]{1,2,3}.AsObservable()
.SelectMany(someService)
.SelectMany(someOtherService)
.Subscribe(Console.WriteLine);
[TestMethod]
public void TimerShouldFinishAfterThirtyMinutes()
{
(new TestScheduler()).With(sched => {
var lastState = BlockTimerViewState.Initialized;
bool isTimerStateDone = false;
var fixture = new BlockTimerViewModel(new BlockItem() {
Description = "Test Item"
});
// This works in C# (puts out 1..10, one each second), but the RxJS one
// waits 1 second then dumps out the entire Range:
Observable.Range(1,10)
.Select(x => Observable.Return(x).Delay(TimeSpan.FromMilliseconds(1000)))
.Concat()
// Here's a version I wrote that seems to work in CoffeeScript:
Rx.Observable.WorkingConcat = (x) ->
public IObservable<IObservedChange<object, object>> Changed {
get { return _reactiveHelper.Changed; }
}
public IObservable<IObservedChange<object, object>> Changing {
get { return _reactiveHelper.Changing; }
}
public IDisposable SuppressChangeNotifications() {
return _reactiveHelper.SuppressChangeNotifications();
// This is the WPF/Silverlight ObservableCollection, not from Rx at all!
ObservableCollection<MyCoolModel> modelCollection;
model.Length
>>> 4
// Create a View Model Collection that will track the Model collection
var viewModelCollection = modelCollection.CreateDerivedCollection(
x => new MyCoolViewModel(x));