Skip to content

Conversation

@yusinto
Copy link
Contributor

@yusinto yusinto commented Dec 20, 2023

This implements feedback from #326.

  • Run synchronization logic for all change events.
  • Removed ready event and use change instead.
  • Callback argument for change is now just a string array of flag keys.
  • Removed config options stream and useReport for now for this alpha.

@yusinto yusinto changed the title Yus/sdk client pr feedback chore: pr feedback Dec 20, 2023
@yusinto yusinto changed the title chore: pr feedback chore: localstorage pr feedback Dec 20, 2023
Comment on lines -10 to -12
client.on('ready', () => {
setState({ client });
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ready has been deleted in favor of a simpler design relying only on change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was used as the change callback argument but that's been simplified in favor of a string array of flag keys. This is no longer needed.

Comment on lines +126 to +129
// I'm not sure why but both runAllTimersAsync and runAllTicks are required
// here for the identify promise be resolved
await jest.runAllTimersAsync();
jest.runAllTicks();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be a bug in jest fake timers.

} else {
// manually resolve identify
this.logger.debug('No changes from PUT');
identifyResolve();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Callout: manually resolve the identify promise if there are no changes.

deserializeData: JSON.parse,
processJson: async (dataJson: Flags) => {
this.logger.debug(`Streamer PUT: ${Object.keys(dataJson)}`);
if (initializedFromStorage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed we'll always run the synchronization logic and emit change when there's a change.

this.logger.debug('Initializing all data from storage');
this.logger.debug('Using storage');

const changedKeys = calculateFlagChanges(this.flags, flagsStorage);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, like my comment above, always run the sync logic.

Comment on lines -199 to -206
* - `"ready"`: The client has finished starting up. This event will be sent regardless
* of whether it successfully connected to LaunchDarkly, or encountered an error
* and had to give up; to distinguish between these cases, see below.
* - `"initialized"`: The client successfully started up and has valid feature flag
* data. This will always be accompanied by `"ready"`.
* - `"failed"`: The client encountered an error that prevented it from connecting to
* LaunchDarkly, such as an invalid environment ID. All flag evaluations will
* therefore receive default values. This will always be accompanied by `"ready"`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ready has been removed. initialized is replaced by identifying. failed has been removed, in favor of error.

Copy link
Contributor Author

@yusinto yusinto Dec 20, 2023

Choose a reason for hiding this comment

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

I moved these types to its own folder under types/index.ts so they are easier to reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the config options stream and streamingDisabled for now. For this alpha, streaming will always be on.

expect(json).toEqual(mockResponse);
});

test('report', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed useReport from this alpha for now.

@yusinto yusinto merged commit 713221e into yus/sc-225809/use-localstorage-for-bootstrapping-rn-sdk Dec 20, 2023
@yusinto yusinto deleted the yus/sdk-client-pr-feedback branch December 20, 2023 20:47
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.

3 participants