@schematichq/schematic-react 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schematic-react.cjs.js +18 -11
- package/dist/schematic-react.d.ts +1 -1
- package/dist/schematic-react.esm.js +18 -11
- package/package.json +2 -2
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/index.tsx
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
|
+
Schematic: () => Schematic,
|
23
24
|
SchematicProvider: () => SchematicProvider,
|
24
25
|
useSchematic: () => useSchematic,
|
25
26
|
useSchematicContext: () => useSchematicContext,
|
@@ -107,7 +108,7 @@ var Schematic = class {
|
|
107
108
|
});
|
108
109
|
}
|
109
110
|
}
|
110
|
-
|
111
|
+
async checkFlag(options) {
|
111
112
|
const { fallback = false, key } = options;
|
112
113
|
const context = options.context || this.context;
|
113
114
|
if (this.useWebSocket) {
|
@@ -133,7 +134,7 @@ var Schematic = class {
|
|
133
134
|
console.error("There was a problem with the fetch operation:", error);
|
134
135
|
return fallback;
|
135
136
|
});
|
136
|
-
}
|
137
|
+
}
|
137
138
|
// Make a REST API call to fetch all flag values for a given context
|
138
139
|
checkFlags = async (context) => {
|
139
140
|
context = context || this.context;
|
@@ -271,6 +272,7 @@ var Schematic = class {
|
|
271
272
|
return new Promise((resolve, reject) => {
|
272
273
|
if (contextString(context) == contextString(this.context)) {
|
273
274
|
resolve();
|
275
|
+
return;
|
274
276
|
}
|
275
277
|
this.context = context;
|
276
278
|
if (!this.conn) {
|
@@ -281,12 +283,13 @@ var Schematic = class {
|
|
281
283
|
let resolved = false;
|
282
284
|
this.conn.onmessage = (event) => {
|
283
285
|
const message = JSON.parse(event.data);
|
284
|
-
|
285
|
-
(
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
286
|
+
if (!(contextString(context) in this.values)) {
|
287
|
+
this.values[contextString(context)] = {};
|
288
|
+
}
|
289
|
+
(message.flags ?? []).forEach(
|
290
|
+
(flag) => {
|
291
|
+
this.values[contextString(context)][flag.flag] = flag.value;
|
292
|
+
}
|
290
293
|
);
|
291
294
|
if (this.flagListener) {
|
292
295
|
this.flagListener(this.values[contextString(context)]);
|
@@ -394,9 +397,13 @@ var useSchematicFlag = (key, opts) => {
|
|
394
397
|
(0, import_react.useEffect)(() => {
|
395
398
|
typeof flagValue === "undefined" ? setValue(fallback) : setValue(flagValue);
|
396
399
|
}, [key, fallback, flagValue]);
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
+
(0, import_react.useEffect)(() => {
|
401
|
+
if (!client)
|
402
|
+
return;
|
403
|
+
client.checkFlag({ key, fallback }).then((value2) => {
|
404
|
+
setValue(value2);
|
405
|
+
});
|
406
|
+
}, [client, key, fallback]);
|
400
407
|
return value;
|
401
408
|
};
|
402
409
|
/*! Bundled license information:
|
@@ -74,7 +74,7 @@ export declare const useSchematicEvents: (opts?: SchematicHookOpts) => {
|
|
74
74
|
identify: ((body: SchematicJS.EventBodyIdentify) => void) | undefined;
|
75
75
|
};
|
76
76
|
|
77
|
-
export declare const useSchematicFlag: (key: string, opts?: UseSchematicFlagOpts) => boolean
|
77
|
+
export declare const useSchematicFlag: (key: string, opts?: UseSchematicFlagOpts) => boolean;
|
78
78
|
|
79
79
|
export declare type UseSchematicFlagOpts = SchematicHookOpts & {
|
80
80
|
fallback?: boolean;
|
@@ -77,7 +77,7 @@ var Schematic = class {
|
|
77
77
|
});
|
78
78
|
}
|
79
79
|
}
|
80
|
-
|
80
|
+
async checkFlag(options) {
|
81
81
|
const { fallback = false, key } = options;
|
82
82
|
const context = options.context || this.context;
|
83
83
|
if (this.useWebSocket) {
|
@@ -103,7 +103,7 @@ var Schematic = class {
|
|
103
103
|
console.error("There was a problem with the fetch operation:", error);
|
104
104
|
return fallback;
|
105
105
|
});
|
106
|
-
}
|
106
|
+
}
|
107
107
|
// Make a REST API call to fetch all flag values for a given context
|
108
108
|
checkFlags = async (context) => {
|
109
109
|
context = context || this.context;
|
@@ -241,6 +241,7 @@ var Schematic = class {
|
|
241
241
|
return new Promise((resolve, reject) => {
|
242
242
|
if (contextString(context) == contextString(this.context)) {
|
243
243
|
resolve();
|
244
|
+
return;
|
244
245
|
}
|
245
246
|
this.context = context;
|
246
247
|
if (!this.conn) {
|
@@ -251,12 +252,13 @@ var Schematic = class {
|
|
251
252
|
let resolved = false;
|
252
253
|
this.conn.onmessage = (event) => {
|
253
254
|
const message = JSON.parse(event.data);
|
254
|
-
|
255
|
-
(
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
255
|
+
if (!(contextString(context) in this.values)) {
|
256
|
+
this.values[contextString(context)] = {};
|
257
|
+
}
|
258
|
+
(message.flags ?? []).forEach(
|
259
|
+
(flag) => {
|
260
|
+
this.values[contextString(context)][flag.flag] = flag.value;
|
261
|
+
}
|
260
262
|
);
|
261
263
|
if (this.flagListener) {
|
262
264
|
this.flagListener(this.values[contextString(context)]);
|
@@ -369,12 +371,17 @@ var useSchematicFlag = (key, opts) => {
|
|
369
371
|
useEffect(() => {
|
370
372
|
typeof flagValue === "undefined" ? setValue(fallback) : setValue(flagValue);
|
371
373
|
}, [key, fallback, flagValue]);
|
372
|
-
|
373
|
-
|
374
|
-
|
374
|
+
useEffect(() => {
|
375
|
+
if (!client)
|
376
|
+
return;
|
377
|
+
client.checkFlag({ key, fallback }).then((value2) => {
|
378
|
+
setValue(value2);
|
379
|
+
});
|
380
|
+
}, [client, key, fallback]);
|
375
381
|
return value;
|
376
382
|
};
|
377
383
|
export {
|
384
|
+
Schematic,
|
378
385
|
SchematicProvider,
|
379
386
|
useSchematic,
|
380
387
|
useSchematicContext,
|
package/package.json
CHANGED
@@ -42,9 +42,9 @@
|
|
42
42
|
"test": "jest --config jest.config.js"
|
43
43
|
},
|
44
44
|
"types": "dist/schematic-react.d.ts",
|
45
|
-
"version": "0.1.
|
45
|
+
"version": "0.1.8",
|
46
46
|
"dependencies": {
|
47
|
-
"@schematichq/schematic-js": "^0.1.
|
47
|
+
"@schematichq/schematic-js": "^0.1.10"
|
48
48
|
},
|
49
49
|
"peerDependencies": {
|
50
50
|
"react": ">=18"
|