public override DataState Reduce(DataState state = null, object action = null) { if (state == null) { return(initialState); } var addEntity1Action = action as AddEntity1Action; if (addEntity1Action != null) { var newEntity1 = new Entitiy1(addEntity1Action.Id, addEntity1Action.Value); return(new DataState( entities1: state.Entities1.Add(addEntity1Action.Id, newEntity1), entities2: state.Entities2 )); } var addEntity2Action = action as AddEntity2Action; if (addEntity2Action != null) { var newEntity2 = new Entitiy2(addEntity2Action.Id, addEntity2Action.Value); return(new DataState( entities1: state.Entities1, entities2: state.Entities2.Add(addEntity2Action.Id, newEntity2) )); } return(state); }
public override ApplicationState Reduce(ApplicationState state = null, object action = null) { if (state == null) { return(initialState); } var toggleVisibilityAction = action as ToggleVisibilityAction; if (toggleVisibilityAction != null) { return(new ApplicationState( ui: new UIState(isVisible: !state.UI.IsVisible), data: state.Data )); } var addEntity1Action = action as AddEntity1Action; if (addEntity1Action != null) { var newEntity1 = new Entitiy1(addEntity1Action.Id, addEntity1Action.Value); return(new ApplicationState( ui: state.UI, data: new DataState( entities1: state.Data.Entities1.Add(addEntity1Action.Id, newEntity1), entities2: state.Data.Entities2 ) )); } var addEntity2Action = action as AddEntity2Action; if (addEntity2Action != null) { var newEntity2 = new Entitiy2(addEntity2Action.Id, addEntity2Action.Value); return(new ApplicationState( ui: state.UI, data: new DataState( entities1: state.Data.Entities1, entities2: state.Data.Entities2.Add(addEntity2Action.Id, newEntity2) ) )); } return(state); }