-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
refactor: migrate widget side effects over to use.disposable
#235
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ TextEditingController _textEditingController( | |
WidgetSideEffectRegistrar use, { | ||
String? initialText, | ||
}) { | ||
final controller = use.memo(() => TextEditingController(text: initialText)); | ||
use.effect(() => controller.dispose, [controller]); | ||
return controller; | ||
return use.disposable( | ||
() => TextEditingController(text: initialText), | ||
(controller) => controller.dispose(), | ||
[initialText], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The controller should not be recreated if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TY |
||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering to rewrite it this way:
I've seen examples of passing the arguments as dependencies. But in this case, I thought there might be a reason not to pass them as deps. Am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i made the decision that it should keep the same controller instance here regardless of whether those params change, which is why I have that string of
..
s forduration
andreverseDuration
at the end.Normally, you should put any captured variables in the dependencies list, but this case is an exception since we don't want to return a new controller (at least I don't think that would be the desired behavior).