launchdarkly / react-native-client-sdk

LaunchDarkly Client-side SDK for React Native
Other
47 stars 32 forks source link

Fetch flag state synchronously #49

Open dkwl93 opened 4 years ago

dkwl93 commented 4 years ago

Is your feature request related to a problem? Please describe. I was wondering if there was a way to fetch the flag state synchronously (based on cached values). I've gone through the documentation and example application and each evaluation seems to return a promise.

We use feature flags to flag navigation so It's important to us for flag evaluations to be instant.

Describe the solution you'd like Synchronous way of fetching flag state (boolean)

Describe alternatives you've considered Hand rolling a caching system with redux and redux-persist that gets written on launch with allFlags() and gets overwritten each time a flag changes.

Additional context React native

torchhound commented 4 years ago

Because we use native libraries for Android and iOS under the hood we return a promise. I will look into whether we can fetch flag state synchronously. Filed internally as 74438

dkwl93 commented 4 years ago

Thanks @torchhound Completely forgot about the bridge... I understand this seems easy but would be a big change. Appreciate your effort!

torchhound commented 3 years ago

Hi @dkwl93 we do not have a way to directly fetch flag state synchronously however in React Native 4.0 you can set a timeout on the flag fetch in both iOS and Android by passing an integer parameter to configure.

abhiin1947 commented 2 years ago

We hit this when migrating from the web SDK to the mobile one. The web SDK returns values synchronously but the mobile one does not. This actually requires a lot of loading states to be introduced in the app for us which makes it a no-go.

Would JSI be a possible solution here?

LucasEThomas commented 11 months ago

I wrote a wrapper library that exposes a getFeatureFlag() function that returns the latest flag value from its state synchronously. It also exposes some really nice hooks that just work. The library is still a bit new. It lacks tests and I haven't tested it on ios, but my team has been using it in our production Android app for a couple months without any issues.

https://www.npmjs.com/package/launch-darkly-react-native-client-factory