launchdarkly-react-client-sdk
Advanced tools
Comparing version 3.6.0 to 3.6.1
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("react"),t=require("launchdarkly-js-client-sdk"),r=require("lodash.camelcase"),n=require("hoist-non-react-statics");function o(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(e);const i=()=>e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),a={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0,reactContext:i()},l=e=>{var t;return null!=(t=e.context)?t:e.user},c=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},u=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},p=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function f(e,t,n=a,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(d(e,r)&&(t[r]=e[r]),t)),{})}(t,o),{useCamelCaseFlagKeys:i=!0}=n,[l,c={}]=i?function(e){const t={},n={};for(const o in e){if(0===o.indexOf("$"))continue;const s=r(o);t[s]=e[o],n[s]=o}return[t,n]}(s):[s];return{flags:n.sendEventsOnFlagRead?y(e,l,c,i):l,flagKeyMap:c}}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function y(e,t,r,n){return new Proxy(t,{get(t,o,s){const i=Reflect.get(t,o,s),a=n&&d(r,o)||d(t,o);if("symbol"==typeof o||!a)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}c.camelCaseKeys=c;const h={wrapperName:"react-client-sdk",wrapperVersion:"3.6.0",sendEventsOnlyForVariation:!0};var O=Object.defineProperty,g=Object.defineProperties,b=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable,C=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))x.call(t,r)&&C(e,r,t[r]);if(v)for(var r of v(t))m.call(t,r)&&C(e,r,t[r]);return e},P=(e,t)=>g(e,b(t)),w=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));class F extends e.Component{constructor(e){super(e),this.getReactOptions=()=>j(j({},a),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=u(r,t),s=j(j({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>j(P(j({},r),{unproxiedFlags:s}),f(e,s,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>P(j({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=p(e,r);this.setState((o=>j(P(j({},o),{unproxiedFlags:n}),f(e,n,t,r))))},this.prepareLDClient=()=>w(this,null,(function*(){var e;const{clientSideID:r,flags:n,options:o}=this.props;let s=yield this.props.ldClient;const i=this.getReactOptions();let a,c=this.state.unproxiedFlags;if(s)c=p(s,n);else{const u=null!=(e=l(this.props))?e:{anonymous:!0,kind:"user"};s=t.initialize(r,u,j(j({},h),o));try{yield s.waitForInitialization(this.props.timeout),c=p(s,n)}catch(e){a=e,(null==a?void 0:a.name.toLowerCase().includes("timeout"))&&(s.on("failed",this.onFailed),s.on("ready",(()=>{this.onReady(s,i,n)})))}}this.setState((e=>P(j(P(j({},e),{unproxiedFlags:c}),f(s,c,i,n)),{ldClient:s,error:a}))),this.subscribeToChanges(s)}));const{options:r}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},r){const{bootstrap:e}=r;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?c(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return w(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!l(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return w(this,null,(function*(){const{deferInitialization:t}=this.props,r=!l(e)&&l(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state,{reactContext:s}=this.getReactOptions();return e.createElement(s.Provider,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var E=Object.defineProperty,D=Object.defineProperties,S=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,R=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,I=(e,t)=>{for(var r in t||(t={}))K.call(t,r)&&R(e,r,t[r]);if(k)for(var r of k(t))L.call(t,r)&&R(e,r,t[r]);return e};var z=Object.defineProperty,M=Object.defineProperties,q=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,N=(e,t,r)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,U=(e,t)=>{for(var r in t||(t={}))V.call(t,r)&&N(e,r,t[r]);if(T)for(var r of T(t))$.call(t,r)&&N(e,r,t[r]);return e},W=(e,t)=>M(e,q(t));var A=Object.defineProperty,B=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Q=(e,t)=>{for(var r in t||(t={}))G.call(t,r)&&J(e,r,t[r]);if(B)for(var r of B(t))H.call(t,r)&&J(e,r,t[r]);return e};exports.LDProvider=F,exports.asyncWithLDProvider=function(r){return n=this,o=null,s=function*(){var n,o;const{clientSideID:s,flags:i,options:c,reactOptions:d}=r,y=U(U({},a),d),O=null!=(n=l(r))?n:{anonymous:!0,kind:"user"};let g,b={};const v=null!=(o=yield r.ldClient)?o:t.initialize(s,O,U(U({},h),c));try{yield v.waitForInitialization(r.timeout),b=p(v,i)}catch(e){g=e}const x=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:b;return({children:t})=>{const[r,n]=e.useState((()=>W(U({unproxiedFlags:x},f(v,x,y,i)),{ldClient:v,error:g})));e.useEffect((()=>{function e(e){const t=u(e,i);Object.keys(t).length>0&&n((e=>{const r=U(U({},e.unproxiedFlags),t);return U(W(U({},e),{unproxiedFlags:r}),f(v,r,y,i))}))}function t(){const e=p(v,i);n((t=>U(W(U({},t),{unproxiedFlags:e}),f(v,e,y,i))))}function r(e){n((t=>W(U({},t),{error:e})))}return v.on("change",e),(null==g?void 0:g.name.toLowerCase().includes("timeout"))&&(v.on("failed",r),v.on("ready",t)),function(){v.off("change",e),v.off("failed",r),v.off("ready",t)}}),[]);const o=((e,t)=>{var r={};for(var n in e)V.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&T)for(var n of T(e))t.indexOf(n)<0&&$.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]),{reactContext:s}=y;return e.createElement(s.Provider,{value:o},t)}},new Promise(((e,t)=>{var r=e=>{try{a(s.next(e))}catch(e){t(e)}},i=e=>{try{a(s.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(n,o)).next())}));var n,o,s},exports.camelCaseKeys=c,exports.defaultReactOptions=a,exports.reactSdkContextFactory=i,exports.useFlags=t=>{const{flags:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.useLDClient=t=>{const{ldClient:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.useLDClientError=function(t){const{error:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){var r;const n=null!=(r=e.reactContext)?r:a.reactContext;return r=>s.createElement(n.Consumer,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,Q({ldClient:o},r)):s.createElement(t,Q({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=I(I({},a),r),i=(l=I({},e),D(l,S({reactOptions:o})));var l;function c(e){return s.createElement(F,I({},i),s.createElement(t,I({},e)))}return n(c,t),c}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})); | ||
"use strict";var e=require("react"),t=require("launchdarkly-js-client-sdk"),r=require("lodash.camelcase"),n=require("hoist-non-react-statics");function o(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(e);const i=()=>e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),a={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0,reactContext:i()},l=e=>{var t;return null!=(t=e.context)?t:e.user},c=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},u=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},p=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function f(e,t,n=a,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(d(e,r)&&(t[r]=e[r]),t)),{})}(t,o),{useCamelCaseFlagKeys:i=!0}=n,[l,c={}]=i?function(e){const t={},n={};for(const o in e){if(0===o.indexOf("$"))continue;const s=r(o);t[s]=e[o],n[s]=o}return[t,n]}(s):[s];return{flags:n.sendEventsOnFlagRead?y(e,l,c,i):l,flagKeyMap:c}}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function y(e,t,r,n){return new Proxy(t,{get(t,o,s){const i=Reflect.get(t,o,s),a=n&&d(r,o)||d(t,o);if("symbol"==typeof o||!a)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}c.camelCaseKeys=c;const h={wrapperName:"react-client-sdk",wrapperVersion:"3.6.1",sendEventsOnlyForVariation:!0};var O=Object.defineProperty,g=Object.defineProperties,b=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable,C=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))x.call(t,r)&&C(e,r,t[r]);if(v)for(var r of v(t))m.call(t,r)&&C(e,r,t[r]);return e},P=(e,t)=>g(e,b(t)),w=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));class F extends e.Component{constructor(e){super(e),this.getReactOptions=()=>j(j({},a),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=u(r,t),s=j(j({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>j(P(j({},r),{unproxiedFlags:s}),f(e,s,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>P(j({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=p(e,r);this.setState((o=>j(P(j({},o),{unproxiedFlags:n}),f(e,n,t,r))))},this.prepareLDClient=()=>w(this,null,(function*(){var e;const{clientSideID:r,flags:n,options:o}=this.props;let s=yield this.props.ldClient;const i=this.getReactOptions();let a,c=this.state.unproxiedFlags;if(s)c=p(s,n);else{const u=null!=(e=l(this.props))?e:{anonymous:!0,kind:"user"};s=t.initialize(r,u,j(j({},h),o));try{yield s.waitForInitialization(this.props.timeout),c=p(s,n)}catch(e){a=e,(null==a?void 0:a.name.toLowerCase().includes("timeout"))&&(s.on("failed",this.onFailed),s.on("ready",(()=>{this.onReady(s,i,n)})))}}this.setState((e=>P(j(P(j({},e),{unproxiedFlags:c}),f(s,c,i,n)),{ldClient:s,error:a}))),this.subscribeToChanges(s)}));const{options:r}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},r){const{bootstrap:e}=r;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?c(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return w(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!l(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return w(this,null,(function*(){const{deferInitialization:t}=this.props,r=!l(e)&&l(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state,{reactContext:s}=this.getReactOptions();return e.createElement(s.Provider,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var E=Object.defineProperty,D=Object.defineProperties,S=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,R=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,I=(e,t)=>{for(var r in t||(t={}))K.call(t,r)&&R(e,r,t[r]);if(k)for(var r of k(t))L.call(t,r)&&R(e,r,t[r]);return e};var z=Object.defineProperty,M=Object.defineProperties,q=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,N=(e,t,r)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,U=(e,t)=>{for(var r in t||(t={}))V.call(t,r)&&N(e,r,t[r]);if(T)for(var r of T(t))$.call(t,r)&&N(e,r,t[r]);return e},W=(e,t)=>M(e,q(t));var A=Object.defineProperty,B=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Q=(e,t)=>{for(var r in t||(t={}))G.call(t,r)&&J(e,r,t[r]);if(B)for(var r of B(t))H.call(t,r)&&J(e,r,t[r]);return e};exports.LDProvider=F,exports.asyncWithLDProvider=function(r){return n=this,o=null,s=function*(){var n,o;const{clientSideID:s,flags:i,options:c,reactOptions:d}=r,y=U(U({},a),d),O=null!=(n=l(r))?n:{anonymous:!0,kind:"user"};let g,b={};const v=null!=(o=yield r.ldClient)?o:t.initialize(s,O,U(U({},h),c));try{yield v.waitForInitialization(r.timeout),b=p(v,i)}catch(e){g=e}const x=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:b;return({children:t})=>{const[r,n]=e.useState((()=>W(U({unproxiedFlags:x},f(v,x,y,i)),{ldClient:v,error:g})));e.useEffect((()=>{function e(e){const t=u(e,i);Object.keys(t).length>0&&n((e=>{const r=U(U({},e.unproxiedFlags),t);return U(W(U({},e),{unproxiedFlags:r}),f(v,r,y,i))}))}function t(){const e=p(v,i);n((t=>U(W(U({},t),{unproxiedFlags:e}),f(v,e,y,i))))}function r(e){n((t=>W(U({},t),{error:e})))}return v.on("change",e),(null==g?void 0:g.name.toLowerCase().includes("timeout"))&&(v.on("failed",r),v.on("ready",t)),function(){v.off("change",e),v.off("failed",r),v.off("ready",t)}}),[]);const o=((e,t)=>{var r={};for(var n in e)V.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&T)for(var n of T(e))t.indexOf(n)<0&&$.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]),{reactContext:s}=y;return e.createElement(s.Provider,{value:o},t)}},new Promise(((e,t)=>{var r=e=>{try{a(s.next(e))}catch(e){t(e)}},i=e=>{try{a(s.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(n,o)).next())}));var n,o,s},exports.camelCaseKeys=c,exports.defaultReactOptions=a,exports.reactSdkContextFactory=i,exports.useFlags=t=>{const{flags:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.useLDClient=t=>{const{ldClient:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.useLDClientError=function(t){const{error:r}=e.useContext(null!=t?t:a.reactContext);return r},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){var r;const n=null!=(r=e.reactContext)?r:a.reactContext;return r=>s.createElement(n.Consumer,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,Q({ldClient:o},r)):s.createElement(t,Q({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=I(I({},a),r),i=(l=I({},e),D(l,S({reactOptions:o})));var l;function c(e){return s.createElement(F,I({},i),s.createElement(t,I({},e)))}return n(c,t),c}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"react";import t,{createContext as r,Component as n,useState as o,useEffect as a,useContext as i}from"react";import{initialize as s}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import l from"lodash.camelcase";import c from"hoist-non-react-statics";const p=()=>r({flags:{},flagKeyMap:{},ldClient:void 0}),u={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0,reactContext:p()},f=e=>{var t;return null!=(t=e.context)?t:e.user},d=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[l(r)]=e[r]);return t},y=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},h=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function g(e,t,r=u,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(O(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:a=!0}=r,[i,s={}]=a?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=l(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?b(e,i,s,a):i,flagKeyMap:s}}function O(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function b(e,t,r,n){return new Proxy(t,{get(t,o,a){const i=Reflect.get(t,o,a),s=n&&O(r,o)||O(t,o);if("symbol"==typeof o||!s)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}d.camelCaseKeys=d;const m={wrapperName:"react-client-sdk",wrapperVersion:"3.6.0",sendEventsOnlyForVariation:!0};var v=Object.defineProperty,C=Object.defineProperties,x=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,F=(e,t,r)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,E=(e,t)=>{for(var r in t||(t={}))w.call(t,r)&&F(e,r,t[r]);if(j)for(var r of j(t))P.call(t,r)&&F(e,r,t[r]);return e},S=(e,t)=>C(e,x(t)),k=(e,t,r)=>new Promise(((n,o)=>{var a=e=>{try{s(r.next(e))}catch(e){o(e)}},i=e=>{try{s(r.throw(e))}catch(e){o(e)}},s=e=>e.done?n(e.value):Promise.resolve(e.value).then(a,i);s((r=r.apply(e,t)).next())}));class D extends n{constructor(e){super(e),this.getReactOptions=()=>E(E({},u),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=y(r,t),a=E(E({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>E(S(E({},r),{unproxiedFlags:a}),g(e,a,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>S(E({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=h(e,r);this.setState((o=>E(S(E({},o),{unproxiedFlags:n}),g(e,n,t,r))))},this.prepareLDClient=()=>k(this,null,(function*(){var e;const{clientSideID:t,flags:r,options:n}=this.props;let o=yield this.props.ldClient;const a=this.getReactOptions();let i,l=this.state.unproxiedFlags;if(o)l=h(o,r);else{const c=null!=(e=f(this.props))?e:{anonymous:!0,kind:"user"};o=s(t,c,E(E({},m),n));try{yield o.waitForInitialization(this.props.timeout),l=h(o,r)}catch(e){i=e,(null==i?void 0:i.name.toLowerCase().includes("timeout"))&&(o.on("failed",this.onFailed),o.on("ready",(()=>{this.onReady(o,a,r)})))}}this.setState((e=>S(E(S(E({},e),{unproxiedFlags:l}),g(o,l,a,r)),{ldClient:o,error:i}))),this.subscribeToChanges(o)}));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?d(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return k(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!f(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return k(this,null,(function*(){const{deferInitialization:t}=this.props,r=!f(e)&&f(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state,{reactContext:a}=this.getReactOptions();return t.createElement(a.Provider,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var I=Object.defineProperty,K=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,T=(e,t,r)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,V=(e,t)=>{for(var r in t||(t={}))L.call(t,r)&&T(e,r,t[r]);if(M)for(var r of M(t))z.call(t,r)&&T(e,r,t[r]);return e};function $(t){return function(r){const{reactOptions:n}=t,o=V(V({},u),n),a=(i=V({},t),K(i,R({reactOptions:o})));var i;function s(t){return e.createElement(D,V({},a),e.createElement(r,V({},t)))}return c(s,r),s}}var N=Object.defineProperty,U=Object.defineProperties,q=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,H=(e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,J=(e,t)=>{for(var r in t||(t={}))B.call(t,r)&&H(e,r,t[r]);if(A)for(var r of A(t))G.call(t,r)&&H(e,r,t[r]);return e},Q=(e,t)=>U(e,q(t));function W(e){return r=this,n=null,i=function*(){var r,n;const{clientSideID:i,flags:l,options:c,reactOptions:p}=e,d=J(J({},u),p),O=null!=(r=f(e))?r:{anonymous:!0,kind:"user"};let b,v={};const C=null!=(n=yield e.ldClient)?n:s(i,O,J(J({},m),c));try{yield C.waitForInitialization(e.timeout),v=h(C,l)}catch(e){b=e}const x=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:v;return({children:e})=>{const[r,n]=o((()=>Q(J({unproxiedFlags:x},g(C,x,d,l)),{ldClient:C,error:b})));a((()=>{function e(e){const t=y(e,l);Object.keys(t).length>0&&n((e=>{const r=J(J({},e.unproxiedFlags),t);return J(Q(J({},e),{unproxiedFlags:r}),g(C,r,d,l))}))}function t(){const e=h(C,l);n((t=>J(Q(J({},t),{unproxiedFlags:e}),g(C,e,d,l))))}function r(e){n((t=>Q(J({},t),{error:e})))}return C.on("change",e),(null==b?void 0:b.name.toLowerCase().includes("timeout"))&&(C.on("failed",r),C.on("ready",t)),function(){C.off("change",e),C.off("failed",r),C.off("ready",t)}}),[]);const i=((e,t)=>{var r={};for(var n in e)B.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&A)for(var n of A(e))t.indexOf(n)<0&&G.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]),{reactContext:s}=d;return t.createElement(s.Provider,{value:i},e)}},new Promise(((e,t)=>{var o=e=>{try{s(i.next(e))}catch(e){t(e)}},a=e=>{try{s(i.throw(e))}catch(e){t(e)}},s=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,a);s((i=i.apply(r,n)).next())}));var r,n,i}var X=Object.defineProperty,Y=Object.getOwnPropertySymbols,Z=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,ee=(e,t,r)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,te=(e,t)=>{for(var r in t||(t={}))Z.call(t,r)&&ee(e,r,t[r]);if(Y)for(var r of Y(t))_.call(t,r)&&ee(e,r,t[r]);return e};function re(t={clientOnly:!1}){return function(r){var n;const o=null!=(n=t.reactContext)?n:u.reactContext;return n=>e.createElement(o.Consumer,null,(({flags:o,ldClient:a})=>t.clientOnly?e.createElement(r,te({ldClient:a},n)):e.createElement(r,te({flags:o,ldClient:a},n))))}}const ne=e=>{const{flags:t}=i(null!=e?e:u.reactContext);return t},oe=e=>{const{ldClient:t}=i(null!=e?e:u.reactContext);return t};function ae(e){const{error:t}=i(null!=e?e:u.reactContext);return t}export{D as LDProvider,W as asyncWithLDProvider,d as camelCaseKeys,u as defaultReactOptions,p as reactSdkContextFactory,ne as useFlags,oe as useLDClient,ae as useLDClientError,re as withLDConsumer,$ as withLDProvider}; | ||
import*as e from"react";import t,{createContext as r,Component as n,useState as o,useEffect as a,useContext as i}from"react";import{initialize as s}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import l from"lodash.camelcase";import c from"hoist-non-react-statics";const p=()=>r({flags:{},flagKeyMap:{},ldClient:void 0}),u={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0,reactContext:p()},f=e=>{var t;return null!=(t=e.context)?t:e.user},d=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[l(r)]=e[r]);return t},y=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},h=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function g(e,t,r=u,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(O(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:a=!0}=r,[i,s={}]=a?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=l(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?b(e,i,s,a):i,flagKeyMap:s}}function O(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function b(e,t,r,n){return new Proxy(t,{get(t,o,a){const i=Reflect.get(t,o,a),s=n&&O(r,o)||O(t,o);if("symbol"==typeof o||!s)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}d.camelCaseKeys=d;const m={wrapperName:"react-client-sdk",wrapperVersion:"3.6.1",sendEventsOnlyForVariation:!0};var v=Object.defineProperty,C=Object.defineProperties,x=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,F=(e,t,r)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,E=(e,t)=>{for(var r in t||(t={}))w.call(t,r)&&F(e,r,t[r]);if(j)for(var r of j(t))P.call(t,r)&&F(e,r,t[r]);return e},S=(e,t)=>C(e,x(t)),k=(e,t,r)=>new Promise(((n,o)=>{var a=e=>{try{s(r.next(e))}catch(e){o(e)}},i=e=>{try{s(r.throw(e))}catch(e){o(e)}},s=e=>e.done?n(e.value):Promise.resolve(e.value).then(a,i);s((r=r.apply(e,t)).next())}));class D extends n{constructor(e){super(e),this.getReactOptions=()=>E(E({},u),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=y(r,t),a=E(E({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>E(S(E({},r),{unproxiedFlags:a}),g(e,a,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>S(E({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=h(e,r);this.setState((o=>E(S(E({},o),{unproxiedFlags:n}),g(e,n,t,r))))},this.prepareLDClient=()=>k(this,null,(function*(){var e;const{clientSideID:t,flags:r,options:n}=this.props;let o=yield this.props.ldClient;const a=this.getReactOptions();let i,l=this.state.unproxiedFlags;if(o)l=h(o,r);else{const c=null!=(e=f(this.props))?e:{anonymous:!0,kind:"user"};o=s(t,c,E(E({},m),n));try{yield o.waitForInitialization(this.props.timeout),l=h(o,r)}catch(e){i=e,(null==i?void 0:i.name.toLowerCase().includes("timeout"))&&(o.on("failed",this.onFailed),o.on("ready",(()=>{this.onReady(o,a,r)})))}}this.setState((e=>S(E(S(E({},e),{unproxiedFlags:l}),g(o,l,a,r)),{ldClient:o,error:i}))),this.subscribeToChanges(o)}));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?d(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return k(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!f(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return k(this,null,(function*(){const{deferInitialization:t}=this.props,r=!f(e)&&f(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state,{reactContext:a}=this.getReactOptions();return t.createElement(a.Provider,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var I=Object.defineProperty,K=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,T=(e,t,r)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,V=(e,t)=>{for(var r in t||(t={}))L.call(t,r)&&T(e,r,t[r]);if(M)for(var r of M(t))z.call(t,r)&&T(e,r,t[r]);return e};function $(t){return function(r){const{reactOptions:n}=t,o=V(V({},u),n),a=(i=V({},t),K(i,R({reactOptions:o})));var i;function s(t){return e.createElement(D,V({},a),e.createElement(r,V({},t)))}return c(s,r),s}}var N=Object.defineProperty,U=Object.defineProperties,q=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,H=(e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,J=(e,t)=>{for(var r in t||(t={}))B.call(t,r)&&H(e,r,t[r]);if(A)for(var r of A(t))G.call(t,r)&&H(e,r,t[r]);return e},Q=(e,t)=>U(e,q(t));function W(e){return r=this,n=null,i=function*(){var r,n;const{clientSideID:i,flags:l,options:c,reactOptions:p}=e,d=J(J({},u),p),O=null!=(r=f(e))?r:{anonymous:!0,kind:"user"};let b,v={};const C=null!=(n=yield e.ldClient)?n:s(i,O,J(J({},m),c));try{yield C.waitForInitialization(e.timeout),v=h(C,l)}catch(e){b=e}const x=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:v;return({children:e})=>{const[r,n]=o((()=>Q(J({unproxiedFlags:x},g(C,x,d,l)),{ldClient:C,error:b})));a((()=>{function e(e){const t=y(e,l);Object.keys(t).length>0&&n((e=>{const r=J(J({},e.unproxiedFlags),t);return J(Q(J({},e),{unproxiedFlags:r}),g(C,r,d,l))}))}function t(){const e=h(C,l);n((t=>J(Q(J({},t),{unproxiedFlags:e}),g(C,e,d,l))))}function r(e){n((t=>Q(J({},t),{error:e})))}return C.on("change",e),(null==b?void 0:b.name.toLowerCase().includes("timeout"))&&(C.on("failed",r),C.on("ready",t)),function(){C.off("change",e),C.off("failed",r),C.off("ready",t)}}),[]);const i=((e,t)=>{var r={};for(var n in e)B.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&A)for(var n of A(e))t.indexOf(n)<0&&G.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]),{reactContext:s}=d;return t.createElement(s.Provider,{value:i},e)}},new Promise(((e,t)=>{var o=e=>{try{s(i.next(e))}catch(e){t(e)}},a=e=>{try{s(i.throw(e))}catch(e){t(e)}},s=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,a);s((i=i.apply(r,n)).next())}));var r,n,i}var X=Object.defineProperty,Y=Object.getOwnPropertySymbols,Z=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,ee=(e,t,r)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,te=(e,t)=>{for(var r in t||(t={}))Z.call(t,r)&&ee(e,r,t[r]);if(Y)for(var r of Y(t))_.call(t,r)&&ee(e,r,t[r]);return e};function re(t={clientOnly:!1}){return function(r){var n;const o=null!=(n=t.reactContext)?n:u.reactContext;return n=>e.createElement(o.Consumer,null,(({flags:o,ldClient:a})=>t.clientOnly?e.createElement(r,te({ldClient:a},n)):e.createElement(r,te({flags:o,ldClient:a},n))))}}const ne=e=>{const{flags:t}=i(null!=e?e:u.reactContext);return t},oe=e=>{const{ldClient:t}=i(null!=e?e:u.reactContext);return t};function ae(e){const{error:t}=i(null!=e?e:u.reactContext);return t}export{D as LDProvider,W as asyncWithLDProvider,d as camelCaseKeys,u as defaultReactOptions,p as reactSdkContextFactory,ne as useFlags,oe as useLDClient,ae as useLDClientError,re as withLDConsumer,$ as withLDProvider}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "launchdarkly-react-client-sdk", | ||
"version": "3.6.0", | ||
"version": "3.6.1", | ||
"description": "LaunchDarkly SDK for React", | ||
@@ -92,5 +92,5 @@ "author": "LaunchDarkly <team@launchdarkly.com>", | ||
"peerDependencies": { | ||
"react": "^16.6.3 || ^17.0.0 || ^18.0.0", | ||
"react-dom": "^16.8.4 || ^17.0.0 || ^18.0.0" | ||
"react": "^16.6.3 || ^17.0.0 || ^18.0.0 || ^19.0.0", | ||
"react-dom": "^16.8.4 || ^17.0.0 || ^18.0.0 || ^19.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
149788