Skip to content

Conversation

@FredrikOseberg
Copy link
Contributor

No description provided.

React.useEffect(() => {
client.current.start();

return () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add client.current.stop here too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Could move the client.current.on calls into useEffect as well.

@renesansz
Copy link

Hi, looking forward for this fix to be merged, I agree that client.current.stop() should also be added in the useEffect cleanup 👍🏼

React.useEffect(() => {
client.current.start();

return () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Could move the client.current.on calls into useEffect as well.

Comment on lines +28 to +29
client.off('update');
client.off('ready');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we pass in the handlers here, to match the on calls above? Same for useVariant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was a bit unsure, but the tinyEmitter library says you can omit these: https://www.npmjs.com/package/tiny-emitter

Copy link
Contributor

@jtaaa jtaaa Mar 15, 2022

Choose a reason for hiding this comment

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

It looks to me like if the handlers are not passed, then all of the event handlers on the client will be removed for those events. This would mean that existing event handlers on a client passed into the FlagProvider would be reset when the FlagProvider is unmounted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks to me like if the handlers are not passed, then all of the event handlers on the client will be removed for those events. This would mean that existing event handlers on a client passed into the FlagProvider would be reset when the FlagProvider is unmounted.

Yeah, I agree with your assessment, and we will add the event handlers to the the off calls.

@jtaaa
Copy link
Contributor

jtaaa commented Mar 15, 2022

Maybe I should open a new issue for this (please let me know if I should!) but I'd like to make a case for only starting and stopping the unleash client if it is created via config. That would allow a custom client passed in to FlagProvider to be started and stopped independently of FlagProvider mounting.

One use case is delaying starting the client until custom properties of the unleash context are set. In order to get the initial query for flags to use these custom properties we would need to delay mounting the FlagProvider otherwise properties set after mounting will have to wait for the next interval to kick in. A cleaner solution might be to allow the creator of the client to handle starting and stopping.

Please let me know what you think and if I should expand in a new issue :)

@FredrikOseberg
Copy link
Contributor Author

FredrikOseberg commented Mar 15, 2022

Maybe I should open a new issue for this (please let me know if I should!) but I'd like to make a case for only starting and stopping the unleash client if it is created via config. That would allow a custom client passed in to FlagProvider to be started and stopped independently of FlagProvider mounting.

One use case is delaying starting the client until custom properties of the unleash context are set. In order to get the initial query for flags to use these custom properties we would need to delay mounting the FlagProvider otherwise properties set after mounting will have to wait for the next interval to kick in. A cleaner solution might be to allow the creator of the client to handle starting and stopping.

Please let me know what you think and if I should expand in a new issue :)

I think this at least will require another PR. Can you open an issue? I can see your use-case, but we'll need to think a bit on how to implement this as it would be a breaking change for anyone using the current approach. Might have to be a setting if we want to avoid a bump in the major version. If you have any other ideas, we can discuss them in the issue - also happy to receive a PR for this.

@FredrikOseberg
Copy link
Contributor Author

@Tymek Tymek marked this pull request as draft May 31, 2022 09:27
@stale
Copy link

stale bot commented Jul 6, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 6, 2022
@FredrikOseberg
Copy link
Contributor Author

Don't close.

@stale stale bot removed the stale label Jul 6, 2022
@stale
Copy link

stale bot commented Aug 5, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 5, 2022
@FredrikOseberg
Copy link
Contributor Author

Reopen.

@stale stale bot removed the stale label Aug 5, 2022
@stale
Copy link

stale bot commented Sep 4, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 4, 2022
@stale stale bot closed this Sep 14, 2022
@stale stale bot removed the stale label Oct 31, 2022
@thomasheartman thomasheartman mentioned this pull request Oct 31, 2022
@thomasheartman
Copy link
Contributor

@FredrikOseberg : what's the status on this? Any chance of it getting picked up?

@FredrikOseberg
Copy link
Contributor Author

Superseded by #96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants