@dif.sh/react 0.7.0 → 0.9.0
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/README.md +1 -1
- package/dist/provider.d.ts +6 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +4 -2
- package/dist/provider.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ the link with `dif qa --force <exp>=<variant> --preview-url <url>`.
|
|
|
90
90
|
|
|
91
91
|
**Does:**
|
|
92
92
|
- Provide `<DifProvider>` to initialize the SDK at the root of your tree.
|
|
93
|
-
- Provide `useDif()` to read `{ track, exposure }` from anywhere.
|
|
93
|
+
- Provide `useDif()` to read `{ track, exposure, page, identify }` from anywhere.
|
|
94
94
|
|
|
95
95
|
**Does not:**
|
|
96
96
|
- Re-initialize on prop changes in v0; pass a stable config.
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import type { DifInitConfig, TrackProps } from "@dif.sh/sdk";
|
|
2
|
+
import type { DifInitConfig, DifProps, PageOptions, TrackProps } from "@dif.sh/sdk";
|
|
3
3
|
interface ExperimentFn {
|
|
4
4
|
<V extends string, R>(id: string, branches: Record<V, () => R>): () => R;
|
|
5
5
|
}
|
|
@@ -8,6 +8,10 @@ export interface DifContextValue {
|
|
|
8
8
|
track: (metric: string, opts?: TrackProps) => void;
|
|
9
9
|
/** Experiment assignment — same signature as the bare `dif(...)` function. */
|
|
10
10
|
exposure: ExperimentFn;
|
|
11
|
+
/** Send one page view. Needed only with `pageViews: "off"` or for a custom route. */
|
|
12
|
+
page: (opts?: PageOptions) => void;
|
|
13
|
+
/** Set the user id. Traits also send an identify event. */
|
|
14
|
+
identify: (userId: string, traits?: DifProps) => void;
|
|
11
15
|
}
|
|
12
16
|
export interface DifProviderProps {
|
|
13
17
|
config: DifInitConfig;
|
|
@@ -25,7 +29,7 @@ export interface DifProviderProps {
|
|
|
25
29
|
* not re-init on prop changes — pass a stable config object.
|
|
26
30
|
*/
|
|
27
31
|
export declare function DifProvider({ config, children, allowOverrides, preview }: DifProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
/** Hook returning `{ track, exposure }`. Must be called inside `<DifProvider>`. */
|
|
32
|
+
/** Hook returning `{ track, exposure, page, identify }`. Must be called inside `<DifProvider>`. */
|
|
29
33
|
export declare function useDif(): DifContextValue;
|
|
30
34
|
export {};
|
|
31
35
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpF,UAAU,YAAY;IACpB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CAC1E;AAED,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACnD,8EAA8E;IAC9E,QAAQ,EAAE,YAAY,CAAC;IACvB,qFAAqF;IACrF,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAAC;IACnC,2DAA2D;IAC3D,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;CACvD;AAID,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,gBAAgB,2CAgC1F;AAED,mGAAmG;AACnG,wBAAgB,MAAM,IAAI,eAAe,CAMxC"}
|
package/dist/provider.js
CHANGED
|
@@ -28,15 +28,17 @@ export function DifProvider({ config, children, allowOverrides, preview }) {
|
|
|
28
28
|
if (preview !== false)
|
|
29
29
|
mountDifPreview();
|
|
30
30
|
}, [allowOverrides, preview]);
|
|
31
|
-
// Stable identity:
|
|
31
|
+
// Stable identity: all functions close over module-level state, so consumers
|
|
32
32
|
// of useDif() must not re-render just because the provider did.
|
|
33
33
|
const value = useMemo(() => ({
|
|
34
34
|
track: (metric, opts) => dif.track(metric, opts),
|
|
35
35
|
exposure: ((id, branches) => dif(id, branches)),
|
|
36
|
+
page: (opts) => dif.page(opts),
|
|
37
|
+
identify: (userId, traits) => dif.identify(userId, traits),
|
|
36
38
|
}), []);
|
|
37
39
|
return _jsx(DifContext.Provider, { value: value, children: children });
|
|
38
40
|
}
|
|
39
|
-
/** Hook returning `{ track, exposure }`. Must be called inside `<DifProvider>`. */
|
|
41
|
+
/** Hook returning `{ track, exposure, page, identify }`. Must be called inside `<DifProvider>`. */
|
|
40
42
|
export function useDif() {
|
|
41
43
|
const ctx = useContext(DifContext);
|
|
42
44
|
if (!ctx) {
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,UAAU,EACV,MAAM,EACN,SAAS,EACT,OAAO,GAER,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,UAAU,EACV,MAAM,EACN,SAAS,EACT,OAAO,GAER,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkBlE,MAAM,UAAU,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAW/D;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAoB;IACzF,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,4EAA4E;IAC5E,4EAA4E;IAC5E,sEAAsE;IACtE,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAC1D,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;IAC7B,CAAC;IAED,+EAA+E;IAC/E,gFAAgF;IAChF,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,CAAC,EAAE,KAAK,EAAE,cAAc,KAAK,KAAK,EAAE,CAAC,CAAC;QACnD,IAAI,OAAO,KAAK,KAAK;YAAE,eAAe,EAAE,CAAC;IAC3C,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAE9B,6EAA6E;IAC7E,gEAAgE;IAChE,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAiB;QAC/D,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KAC3D,CAAC,EACF,EAAE,CACH,CAAC;IAEF,OAAO,KAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAuB,CAAC;AAC7E,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,MAAM;IACpB,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dif.sh/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "React adapter for @dif.sh/sdk feature flags and A/B tests: DifProvider and the useDif hook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typescript"
|
|
49
49
|
],
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@dif.sh/sdk": "^0.
|
|
51
|
+
"@dif.sh/sdk": "^0.9.0",
|
|
52
52
|
"react": ">=18"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|