public override IDisposable Subscribe(IObserver <Any> observer) { var reducer = new PagePushReducer(); var valueNode = new ValueNode(this.Parent, this.Page); var stateActionWriterNode = new StateActionWriterNode( valueNode, "page", StoreHolder, reducer ); return(stateActionWriterNode.Subscribe(observer)); }
public void ReduceTest() { var reducer = new PagePushReducer(); var state = new State(); state.SetValue <PageStack>(PageConst.StateStackKey, new PageStack()); state.SetValue <PageDefinition>(PageConst.StateDefinitionKey, new PageDefinition { PermanentScenes = new[] { "PermanentScene1" }, PageScenes = new[] { new PageScene { Name = "Page1", Scenes = new[] { "Scene1", "Scene2" }, }, new PageScene { Name = "Page2", Scenes = new[] { "Scene1", "Scene3" }, } } }); state.SetValue <IDictionary <string, bool> >(SceneConst.StateKey, new Dictionary <string, bool>() { { "Scene1", true }, { "Scene2", false }, { "Scene3", false }, { "Scene4", true }, { "PermanentScene1", true }, }); state.SetValue <PageStack>(PageConst.StateStackKey, new PageStack()); { var page = new Page { Name = "Page1", Data = null }; var action = new StateAction(reducer, "page", new Any(page)); state = reducer.Reduce(state, action); var stack = state.GetValue <PageStack>(PageConst.StateStackKey); Assert.That(stack.Count, Is.EqualTo(1)); Assert.That(stack.Peek().Name, Is.EqualTo("Page1")); var sceneMap = state.GetValue <IDictionary <string, bool> >(SceneConst.StateKey); Assert.That(sceneMap.Count, Is.EqualTo(5)); Assert.That(sceneMap["Scene1"], Is.True); Assert.That(sceneMap["Scene2"], Is.True); Assert.That(sceneMap["Scene3"], Is.False); Assert.That(sceneMap["Scene4"], Is.False); Assert.That(sceneMap["PermanentScene1"], Is.True); } { var page = new Page { Name = "Page2", Data = null }; var action = new StateAction(reducer, "page", new Any(page)); state = reducer.Reduce(state, action); var stack = state.GetValue <PageStack>(PageConst.StateStackKey); Assert.That(stack.Count, Is.EqualTo(2)); Assert.That(stack.Peek().Name, Is.EqualTo("Page2")); var sceneMap = state.GetValue <IDictionary <string, bool> >(SceneConst.StateKey); Assert.That(sceneMap.Count, Is.EqualTo(5)); Assert.That(sceneMap["Scene1"], Is.True); Assert.That(sceneMap["Scene2"], Is.False); Assert.That(sceneMap["Scene3"], Is.True); Assert.That(sceneMap["Scene4"], Is.False); Assert.That(sceneMap["PermanentScene1"], Is.True); } }