Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise and improve cached factory handling with params #387

Merged

Conversation

ArtAhmetajCR
Copy link

This Pr references issue #382 where an assertion on the getObject method (and its async equivalent) blocks cached factories from having parameters passed.
The fix is adjusting the assertion to include the "cachedFactory" as a type.
While fixing this issue I also noticed that the lastParameters were not being saved in the cached factory section, which resulted in the cached factory functions being broken since this check always failed:

if (weakReferenceInstance?.target != null &&
              param1 == lastParam1 &&
              param2 == lastParam2)

Saving the lastParams when creating new instances fixes this.

Appropriate tests have been writen for the cached factory which were entirely missing earlier.

Copy link

@samirsimnica samirsimnica left a comment

Choose a reason for hiding this comment

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

LGTM!

@escamoteur
Copy link
Collaborator

@samirsimnica just curious, why could you approve this PR?

lib/get_it_impl.dart Outdated Show resolved Hide resolved
constructorCounter++;
}

void dispose() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you don't use the dispose in your test so the linter complains and the CI can't run.

Copy link
Author

Choose a reason for hiding this comment

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

I have removed the method given that its not used on the test class atm, added it for consistency since it was on other classes but I dont use dispose counter to assert anything atm, if you want I can add it with your guidance.

@escamoteur escamoteur merged commit d9f7485 into fluttercommunity:master Oct 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants