Skip to content

Commit

Permalink
feat: experimental web support (open-feature#200)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert authored Sep 29, 2022
1 parent ce7c4ad commit fd144bb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is the JavaScript implementation of [OpenFeature](https://openfeature.dev),

We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.

This library is intended to be used in server-side contexts and has not been evaluated for use client-side or on mobile devices.
**This library is intended to be used in server-side contexts and has only experimental support for web usage.**

## Installation

Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
"dist/"
],
"exports": {
"node": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/cjs/index.js"
},
"devDependencies": {
"@types/jest": "^28.1.4",
Expand Down
6 changes: 3 additions & 3 deletions src/open-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const GLOBAL_OPENFEATURE_API_KEY = Symbol.for('@openfeature/js.api');
type OpenFeatureGlobal = {
[GLOBAL_OPENFEATURE_API_KEY]?: OpenFeatureAPI;
};
const _global = global as OpenFeatureGlobal;
const _globalThis = globalThis as OpenFeatureGlobal;

class OpenFeatureAPI implements GlobalApi {
private _provider: Provider = NOOP_PROVIDER;
Expand All @@ -18,13 +18,13 @@ class OpenFeatureAPI implements GlobalApi {
private _logger: Logger = new DefaultLogger();

static getInstance(): OpenFeatureAPI {
const globalApi = _global[GLOBAL_OPENFEATURE_API_KEY];
const globalApi = _globalThis[GLOBAL_OPENFEATURE_API_KEY];
if (globalApi) {
return globalApi;
}

const instance = new OpenFeatureAPI();
_global[GLOBAL_OPENFEATURE_API_KEY] = instance;
_globalThis[GLOBAL_OPENFEATURE_API_KEY] = instance;
return instance;
}

Expand Down

0 comments on commit fd144bb

Please sign in to comment.