Implement onBindableContainerDidLoad and onBindableContainerDidUnload on BindableContainer#117
Draft
killlilwinters wants to merge 7 commits into
Conversation
…stance by the reference count instead of a key value presence
IosifSuzuki
approved these changes
Jun 3, 2026
Sashe0
approved these changes
Jun 3, 2026
Collaborator
Author
|
Додав кешування:
Залишилось додати delayed onBindableCotnainerStateDidLoad callback, щоб ми не отримували колбек коли редюсер для нас ще nil і ми не можемо його читати + вигадати назви новим lifecycle методам. Edit: + тести, звичайно. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This merge request adds lifecycle hooks for bindable container state creation and teardown, so container-specific setup/cleanup can run exactly once per bound state instance rather than on every view appearance.
The problem addressed here is that
BindableContainerpreviously exposed only generic load/unload callbacks tied to the view lifecycle. That makes it hard to distinguish between:To solve this, the MR introduces reducer introspection and reference-count checks to detect whether a reducer for a given bindable container ID already exists and whether the current instance is the last one before unload. This allows calling dedicated hooks only when the bound state is first loaded or finally released.
An alternative would have been to move this logic fully into reducer/store internals and emit explicit state lifecycle events, but this implementation keeps the feature localized to bindable containers and existing reducer storage.
Changes Made
Added new bindable container lifecycle hooks:
onBindableContainerStateDidLoad(store:)onBindableContainerStateDidUnload(store:)Provided default no-op implementations so existing containers remain source-compatible.
Wired these new hooks through
BindableContainer.connected(...)intoConnectedContainer.Introduced
AnyBindableReducerto expose runtime metadata and reducer-instance checks:Made
BindableReducerconform toAnyBindableReducerby exposing:Extended
RCDictionarywith uniqueness detection:isUniquelyReferenced(key:)ReducerBox.referenceCountasprivate(set)so it can be inspected externally without allowing mutation.Updated
ConnectedContainerto invoke the new state lifecycle hooks conditionally:onBindableContainerStateDidLoadonly when no reducer exists yet for the container ID,onBindableContainerStateDidUnloadonly when the current reducer instance is the last active one.Added runtime-based reducer lookup in
ConnectedContainerusingRuntime.typeInfoto find the matchingBindableReducerinside app state by container type.ClickUp task
https://app.clickup.com/t/869dh0kpx