From 0529b85f89bf873b78aa06197e94019d432133fa Mon Sep 17 00:00:00 2001 From: Albert Mulia Shintra Date: Tue, 6 Aug 2024 19:02:39 +0700 Subject: [PATCH 1/3] fix: async not transpiled on babel for older browser - old browser (chrome v50) gets error from the async await - despite attempt to transpile with babel-plugin-transform-async-to-generator, it still not transpiled on my compiler - solution is to update the codebase, since there is no value to return, might as well directly return the method result if it's a Promise --- src/FlagProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlagProvider.tsx b/src/FlagProvider.tsx index 3e5a742..2896cd8 100644 --- a/src/FlagProvider.tsx +++ b/src/FlagProvider.tsx @@ -107,7 +107,7 @@ const FlagProvider: FC> = ({ () => ({ 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: (context) => client.current.updateContext(context), isEnabled: (toggleName) => client.current.isEnabled(toggleName), getVariant: (toggleName) => client.current.getVariant(toggleName), client: client.current, From bf37fd442b638eba96d47facf72cadf1ad39e194 Mon Sep 17 00:00:00 2001 From: Albert Mulia Shintra Date: Mon, 2 Sep 2024 08:49:41 +0700 Subject: [PATCH 2/3] refactor: direct function updateContext --- src/FlagProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlagProvider.tsx b/src/FlagProvider.tsx index 2896cd8..828ea89 100644 --- a/src/FlagProvider.tsx +++ b/src/FlagProvider.tsx @@ -107,7 +107,7 @@ const FlagProvider: FC> = ({ () => ({ 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: (context) => client.current.updateContext(context), + updateContext: client.current.updateContext, isEnabled: (toggleName) => client.current.isEnabled(toggleName), getVariant: (toggleName) => client.current.getVariant(toggleName), client: client.current, From 1206a4fbc2f7981b34fa468610bd1c6764338c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Tue, 3 Sep 2024 16:10:32 +0200 Subject: [PATCH 3/3] Fix test --- src/FlagProvider.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlagProvider.test.tsx b/src/FlagProvider.test.tsx index 4061eed..8f158c8 100644 --- a/src/FlagProvider.test.tsx +++ b/src/FlagProvider.test.tsx @@ -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' @@ -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' ); expect(screen.getByText(/consuming value getVariant/)).toHaveTextContent( 'consuming value getVariant A'