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()); }
public App() { var reducer = new CompositeReducer <AppState>() .Part(s => s.DevicePage, DeviceListReducer()) .Part(s => s.LoginPage, LoginPageReducer()); Store = new Store <AppState>(reducer); }
public App() { var reducer = new CompositeReducer<AppState>() .Part(s => s.DevicePage, DeviceListReducer()) .Part(s => s.LoginPage, LoginPageReducer()); Store = new Store<AppState>(reducer); }
public AppStoreContainer() { var reducer = new CompositeReducer <AppState>() .Part(s => s.SearchState, SearchReducer.GetReducer()) .Part(s => s.DiscoverState, DiscoverReducer.GetReducer()) .Part(s => s.AuthenticationState, AuthenticationReducer.GetReducer()) .Part(s => s.FavoriteState, FavouriteReducer.GetReducer()) .Part(s => s.DataState, DataReducer.GetReducer()) .Part(s => s.MovieDetailsState, MovieDetailsReducer.GetReducer()) .Part(s => s.ReviewsState, ReviewsReducer.GetReducer()); Store = new Store <AppState>(reducer); }
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()); }
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(state => state.deliver, new SimpleReducer <DeliveryMethod>().When <BehindSchedule>((s, a) => DeliveryMethod.REGULAR) .When <SetDelivery>((_, a) => a.method)) .Part(state => state.addr, new SimpleReducer <Address>().When <SetDestination>((s, a) => a.newAddress)); var orderReducer = new CompositeReducer <Order>() .Part(state => state.origin, originReducer) .Part(state => state.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()); }
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(state => state.redditTopic, topicReducer) .Part(state => state.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()); }
public static void Init() { UnityIocService.AssertIsFirstInject(typeof(ReduxIoc)); //== 注入 redux 相关数据 var reducer = new CompositeReducer <AppState>() .Part(s => s.CpmState, CpmReducer.Create()) .Part(s => s.SysState, SysReducer.Create()) .Part(s => s.MqState, MqReducer.Create()) .Part(s => s.AlarmState, AlarmReducer.Create()) .Part(s => s.OeeState, OeeReducer.Create()) .Part(s => s.DMesState, DMesReducer.Create()) .Part(s => s.ViewStoreState, ViewStoreReducer.Create()) .Part(s => s.DpmStore, DpmReducer.Create()); var storePro = new StorePro <AppState>(reducer); //== 设置依赖注入 UnityIocService.RegisterGlobalDepend(storePro); UnityIocService.RegisterGlobalDepend <CpmCore>(); UnityIocService.RegisterGlobalDepend <CpmEffects>(); UnityIocService.RegisterGlobalDepend <SysService>(); UnityIocService.RegisterGlobalDepend <SysEffects>(); UnityIocService.RegisterGlobalDepend <MqService>(); UnityIocService.RegisterGlobalDepend <MqEffects>(); UnityIocService.RegisterGlobalDepend <MockEffects>(); UnityIocService.RegisterGlobalDepend <DbEffects>(); UnityIocService.RegisterGlobalDepend <DMesCore>(); UnityIocService.RegisterGlobalDepend <SchCore>(); UnityIocService.RegisterGlobalDepend <OeeCore>(); UnityIocService.RegisterGlobalDepend <AlarmCore>(); UnityIocService.RegisterGlobalDepend <ViewStoreCore>(); UnityIocService.RegisterGlobalDepend <DpmCore>(); UnityIocService.RegisterGlobalDepend <PipeEffects>(); UnityIocService.RegisterGlobalDepend <LoadEffects>(); UnityIocService.RegisterGlobalDepend <HookCore>(); }
public RxStore(CompositeReducer <TState> rootReducer) : base(rootReducer) { _stateChanged = new BehaviorSubject <TState>(GetState()); SubscribeToStateChange(); }
public StorePro(CompositeReducer <T> rootReducer) : base(rootReducer) { init(); }