当前位置: 首页>>代码示例>>C#>>正文


C# Store.Subscribe方法代码示例

本文整理汇总了C#中Store.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Store.Subscribe方法的具体用法?C# Store.Subscribe怎么用?C# Store.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Store的用法示例。


在下文中一共展示了Store.Subscribe方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_push_initial_state

        public void Should_push_initial_state()
        {
            var sut = new Store<int>(1, Reducers.PassThrough);
            var mockObserver = new MockObserver<int>();

            sut.Subscribe(mockObserver);

            CollectionAssert.AreEqual(new[] { 1 }, mockObserver.Values);
        }
开发者ID:anthonyliao,项目名称:redux.NET,代码行数:9,代码来源:StoreTests.cs

示例2: Should_only_push_the_last_state_before_subscription

        public void Should_only_push_the_last_state_before_subscription()
        {
            var sut = new Store<int>(1, Reducers.Replace);
            var mockObserver = new MockObserver<int>();

            sut.Dispatch(new FakeAction<int>(2));
            sut.Subscribe(mockObserver);

            CollectionAssert.AreEqual(new[] { 2 }, mockObserver.Values);
        }
开发者ID:anthonyliao,项目名称:redux.NET,代码行数:10,代码来源:StoreTests.cs

示例3: Should_push_state_to_end_of_queue_on_nested_dispatch

        public void Should_push_state_to_end_of_queue_on_nested_dispatch()
        {
            var sut = new Store<int>(1, Reducers.Replace);
            var mockObserver = new MockObserver<int>();
            sut.Subscribe(val =>
            {
                if (val < 5)
                {
                    sut.Dispatch(new FakeAction<int>(val + 1));
                }
                mockObserver.OnNext(val);
            });

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, mockObserver.Values);
        }
开发者ID:anthonyliao,项目名称:redux.NET,代码行数:15,代码来源:StoreTests.cs

示例4: Middleware_should_be_called_for_each_action_dispatched

        public void Middleware_should_be_called_for_each_action_dispatched()
        {
            var numberOfCalls = 0;
            Middleware<int> spyMiddleware = store => next => action =>
            {
                numberOfCalls++;
                return next(action);
            };

            var sut = new Store<int>(1, Reducers.Replace, spyMiddleware);
            var mockObserver = new MockObserver<int>();
            
            sut.Subscribe(mockObserver);
            sut.Dispatch(new FakeAction<int>(2));

            Assert.AreEqual(1, numberOfCalls);
            CollectionAssert.AreEqual(new[] { 1, 2 }, mockObserver.Values);
        }
开发者ID:anthonyliao,项目名称:redux.NET,代码行数:18,代码来源:StoreTests.cs

示例5: should_notify_subscribers_while_they_are_subscribed

        public void should_notify_subscribers_while_they_are_subscribed()
        {
            var reducer = new SimpleReducer<List<string>>(() => new List<string> {"Use ReduxVVM"});
            var store = new Store<List<string>>(reducer);

            var changed = 0;
            var unsub = store.Subscribe(state =>
            {
                Assert.NotNull(state);
                changed += 1;
            });

            store.Dispatch(new ItemAdded {item = "Read the Redux docs"});
            store.Dispatch(new ItemAdded {item = "Read the Redux docs"});

            Assert.That(changed, Is.EqualTo(2));
            unsub();
            store.Dispatch(new ItemAdded {item = ""});

            Assert.That(changed, Is.EqualTo(2));
        }
开发者ID:pshomov,项目名称:reducto,代码行数:21,代码来源:StoreTests.cs


注:本文中的Store.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。