Skip to content

Commit

Permalink
Fix keepalive behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed Jul 11, 2022
1 parent 97d9c43 commit 02a6b63
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Runtime/Core/AtomBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ public void Actualize(bool force = false)

protected void ObsoleteSubscribers()
{
if (subscribers == null)
if (subscribers != null)
{
return;
for (var i = 0; i < subscribersCount; i++)
{
subscribers[i].Obsolete();
}
}

for (var i = 0; i < subscribersCount; i++)
else if (options.Has(AtomOptions.AutoActualize))
{
subscribers[i].Obsolete();
AtomScheduler.Actualize(this);
}
}

Expand Down
47 changes: 46 additions & 1 deletion Tests/AtomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void ReactionUpdatesOnce()
AtomScheduler.Sync();
Assert.AreEqual("BB", watch);
}

[Test]
public void ReactionWithExceptionUpdatesOnce()
{
Expand Down Expand Up @@ -621,5 +621,50 @@ public void SubscriptionOnDisposedAtomDoesNotLeadToActualization()

AtomScheduler.Sync();
}

[Test]
public void SuspendOnInvalidationWithoutKeepAlive()
{
var num = 0;
var atom = Atom.Computed(Lifetime, () => num += 1, keepAlive: false);
atom.Get();

Assert.AreEqual(1, num);

atom.Invalidate();
AtomScheduler.Sync();

Assert.AreEqual(1, num);
}

[Test]
public void ActualizeOnInvalidationWithKeepAlive()
{
var num = 0;
var atom = Atom.Computed(Lifetime, () => num += 1, keepAlive: true);
atom.Get();

Assert.AreEqual(1, num);

atom.Invalidate();
AtomScheduler.Sync();

Assert.AreEqual(2, num);
}

[Test]
public void SuspendOnDeactivationWithKeepAlive()
{
var num = 0;
var atom = Atom.Computed(Lifetime, () => num += 1, keepAlive: true);
atom.Get();

Assert.AreEqual(1, num);

atom.Deactivate();
AtomScheduler.Sync();

Assert.AreEqual(1, num);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.codewriter.unimob",
"displayName": "UniMob",
"description": "Reactive state management for Unity",
"version": "2.1.3",
"version": "2.1.4",
"unity": "2019.3",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 02a6b63

Please sign in to comment.