@unleash/proxy-client-react
Advanced tools
Comparing version 4.3.1 to 4.4.0
@@ -9,4 +9,5 @@ /** @format */ | ||
stopClient?: boolean; | ||
startTransition?: (fn: () => void) => void; | ||
} | ||
declare const FlagProvider: FC<PropsWithChildren<IFlagProvider>>; | ||
export default FlagProvider; |
import { UnleashClient as k } from "unleash-proxy-client"; | ||
import { InMemoryStorageProvider as J, LocalStorageProvider as Q, UnleashClient as W } from "unleash-proxy-client"; | ||
import { InMemoryStorageProvider as Q, LocalStorageProvider as W, UnleashClient as X } from "unleash-proxy-client"; | ||
import g, { useState as b, useEffect as y, useMemo as A, useContext as p, useRef as H } from "react"; | ||
@@ -11,17 +11,18 @@ const d = g.createContext(null), P = { | ||
clientKey: "not-used" | ||
}, M = "startTransition", x = g[M] || ((e) => e()), O = ({ | ||
}, M = "startTransition", _ = g[M] || ((e) => e()), z = ({ | ||
config: e, | ||
children: t, | ||
unleashClient: o, | ||
startClient: c = !0, | ||
stopClient: l = !0 | ||
unleashClient: r, | ||
startClient: s = !0, | ||
stopClient: u = !0, | ||
startTransition: c = _ | ||
}) => { | ||
var F, h, T; | ||
const s = e || P, r = g.useRef( | ||
o || new k(s) | ||
), [u, n] = g.useState( | ||
!!(o ? e != null && e.bootstrap && (e == null ? void 0 : e.bootstrapOverride) !== !1 || (F = o.isReady) != null && F.call(o) : s.bootstrap && s.bootstrapOverride !== !1) | ||
), [R, v] = b(((T = (h = r.current).getError) == null ? void 0 : T.call(h)) || null); | ||
var F, h, S; | ||
const l = e || P, o = g.useRef( | ||
r || new k(l) | ||
), [n, x] = g.useState( | ||
!!(r ? e != null && e.bootstrap && (e == null ? void 0 : e.bootstrapOverride) !== !1 || (F = r.isReady) != null && F.call(r) : l.bootstrap && l.bootstrapOverride !== !1) | ||
), [R, v] = b(((S = (h = o.current).getError) == null ? void 0 : S.call(h)) || null); | ||
y(() => { | ||
!s && !o && console.error( | ||
!l && !r && console.error( | ||
`You must provide either a config or an unleash client to the flag provider. | ||
@@ -32,7 +33,7 @@ If you are initializing the client in useEffect, you can avoid this warning | ||
const a = (E) => { | ||
x(() => { | ||
c(() => { | ||
v((U) => U || E); | ||
}); | ||
}, f = (E) => { | ||
x(() => { | ||
c(() => { | ||
v(null); | ||
@@ -44,82 +45,82 @@ }); | ||
i = setTimeout(() => { | ||
x(() => { | ||
n(!0); | ||
c(() => { | ||
x(!0); | ||
}); | ||
}, 0); | ||
}; | ||
return r.current.on("ready", m), r.current.on("error", a), r.current.on("recovered", f), c && (r.current.stop(), r.current.start()), function() { | ||
r.current && (r.current.off("error", a), r.current.off("ready", m), r.current.off("recovered", f), l && r.current.stop()), i && clearTimeout(i); | ||
return o.current.on("ready", m), o.current.on("error", a), o.current.on("recovered", f), s && (o.current.stop(), o.current.start()), function() { | ||
o.current && (o.current.off("error", a), o.current.off("ready", m), o.current.off("recovered", f), u && o.current.stop()), i && clearTimeout(i); | ||
}; | ||
}, []); | ||
const S = A( | ||
const T = A( | ||
() => ({ | ||
on: (a, f, i) => r.current.on(a, f, i), | ||
off: (a, f) => r.current.off(a, f), | ||
updateContext: async (a) => await r.current.updateContext(a), | ||
isEnabled: (a) => r.current.isEnabled(a), | ||
getVariant: (a) => r.current.getVariant(a), | ||
client: r.current, | ||
flagsReady: u, | ||
on: (a, f, i) => o.current.on(a, f, i), | ||
off: (a, f) => o.current.off(a, f), | ||
updateContext: async (a) => await o.current.updateContext(a), | ||
isEnabled: (a) => o.current.isEnabled(a), | ||
getVariant: (a) => o.current.getVariant(a), | ||
client: o.current, | ||
flagsReady: n, | ||
flagsError: R, | ||
setFlagsReady: n, | ||
setFlagsReady: x, | ||
setFlagsError: v | ||
}), | ||
[u, R] | ||
[n, R] | ||
); | ||
return /* @__PURE__ */ g.createElement(d.Provider, { value: S }, t); | ||
}, z = (e) => { | ||
const { isEnabled: t, client: o } = p(d), [c, l] = b(!!t(e)), s = H(); | ||
return s.current = c, y(() => { | ||
if (!o) | ||
return /* @__PURE__ */ g.createElement(d.Provider, { value: T }, t); | ||
}, B = (e) => { | ||
const { isEnabled: t, client: r } = p(d), [s, u] = b(!!t(e)), c = H(); | ||
return c.current = s, y(() => { | ||
if (!r) | ||
return; | ||
const r = () => { | ||
const l = () => { | ||
const n = t(e); | ||
n !== s.current && (s.current = n, l(!!n)); | ||
}, u = () => { | ||
n !== c.current && (c.current = n, u(!!n)); | ||
}, o = () => { | ||
const n = t(e); | ||
s.current = n, l(n); | ||
c.current = n, u(n); | ||
}; | ||
return o.on("update", r), o.on("ready", u), () => { | ||
o.off("update", r), o.off("ready", u); | ||
return r.on("update", l), r.on("ready", o), () => { | ||
r.off("update", l), r.off("ready", o); | ||
}; | ||
}, [o]), c; | ||
}, B = () => { | ||
const { client: e } = p(d), [t, o] = b(e.getAllToggles()); | ||
}, [r]), s; | ||
}, K = () => { | ||
const { client: e } = p(d), [t, r] = b(e.getAllToggles()); | ||
return y(() => { | ||
const c = () => { | ||
o(e.getAllToggles()); | ||
const s = () => { | ||
r(e.getAllToggles()); | ||
}; | ||
return e.on("update", c), () => { | ||
e.off("update", c); | ||
return e.on("update", s), () => { | ||
e.off("update", s); | ||
}; | ||
}, []), t; | ||
}, K = () => { | ||
}, L = () => { | ||
const { flagsReady: e, flagsError: t } = p(d); | ||
return { flagsReady: e, flagsError: t }; | ||
}, _ = (e, t) => { | ||
var c, l, s, r; | ||
return !(e.name === (t == null ? void 0 : t.name) && e.enabled === (t == null ? void 0 : t.enabled) && e.feature_enabled === (t == null ? void 0 : t.feature_enabled) && ((c = e.payload) == null ? void 0 : c.type) === ((l = t == null ? void 0 : t.payload) == null ? void 0 : l.type) && ((s = e.payload) == null ? void 0 : s.value) === ((r = t == null ? void 0 : t.payload) == null ? void 0 : r.value)); | ||
}, L = (e) => { | ||
const { getVariant: t, client: o } = p(d), [c, l] = b(t(e)), s = H({ | ||
name: c.name, | ||
enabled: c.enabled | ||
}, q = (e, t) => { | ||
var s, u, c, l; | ||
return !(e.name === (t == null ? void 0 : t.name) && e.enabled === (t == null ? void 0 : t.enabled) && e.feature_enabled === (t == null ? void 0 : t.feature_enabled) && ((s = e.payload) == null ? void 0 : s.type) === ((u = t == null ? void 0 : t.payload) == null ? void 0 : u.type) && ((c = e.payload) == null ? void 0 : c.value) === ((l = t == null ? void 0 : t.payload) == null ? void 0 : l.value)); | ||
}, Y = (e) => { | ||
const { getVariant: t, client: r } = p(d), [s, u] = b(t(e)), c = H({ | ||
name: s.name, | ||
enabled: s.enabled | ||
}); | ||
return s.current = c, y(() => { | ||
if (!o) | ||
return c.current = s, y(() => { | ||
if (!r) | ||
return; | ||
const r = () => { | ||
const l = () => { | ||
const n = t(e); | ||
_(s.current, n) && (l(n), s.current = n); | ||
}, u = () => { | ||
q(c.current, n) && (u(n), c.current = n); | ||
}, o = () => { | ||
const n = t(e); | ||
s.current.name = n == null ? void 0 : n.name, s.current.enabled = n == null ? void 0 : n.enabled, l(n); | ||
c.current.name = n == null ? void 0 : n.name, c.current.enabled = n == null ? void 0 : n.enabled, u(n); | ||
}; | ||
return o.on("update", r), o.on("ready", u), () => { | ||
o.off("update", r), o.off("ready", u); | ||
return r.on("update", l), r.on("ready", o), () => { | ||
r.off("update", l), r.off("ready", o); | ||
}; | ||
}, [o]), c || {}; | ||
}, Y = () => { | ||
}, [r]), s || {}; | ||
}, j = () => { | ||
const { updateContext: e } = p(d); | ||
return e; | ||
}, j = () => { | ||
}, D = () => { | ||
const { client: e } = p(d); | ||
@@ -130,14 +131,14 @@ return e; | ||
d as FlagContext, | ||
O as FlagProvider, | ||
J as InMemoryStorageProvider, | ||
Q as LocalStorageProvider, | ||
W as UnleashClient, | ||
O as default, | ||
z as useFlag, | ||
B as useFlags, | ||
K as useFlagsStatus, | ||
j as useUnleashClient, | ||
Y as useUnleashContext, | ||
L as useVariant | ||
z as FlagProvider, | ||
Q as InMemoryStorageProvider, | ||
W as LocalStorageProvider, | ||
X as UnleashClient, | ||
z as default, | ||
B as useFlag, | ||
K as useFlags, | ||
L as useFlagsStatus, | ||
D as useUnleashClient, | ||
j as useUnleashContext, | ||
Y as useVariant | ||
}; | ||
//# sourceMappingURL=unleash-react.js.map |
{ | ||
"name": "@unleash/proxy-client-react", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"description": "React interface for working with unleash", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62406
221