public async Task ExampleUsage2() { var t = Log.MethodEntered("DataStoreExample2.ExampleUsage2"); // Add a thunk middleware to allow dispatching async actions: var thunkMiddleware = Middlewares.NewThunkMiddleware <MyAppState1>(); // aDD A logging middleware to log all dispatched actions: var loggingMiddleware = Middlewares.NewLoggingMiddleware <MyAppState1>(); // Add a recorder middleware to enable hot reload by replaying previously recorded actions: var recorder = new ReplayRecorder <MyAppState1>(); var recMiddleware = recorder.CreateMiddleware(); var undoable = new UndoRedoReducer <MyAppState1>(); // To allow undo redo on the full store wrap the main reducer with the undo reducer: var undoReducer = undoable.Wrap(MyReducers1.ReduceMyAppState1); var data = new MyAppState1(null, null, 0); // the initial immutable state var store = new DataStore <MyAppState1>(undoReducer, data, loggingMiddleware, recMiddleware, thunkMiddleware); store.storeName = "Store 1"; TestNormalDispatchOfActions(store); TestUndoAndRedo(store); await TestAsyncActions(store); await TestReplayRecorder(recorder, store); TestSkippableUndoActions(store); Log.MethodDone(t); }
private static DataStore <MyModel> NewDataStore() { MyModel model = new MyModel(null, ImmutableList <MyCircle> .Empty); Middleware <MyModel> exampleMiddleware = Middlewares.NewLoggingMiddleware <MyModel>(); UndoRedoReducer <MyModel> undoLogic = new UndoRedoReducer <MyModel>(); return(new DataStore <MyModel>(undoLogic.Wrap(MyReducer), model, exampleMiddleware)); }
public static async Task ShowIn(ViewStack viewStack) { MyModel model = new MyModel(null, ImmutableList <MyUser> .Empty); Middleware <MyModel> exampleMiddleware = Middlewares.NewLoggingMiddleware <MyModel>(); UndoRedoReducer <MyModel> undoLogic = new UndoRedoReducer <MyModel>(); DataStore <MyModel> store = new DataStore <MyModel>(undoLogic.Wrap(MyReducer), model, exampleMiddleware); MyPresenter presenter = new MyPresenter(); presenter.targetView = viewStack.ShowView("7GUIs_Task5_CRUD"); await presenter.LoadModelIntoView(store); }
private async Task TestReplayRecorderOnNewStore(ReplayRecorder <MyAppState1> recorder, MyAppState1 finalStateOfFirstStore) { var t = Log.MethodEntered("TestReplayRecorderOnNewStore"); // Connect the recorder to the new store: var recMiddleware = recorder.CreateMiddleware(); var undoable = new UndoRedoReducer <MyAppState1>(); var logging = Middlewares.NewLoggingMiddleware <MyAppState1>(); var data2 = new MyAppState1(null, null, 0); var store2 = new DataStore <MyAppState1>(undoable.Wrap(MyReducers1.ReduceMyAppState1), data2, logging, recMiddleware); store2.storeName = "Store 2"; // Replaying the recorder will now fill the second store with the same actions: await recorder.ReplayStore(); AssertEqualJson(finalStateOfFirstStore, store2.GetState()); Log.MethodDone(t); }
public static async Task ShowIn(ViewStack viewStack) { // Call model unit tests manually before the UI is shown: CellsModelTests.TestFromAndToRowName(); CellsModelTests.TestDataStoreTransitiveChanges(); CellsModel model = new CellsModel(ImmutableDictionary <CellPos, Cell> .Empty); Middleware <CellsModel> logging = Middlewares.NewLoggingMiddleware <CellsModel>(); UndoRedoReducer <CellsModel> undoLogic = new UndoRedoReducer <CellsModel>(); DataStore <CellsModel> store = new DataStore <CellsModel>(undoLogic.Wrap(CellsReducers.MainReducer), model, logging); MyPresenter presenter = new MyPresenter(); presenter.targetView = viewStack.ShowView("7GUIs_Task7_Cells"); await presenter.LoadModelIntoView(store); await TaskV2.Delay(2000); Toast.Show("Now simulating some table model changes.."); // Simulate changes in the model to check if the UI updates correctly: CellsModelTests.SimulateSomeChangesInModel(store); }