本文整理汇总了C#中Store.GetState方法的典型用法代码示例。如果您正苦于以下问题:C# Store.GetState方法的具体用法?C# Store.GetState怎么用?C# Store.GetState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Store
的用法示例。
在下文中一共展示了Store.GetState方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: all_in_one_example
public async void all_in_one_example(){
var reducer = new SimpleReducer<AppState>()
.When<LoginStarted>((status, action) => {
status.Username = action.Username;
status.Token = "";
status.Status = LoginStatus.LoginInProgress;
return status;
})
.When<LoginSucceeded>((status, action) => {
status.Token = action.Token;
status.Status = LoginStatus.LoggedIn;
return status;
})
.When<LoginFailed>((status, action) => {
status.Status = LoginStatus.NotLoggedIn;
return status;
});
var store = new Store<AppState>(reducer);
var loginAsyncAction = store.asyncAction(async(dispatch, getState) => {
dispatch(new LoginStarted{Username = "John Doe"});
// faking authentication of user
await Task.Delay(500);
var authenticated = new Random().Next() % 2 == 0;
if (authenticated) {
dispatch(new LoginSucceeded{Token = "1234"});
} else {
dispatch(new LoginFailed());
}
return authenticated;
});
var logged = await store.Dispatch(loginAsyncAction);
if (logged){
Assert.That(store.GetState().Status, Is.EqualTo(LoginStatus.LoggedIn));
} else {
Assert.That(store.GetState().Status, Is.EqualTo(LoginStatus.NotLoggedIn));
}
}
示例2: should_prvide_way_to_combine_reducers
public void should_prvide_way_to_combine_reducers()
{
var topicReducer = new SimpleReducer<string>().When<TopicSet>((s, e) => e.topic);
var visibilityReducer = new SimpleReducer<bool>().When<FilterVisibility>((s, e) => e.visible);
var reducer = new CompositeReducer<AppStore>(() => new AppStore {redditTopic = "react", visibility = false})
.Part(s => s.redditTopic, topicReducer)
.Part(s => s.visibility, visibilityReducer);
var store = new Store<AppStore>(reducer);
store.Dispatch(new TopicSet {topic = "Redux is awesome"});
store.Dispatch(new FilterVisibility {visible = true});
Assert.AreEqual(new AppStore {redditTopic = "Redux is awesome", visibility = true}, store.GetState());
}
示例3: should_register_root_reducer_with_builder
public void should_register_root_reducer_with_builder()
{
var reducer = new SimpleReducer<List<string>>(() => new List<string> {"Use ReduxVVM"})
.When<ItemAdded>((state, action) =>
{
var newSatte = new List<string>(state);
newSatte.Add(action.item);
return newSatte;
})
.Get();
var store = new Store<List<string>>(reducer);
store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
CollectionAssert.AreEqual(store.GetState(), new List<string> {"Use ReduxVVM", "Read the Redux docs"});
}
示例4: should_register_root_reducer
public void should_register_root_reducer()
{
Reducer<List<string>> reducer = (List<string> state, Object action) =>
{
if (action.GetType() == typeof (InitStoreAction)) return new List<string> {"Use ReduxVVM"};
var newState = new List<string>(state);
switch (action.GetType().Name)
{
case "ItemAdded":
var concreteEv = (ItemAdded) action;
newState.Add(concreteEv.item);
break;
default:
break;
}
return newState;
};
var store = new Store<List<string>>(reducer);
store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
CollectionAssert.AreEqual(store.GetState(), new List<string> {"Use ReduxVVM", "Read the Redux docs"});
}
示例5: should_return_same_state_when_command_not_for_that_reducer
public void should_return_same_state_when_command_not_for_that_reducer()
{
var reducer = new SimpleReducer<List<string>>(() => new List<string> {"Use ReduxVVM"});
var store = new Store<List<string>>(reducer);
store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
CollectionAssert.AreEqual(store.GetState(), new List<string> {"Use ReduxVVM"});
}
示例6: should_prvide_way_to_create_deep_hierarchy_of_reducers
public void should_prvide_way_to_create_deep_hierarchy_of_reducers()
{
var originReducer = new SimpleReducer<Address>().When<SetOrigin>((s, e) => e.newAddress);
var destinationReducer = new CompositeReducer<Destination>()
.Part(s => s.deliver,
new SimpleReducer<DeliveryMethod>().When<BehindSchedule>((s, a) => DeliveryMethod.REGULAR)
.When<SetDelivery>((_, a) => a.method))
.Part(s => s.addr, new SimpleReducer<Address>().When<SetDestination>((s, a) => a.newAddress));
var orderReducer = new CompositeReducer<Order>()
.Part(s => s.origin, originReducer)
.Part(s => s.destination, destinationReducer);
var store = new Store<Order>(orderReducer);
store.Dispatch(new SetOrigin {newAddress = new Address {streetNr = "Laugavegur 26", city = "Reykjavík"}});
store.Dispatch(new SetDestination {newAddress = new Address {streetNr = "5th Avenue", city = "New York"}});
store.Dispatch(new SetDelivery {method = DeliveryMethod.GUARANTEED});
store.Dispatch(new BehindSchedule());
Assert.AreEqual(new Order
{
origin = new Address {streetNr = "Laugavegur 26", city = "Reykjavík"},
destination =
new Destination
{
addr = new Address {streetNr = "5th Avenue", city = "New York"},
deliver = DeliveryMethod.REGULAR
}
}, store.GetState());
}
示例7: GetState_should_return_the_latest_state
public void GetState_should_return_the_latest_state()
{
var sut = new Store<int>(1, Reducers.Replace);
sut.Dispatch(new FakeAction<int>(2));
Assert.AreEqual(2, sut.GetState());
}
示例8: GetState_should_return_initial_state
public void GetState_should_return_initial_state()
{
var sut = new Store<int>(1, Reducers.Replace);
Assert.AreEqual(1, sut.GetState());
}