launchdarkly / react-client-sdk

LaunchDarkly Client-side SDK for React.js
Other
79 stars 67 forks source link

File Data Source Feature Request #152

Open taschetto opened 1 year ago

taschetto commented 1 year ago

Is your feature request related to a problem? Please describe. In a team with many developers, it can be a hassle to share client-side ids and multiple environments on LaunchDarkly. We want developers to load and manage flags from a file - as we do on server-side SDKs.

Describe the solution you'd like In a local development environment, we want to turn the client offline so we can use a bootstrapped flag set. Ideally, this would behave just like reading flags from a file on server-side SDKs.

Describe alternatives you've considered

louis-launchdarkly commented 1 year ago

Hello @taschetto, Thank you for the feature request. I will discuss with the React engineer about this feature and let you know our thoughts about this.

Filed Internally as 222973.

boxgames1 commented 1 year ago

@louis-launchdarkly any news on this?

avinayak commented 1 year ago

Hacky way to do this if someone needs it..

import LDContext from "launchdarkly-react-client-sdk/lib/context";
import flags from "ld_offline_flags.json";

const withLDProvider = (Component: React.ComponentType) => (
      props: React.ComponentProps<typeof Component>,
    ) => (
      <LDContext.Provider
        value={{
          flags,
          flagKeyMap: {},
          ldClient: {
            allFlags: () => flags,
            identify: () => new Promise(() => {}),
            on: () => new Promise(() => {}),
            waitUntilGoalsReady: () => new Promise(() => {}),
            track: () => new Promise(() => {}),
            variation: () => new Promise(() => {}),
            waitUntilReady: () => new Promise(() => {}),
            waitForInitialization: () => new Promise(() => {}),
            flush: () => new Promise(() => {}),
            getUser: () => ({}),
            variationDetail: () => ({
              value: false,
              variation: 0,
              reason: {
                kind: `ERROR`,
                errorKind: `FLAG_NOT_FOUND`,
              },
            }),
            setStreaming: () => new Promise(() => {}),
            off: () => new Promise(() => {}),
            alias: () => new Promise(() => {}),
            close: () => new Promise(() => {}),
          },
        }}
      >
        <Component {...props} />
      </LDContext.Provider>
    );
taschetto commented 1 year ago

I went with https://github.com/tdeekens/flopflip.