Пример #1
0
        public void BasicForReactivePropertySlim()
        {
            var rp  = new ReactivePropertySlim <string>();
            var rrp = rp.ToReadOnlyReactivePropertySlim();

            rp.Value = "xxxx";
            rp.Dispose();
        }
        public void UnsubscribeTest()
        {
            var rp        = new ReactivePropertySlim <int>(mode: ReactivePropertyMode.None);
            var collector = new List <(string, int)>();
            var a         = rp.Select(x => ("a", x)).Subscribe(collector.Add);
            var b         = rp.Select(x => ("b", x)).Subscribe(collector.Add);
            var c         = rp.Select(x => ("c", x)).Subscribe(collector.Add);

            rp.Value = 99;
            collector.Is(("a", 99), ("b", 99), ("c", 99));

            collector.Clear();
            a.Dispose();

            rp.Value = 40;
            collector.Is(("b", 40), ("c", 40));

            collector.Clear();
            c.Dispose();

            rp.Value = 50;
            collector.Is(("b", 50));

            collector.Clear();
            b.Dispose();

            rp.Value = 9999;
            collector.Count.Is(0);

            var d = rp.Select(x => ("d", x)).Subscribe(collector.Add);

            rp.Value = 9;
            collector.Is(("d", 9));

            rp.Dispose();
        }