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); }
public void NoWatch() { Reaction reaction = null; reaction = Atom.Reaction(Lifetime, () => { // ReSharper disable once AccessToModifiedClosure AtomAssert.CurrentScopeIs(reaction); using (Atom.NoWatch) { AtomAssert.CurrentScopeIsNull(); using (Atom.NoWatch) { AtomAssert.CurrentScopeIsNull(); } AtomAssert.CurrentScopeIsNull(); } // ReSharper disable once AccessToModifiedClosure AtomAssert.CurrentScopeIs(reaction); }); }
public void ActivationOnTrackedRead() { var target = Atom.Computed(Lifetime, () => 1); Atom.Reaction(Lifetime, () => target.Get()); AtomAssert.That(target).IsActive(); }
public void AtomActivatedOnRead(string type) { var atom = type == "Value" ? Atom.Value(Lifetime, 1) : Atom.Computed(Lifetime, () => 1); atom.Get(); AtomAssert.That(atom).IsActive(); }
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(); }
public void DeactivationOnLifetimeDispose() { Atom <int> target; using (var nested = Lifetime.CreateNested()) { target = Atom.Computed(nested.Lifetime, () => 1); target.Get(); } AtomAssert.That(target).IsNotActive(); }
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()); }
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(); }
public void InactiveByDefault() { var target = Atom.Computed(Lifetime, () => 1); AtomAssert.That(target).IsNotActive(); }