-
Notifications
You must be signed in to change notification settings - Fork 18
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
chore: implement initial flag fetch #294
chore: implement initial flag fetch #294
Conversation
… removing only one listener. Emit events on ready and failed. Better comments on dom api usage.
This pull request has been linked to Shortcut Story #219625: Implement initial flag fetch. |
async start() { | ||
try { | ||
this.flags = await fetchFlags(this.sdkKey, this.context, this.config, this.platform); | ||
this.emitter.emit('ready'); | ||
} catch (error: any) { | ||
this.logger.error(error); | ||
this.emitter.emit('error', error); | ||
this.emitter.emit('failed', error); | ||
} |
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.
This is new. This decouples the construction of the ldClient object and the initial poll. The decoupling gives consuming sdks more flexibility how they want initialization to proceed.
* @private | ||
*/ | ||
private saveListener(name: EventName, listener: EventListener) { | ||
private saveListener(name: EventName, originalListener: Function, customListener: Function) { |
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.
We need to save both the original listener and the custom listener in order to remove them both correctly from our own internal map and the javascript EventTarget object respectively.
@@ -98,7 +98,7 @@ export default interface LDOptions { | |||
* {@link LDClientDom.variationDetail} method. Since this increases the size of network requests, | |||
* such information is not sent unless you set this option to true. | |||
*/ | |||
evaluationReasons?: boolean; | |||
withReasons?: boolean; |
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.
This is a breaking api change. I'm making this consistent with the server sdks which I think is a good idea.
@@ -12,7 +13,7 @@ import type LDOptions from '../api/LDOptions'; | |||
import validators from './validators'; | |||
|
|||
export default class Configuration { | |||
public static DEFAULT_POLLING = 'https://clientsdk.launchdarkly.com'; | |||
public static DEFAULT_POLLING = 'https://sdk.launchdarkly.com'; |
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.
According to this confluence page, this is added as part of u2c and so should be the one used. I think either will work.
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.
Apologies, this is not done yet, but most of the functionality in this utils class is tested by its consumer, which is fetchFlags. I will get to this soon, in another PR.
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 don't see the need for a dom specific platform for now, so I have deleted this.
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.
Ah, yeah, platform dom needs to exist, but we should never use it in shared code. I misread this the first time and made a different comment.
sdk-client should work for any possible client platform. So it cannot have knowledge of platform dom.
But platform dom, or something, would need to exist for the browser SDK. We need to hide fetch
for instance, behind a platform. For me this is an immutable requirement.
For instance when we make the node client SDK, we should hoist the node platform out of server and share it. But it probably should be a different platform than browser. If we support node 16, which is currently an LTS, then we shouldn't use actual browser fetch as it was experimental.
The sdk-server only uses Platform, and then implementors can use more specific platforms.
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.
A concrete real example is that electron and node client SDKs should support proxies using the proxy agent. We would not want this code to be in sdk-client
it would be handled by the platform fetch and not affect browser at all.
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.
Ok I'll refactor fetch to use Platform.Requests.
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.
Ok. We need to determine a different base for you do use, because that base you have chosen has already been merged together with my features. So if you merge there, then you will have the mother of all merge conflicts when you want to eventually merge to main.
feat/merge-client-and-migrations
contains all of our changes combined, and if what I was going to merge when we are ready to release migrations.
If these changes don't hurt anything, then you could base it on feat/merge-client-and-migration
, and then it will get merged to main when we release migrations.
If it needs to be held back, then we should make a new feat/
branch.
I'll look at other things, but I wanted to get the base addressed.
@@ -49,6 +50,7 @@ | |||
"jest": "^29.6.1", | |||
"jest-diff": "^29.6.1", | |||
"jest-environment-jsdom": "^29.6.1", | |||
"jest-fetch-mock": "^3.0.3", |
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.
This has not been published in 4 years, which makes me pretty nervous.
): Promise<Flags> => { | ||
const fetchUrl = createFetchUrl(sdkKey, context, config); | ||
const fetchOptions: RequestInit = createFetchOptions(sdkKey, context, config, platform.info); | ||
const response = await fetch(fetchUrl, fetchOptions); |
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.
This (fetch) needs to come from the platform.
…plement-initial-flag-fetch
Ok I've merged changes from |
Co-authored-by: Ryan Lamb <[email protected]> Co-authored-by: LaunchDarklyReleaseBot <[email protected]>
…mock. (#297) Co-authored-by: LaunchDarklyReleaseBot <[email protected]>
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.
We should remove Dom from the name of this one. Can it just be LDClientImpl?
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.
Done
First attempt to implement an initial flag fetch followed by emitting events. I also added comments like this:
There are three right now: fetch, btoa and EventTarget. I left comments in the code for react native how to deal with these.