本文整理汇总了C#中Store.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Store.Subscribe方法的具体用法?C# Store.Subscribe怎么用?C# Store.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Store
的用法示例。
在下文中一共展示了Store.Subscribe方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_push_initial_state
public void Should_push_initial_state()
{
var sut = new Store<int>(1, Reducers.PassThrough);
var mockObserver = new MockObserver<int>();
sut.Subscribe(mockObserver);
CollectionAssert.AreEqual(new[] { 1 }, mockObserver.Values);
}
示例2: Should_only_push_the_last_state_before_subscription
public void Should_only_push_the_last_state_before_subscription()
{
var sut = new Store<int>(1, Reducers.Replace);
var mockObserver = new MockObserver<int>();
sut.Dispatch(new FakeAction<int>(2));
sut.Subscribe(mockObserver);
CollectionAssert.AreEqual(new[] { 2 }, mockObserver.Values);
}
示例3: Should_push_state_to_end_of_queue_on_nested_dispatch
public void Should_push_state_to_end_of_queue_on_nested_dispatch()
{
var sut = new Store<int>(1, Reducers.Replace);
var mockObserver = new MockObserver<int>();
sut.Subscribe(val =>
{
if (val < 5)
{
sut.Dispatch(new FakeAction<int>(val + 1));
}
mockObserver.OnNext(val);
});
CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, mockObserver.Values);
}
示例4: Middleware_should_be_called_for_each_action_dispatched
public void Middleware_should_be_called_for_each_action_dispatched()
{
var numberOfCalls = 0;
Middleware<int> spyMiddleware = store => next => action =>
{
numberOfCalls++;
return next(action);
};
var sut = new Store<int>(1, Reducers.Replace, spyMiddleware);
var mockObserver = new MockObserver<int>();
sut.Subscribe(mockObserver);
sut.Dispatch(new FakeAction<int>(2));
Assert.AreEqual(1, numberOfCalls);
CollectionAssert.AreEqual(new[] { 1, 2 }, mockObserver.Values);
}
示例5: should_notify_subscribers_while_they_are_subscribed
public void should_notify_subscribers_while_they_are_subscribed()
{
var reducer = new SimpleReducer<List<string>>(() => new List<string> {"Use ReduxVVM"});
var store = new Store<List<string>>(reducer);
var changed = 0;
var unsub = store.Subscribe(state =>
{
Assert.NotNull(state);
changed += 1;
});
store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
Assert.That(changed, Is.EqualTo(2));
unsub();
store.Dispatch(new ItemAdded {item = ""});
Assert.That(changed, Is.EqualTo(2));
}