Ejemplo n.º 1
0
        public void WatchedCyclicDependency()
        {
            Atom <int> a, b = null;

            a = Atom.Computed(Lifetime, () => b.Value, debugName: "A");
            b = Atom.Computed(Lifetime, () => a.Value, debugName: "B");

            Exception exception = null;

            var reaction = Atom.Reaction(Lifetime, () =>
            {
                a.Get();
                b.Get();
            }, ex => exception = ex, debugName: "Reaction");

            AtomAssert.That(a).SubscribersCountAreEqualTo(1);
            AtomAssert.That(b).SubscribersCountAreEqualTo(1);

            AtomAssert.That(a).IsSubscribedTo(b);
            AtomAssert.That(reaction).IsSubscribedTo(a);

            Assert.Throws <CyclicAtomDependencyException>(() => a.Get());
            Assert.Throws <CyclicAtomDependencyException>(() => b.Get());
            Assert.IsTrue(exception is CyclicAtomDependencyException);
        }
Ejemplo n.º 2
0
        public void ActivationOnTrackedRead()
        {
            var target = Atom.Computed(Lifetime, () => 1);

            Atom.Reaction(Lifetime, () => target.Get());

            AtomAssert.That(target).IsActive();
        }
Ejemplo n.º 3
0
        public void AtomActivatedOnRead(string type)
        {
            var atom = type == "Value" ? Atom.Value(Lifetime, 1) : Atom.Computed(Lifetime, () => 1);

            atom.Get();

            AtomAssert.That(atom).IsActive();
        }
Ejemplo n.º 4
0
        public void KeepActiveOnUnsubscribe()
        {
            var target = Atom.Computed(Lifetime, () => 1);

            using (var nested = Lifetime.CreateNested())
            {
                Atom.Reaction(nested.Lifetime, () => target.Get());
            }

            AtomAssert.That(target).SubscribersCountAreEqualTo(0);
            AtomAssert.That(target).IsActive();
        }
Ejemplo n.º 5
0
        public void DeactivationOnLifetimeDispose()
        {
            Atom <int> target;

            using (var nested = Lifetime.CreateNested())
            {
                target = Atom.Computed(nested.Lifetime, () => 1);
                target.Get();
            }

            AtomAssert.That(target).IsNotActive();
        }
Ejemplo n.º 6
0
        public void UnwatchedCyclicDependency()
        {
            Atom <int> a, b = null;

            a = Atom.Computed(Lifetime, () => b.Value);
            b = Atom.Computed(Lifetime, () => a.Value);

            AtomAssert.That(a).SubscribersCountAreEqualTo(0);
            AtomAssert.That(b).SubscribersCountAreEqualTo(0);
            Assert.Throws <CyclicAtomDependencyException>(() => a.Get());
            Assert.Throws <CyclicAtomDependencyException>(() => b.Get());
        }
Ejemplo n.º 7
0
        public void UnwatchedPullOfObsoleteActiveAtom()
        {
            var source   = Atom.Value(Lifetime, 0);
            var computed = Atom.Computed(Lifetime, () => source.Value + 1);

            var reaction = Atom.Reaction(Lifetime, () => computed.Get());

            AtomAssert.That(computed).IsActive();
            AtomAssert.That(computed).ChildrenCountAreEqualTo(1);

            using (Atom.NoWatch)
            {
                // make source obsolete
                source.Value = 1;
                // pull new value in unwatched scope
                // dependencies must persist
                Assert.AreEqual(2, computed.Value);
            }

            AtomAssert.That(computed).ChildrenCountAreEqualTo(1);

            reaction.Deactivate();
        }
Ejemplo n.º 8
0
        public void InactiveByDefault()
        {
            var target = Atom.Computed(Lifetime, () => 1);

            AtomAssert.That(target).IsNotActive();
        }