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

fix: async not transpiled on babel for older browser #174

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FlagProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test('A consumer that subscribes AFTER client init shows values from provider an
'consuming value isEnabled true'
);
expect(screen.getByText(/consuming value updateContext/)).toHaveTextContent(
'consuming value updateContext [object Promise]'
'consuming value updateContext undefined'
);
expect(screen.getByText(/consuming value getVariant/)).toHaveTextContent(
'consuming value getVariant A'
Expand Down Expand Up @@ -148,7 +148,7 @@ test('A consumer should be able to get a variant when the client is passed into
'consuming value isEnabled true'
);
expect(screen.getByText(/consuming value updateContext/)).toHaveTextContent(
'consuming value updateContext [object Promise]'
'consuming value updateContext undefined'

Choose a reason for hiding this comment

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

Now the promise is consumed and because setting the context returns no value, this seems correct to me

Copy link
Member

@Tymek Tymek Oct 21, 2024

Choose a reason for hiding this comment

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

It will change the SDK behavior in a subtle way. We have a this binding in client.updateContext. I'm against changing it for the sake of end-of-life browsers.

async syntax is equivalent to

  updateContext: (context) => new Promise(
      (resolve) => (client.current.updateContext(context))?.then(resolve)
  ),

);
expect(screen.getByText(/consuming value getVariant/)).toHaveTextContent(
'consuming value getVariant A'
Expand Down
2 changes: 1 addition & 1 deletion src/FlagProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const FlagProvider: FC<PropsWithChildren<IFlagProvider>> = ({
() => ({
on: ((event, callback, ctx) => client.current.on(event, callback, ctx)) as IFlagContextValue['on'],
off: ((event, callback) => client.current.off(event, callback)) as IFlagContextValue['off'],
updateContext: async (context) => await client.current.updateContext(context),
updateContext: client.current.updateContext,
isEnabled: (toggleName) => client.current.isEnabled(toggleName),
getVariant: (toggleName) => client.current.getVariant(toggleName),
client: client.current,
Expand Down
Loading