This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainWindow.ObservableFromDP(x => x.ViewModel).Subscribe(x => { | |
Console.WriteLine("ViewModel changed!"); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); |