Skip to content

fix: Idempotent start#23

Closed
plajdo wants to merge 2 commits into
mainfrom
fix/idempotent-start
Closed

fix: Idempotent start#23
plajdo wants to merge 2 commits into
mainfrom
fix/idempotent-start

Conversation

@plajdo

@plajdo plajdo commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Added check whether any subscriptions for current Reactor are active. This makes start function idempotent for callers, and effectively prevents creating duplicate subscriptions.

Condition: transform function must be free of side effects, as empty transform will be called multiple times, until first subscription is created for the Reactor.


Disabled auto-start of AnyReactor type-erased type.
Previously this auto-start behaviour caused incorrectly stored Combine/non-combine subscriptions to external events from viewModels. Subscriptions were being stored under the wrapper type, which caused confusion and non-clear event routing.


Effects:

Call to viewModel.start() now has to be explicit and will always be forwarded to correct concrete Reactor type.

@plajdo plajdo requested a review from andrej-jasso April 25, 2026 15:59
@plajdo plajdo self-assigned this Apr 25, 2026
@plajdo plajdo added the bug Something isn't working label Apr 25, 2026
@plajdo plajdo requested a review from MatusMistrik April 25, 2026 17:10
Comment thread README.md
@ViewModel var model: AnyReactor = MyViewModel().eraseToAnyReactor()
```

`AnyReactor` does not start the wrapped reactor automatically. Start it explicitly:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to go to BREAKING CHANGES section after.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plajdo can you please create an MD.file tracking the breaking changes for each version. Its easier to maintain if its part of the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot push to this branch anymore, I will create a new PR from fork. If changelog is needed, please create one separately.

However: I checked that this change should not affect any of company's projects, so no further changes are necessary (calling start manually was a recommended pattern anyway).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make Reactor.start() safe to call multiple times by avoiding duplicate external subscriptions, and changes AnyReactor lifecycle so the wrapped reactor is not auto-started (requiring explicit start() by callers).

Changes:

  • Added a subscription-existence guard to make Reactor.start() behave idempotently.
  • Disabled AnyReactor auto-start by removing base.start() from its initializer and updating its docs.
  • Updated README to instruct explicitly calling start() for AnyReactor.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Sources/GoodReactor/Core/Reactor.swift Adds guidance on transform() side effects and guards start() based on existing subscriptions.
Sources/GoodReactor/Core/Erased/AnyReactor.swift Removes implicit base.start() and updates lifecycle documentation for explicit starting.
README.md Documents explicit start() usage for AnyReactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/GoodReactor/Core/Reactor.swift
Comment thread Sources/GoodReactor/Core/Erased/AnyReactor.swift
Comment thread README.md
@plajdo

plajdo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Cannot push to this branch anymore, let's follow the changes at #25.

@plajdo plajdo closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants