launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
109 stars 62 forks source link

Add a custom function name for amd.define #297

Closed afholderman closed 2 months ago

afholderman commented 3 months ago

Requirements

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

yusinto commented 3 months ago

Our umd package should work with amd as well and I have verified this. The issue is if requirejs or amd is used, please use the named import rather than window.LDClient.

define(["jquery", "//unpkg.com/launchdarkly-js-client-sdk"], function (
  $,
  LDClient, // NOTE: use this named import instead of window.LDClient
) {
  $(function () {
    console.log(`window.LDClient is ${window.LDClient}.`);
    console.log(`But LDClient should be defined: ${LDClient}`);

    const client = LDClient.initialize("client-side-id", {
      kind: "user",
      key: "test-user-1",
    });

    client.waitForInitialization().then(function () {
      console.log(`allFlags: ${JSON.stringify(client.allFlags(), null, " ")}`);
    });
  });
});