launchdarkly-react-client-sdk
Advanced tools
Comparing version 3.0.10 to 3.1.0
@@ -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 a={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},i=e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:l,Consumer:c}=i,u=e=>{var t;return null!=(t=e.context)?t:e.user},p=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},f=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},y=(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};p.camelCaseKeys=p;var d=Object.defineProperty,b=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,h=(e,t,r)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,v=(e,t)=>{for(var r in t||(t={}))g.call(t,r)&&h(e,r,t[r]);if(b)for(var r of b(t))O.call(t,r)&&h(e,r,t[r]);return e};const m={wrapperName:"react-client-sdk",wrapperVersion:"3.0.10",sendEventsOnlyForVariation:!0},j=(e,...r)=>{return n=void 0,o=[e,...r],s=function*(e,r={anonymous:!0,kind:"user"},n,o){const s=t.initialize(e,r,v(v({},m),n));return new Promise((e=>{function t(){s.off("ready",n),s.off("failed",r)}function r(r){t(),e({flags:{},ldClient:s,error:r})}function n(){t();const r=y(s,o);e({flags:r,ldClient:s})}s.on("failed",r),s.on("ready",n)}))},new Promise(((e,t)=>{var r=e=>{try{i(s.next(e))}catch(e){t(e)}},a=e=>{try{i(s.throw(e))}catch(e){t(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,a);i((s=s.apply(n,o)).next())}));var n,o,s};function C(e,t,n=a,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(P(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?x(e,l,c,i):l,flagKeyMap:c}}function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function x(e,t,r,n){return new Proxy(t,{get(t,o,s){const a=Reflect.get(t,o,s),i=n&&P(r,o)||P(t,o);if("symbol"==typeof o||!i)return a;if(void 0===a)return;const l=n?r[o]:o;return e.variation(l,a)}})}var w=Object.defineProperty,E=Object.defineProperties,F=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,k=(e,t,r)=>t in e?w(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)&&k(e,r,t[r]);if(D)for(var r of D(t))S.call(t,r)&&k(e,r,t[r]);return e},L=(e,t,r)=>(k(e,"symbol"!=typeof t?t+"":t,r),r),M=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{i(r.next(e))}catch(e){o(e)}},a=e=>{try{i(r.throw(e))}catch(e){o(e)}},i=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);i((r=r.apply(e,t)).next())}));class R extends e.Component{constructor(e){super(e),L(this,"state"),L(this,"getReactOptions",(()=>I(I({},a),this.props.reactOptions))),L(this,"subscribeToChanges",(e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=f(r,t),s=I(I({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState(I({unproxiedFlags:s},C(e,s,n,t)))}))})),L(this,"initLDClient",(()=>M(this,null,(function*(){const{clientSideID:e,flags:t,options:r}=this.props;let n=yield this.props.ldClient;const o=this.getReactOptions();let s,a=this.state.unproxiedFlags;if(n)a=y(n,t);else{const o=yield j(e,u(this.props),r,t);s=o.error,s||(a=o.flags),n=o.ldClient}var i;this.setState((i=I({unproxiedFlags:a},C(n,a,o,t)),E(i,F({ldClient:n,error:s})))),this.subscribeToChanges(n)}))));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{},ldClient:void 0},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?p(e):e,unproxiedFlags:e,flagKeyMap:{},ldClient:void 0}}}}componentDidMount(){return M(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!u(this.props)||(yield this.initLDClient())}))}componentDidUpdate(e){return M(this,null,(function*(){const{deferInitialization:t}=this.props,r=!u(e)&&u(this.props);t&&r&&(yield this.initLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state;return e.createElement(l,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var q=Object.defineProperty,z=Object.defineProperties,T=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,U=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t)=>{for(var r in t||(t={}))$.call(t,r)&&U(e,r,t[r]);if(V)for(var r of V(t))N.call(t,r)&&U(e,r,t[r]);return e};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};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};exports.LDProvider=R,exports.asyncWithLDProvider=function(t){return r=this,n=null,o=function*(){const{clientSideID:r,flags:n,options:o,reactOptions:s}=t,i=Q(Q({},a),s),{ldClient:c,flags:p,error:y}=yield j(r,u(t),o,n),d=(null==o?void 0:o.bootstrap)&&"localStorage"!==o.bootstrap?o.bootstrap:p;return({children:t})=>{const[r,o]=e.useState((()=>Q({unproxiedFlags:d},C(c,d,i,n))));e.useEffect((()=>{function e(e){const t=f(e,n);Object.keys(t).length>0&&o((({unproxiedFlags:e})=>{const r=Q(Q({},e),t);return Q({unproxiedFlags:r},C(c,r,i,n))}))}return c.on("change",e),function(){c.off("change",e)}}),[]);const{flags:s,flagKeyMap:a}=r;return e.createElement(l,{value:{flags:s,flagKeyMap:a,ldClient:c,error:y}},t)}},new Promise(((e,t)=>{var s=e=>{try{i(o.next(e))}catch(e){t(e)}},a=e=>{try{i(o.throw(e))}catch(e){t(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,a);i((o=o.apply(r,n)).next())}));var r,n,o},exports.camelCaseKeys=p,exports.defaultReactOptions=a,exports.useFlags=()=>{const{flags:t}=e.useContext(i);return t},exports.useLDClient=()=>{const{ldClient:t}=e.useContext(i);return t},exports.useLDClientError=function(){const{error:t}=e.useContext(i);return t},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){return r=>s.createElement(c,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,te({ldClient:o},r)):s.createElement(t,te({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=W(W({},a),r),i=(l=W({},e),z(l,T({reactOptions:o})));var l;function c(e){return s.createElement(R,W({},i),s.createElement(t,W({},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 a={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},i=e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:l,Consumer:c}=i,u=e=>{var t;return null!=(t=e.context)?t:e.user},p=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},f=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},y=(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};p.camelCaseKeys=p;var d=Object.defineProperty,b=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,h=(e,t,r)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,v=(e,t)=>{for(var r in t||(t={}))g.call(t,r)&&h(e,r,t[r]);if(b)for(var r of b(t))O.call(t,r)&&h(e,r,t[r]);return e};const m={wrapperName:"react-client-sdk",wrapperVersion:"3.1.0",sendEventsOnlyForVariation:!0},j=(e,...r)=>{return n=void 0,o=[e,...r],s=function*(e,r={anonymous:!0,kind:"user"},n,o){const s=t.initialize(e,r,v(v({},m),n));return new Promise((e=>{function t(){s.off("ready",n),s.off("failed",r)}function r(r){t(),e({flags:{},ldClient:s,error:r})}function n(){t();const r=y(s,o);e({flags:r,ldClient:s})}s.on("failed",r),s.on("ready",n)}))},new Promise(((e,t)=>{var r=e=>{try{i(s.next(e))}catch(e){t(e)}},a=e=>{try{i(s.throw(e))}catch(e){t(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,a);i((s=s.apply(n,o)).next())}));var n,o,s};function C(e,t,n=a,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(P(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?x(e,l,c,i):l,flagKeyMap:c}}function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function x(e,t,r,n){return new Proxy(t,{get(t,o,s){const a=Reflect.get(t,o,s),i=n&&P(r,o)||P(t,o);if("symbol"==typeof o||!i)return a;if(void 0===a)return;const l=n?r[o]:o;return e.variation(l,a)}})}var w=Object.defineProperty,E=Object.defineProperties,F=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,k=(e,t,r)=>t in e?w(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)&&k(e,r,t[r]);if(D)for(var r of D(t))S.call(t,r)&&k(e,r,t[r]);return e},L=(e,t,r)=>(k(e,"symbol"!=typeof t?t+"":t,r),r),M=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{i(r.next(e))}catch(e){o(e)}},a=e=>{try{i(r.throw(e))}catch(e){o(e)}},i=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);i((r=r.apply(e,t)).next())}));class R extends e.Component{constructor(e){super(e),L(this,"state"),L(this,"getReactOptions",(()=>I(I({},a),this.props.reactOptions))),L(this,"subscribeToChanges",(e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=f(r,t),s=I(I({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState(I({unproxiedFlags:s},C(e,s,n,t)))}))})),L(this,"initLDClient",(()=>M(this,null,(function*(){const{clientSideID:e,flags:t,options:r}=this.props;let n=yield this.props.ldClient;const o=this.getReactOptions();let s,a=this.state.unproxiedFlags;if(n)a=y(n,t);else{const o=yield j(e,u(this.props),r,t);s=o.error,s||(a=o.flags),n=o.ldClient}var i;this.setState((i=I({unproxiedFlags:a},C(n,a,o,t)),E(i,F({ldClient:n,error:s})))),this.subscribeToChanges(n)}))));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{},ldClient:void 0},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?p(e):e,unproxiedFlags:e,flagKeyMap:{},ldClient:void 0}}}}componentDidMount(){return M(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!u(this.props)||(yield this.initLDClient())}))}componentDidUpdate(e){return M(this,null,(function*(){const{deferInitialization:t}=this.props,r=!u(e)&&u(this.props);t&&r&&(yield this.initLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state;return e.createElement(l,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var q=Object.defineProperty,z=Object.defineProperties,T=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,U=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t)=>{for(var r in t||(t={}))$.call(t,r)&&U(e,r,t[r]);if(V)for(var r of V(t))N.call(t,r)&&U(e,r,t[r]);return e};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};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};exports.LDProvider=R,exports.asyncWithLDProvider=function(t){return r=this,n=null,o=function*(){const{clientSideID:r,flags:n,options:o,reactOptions:s}=t,i=Q(Q({},a),s),{ldClient:c,flags:p,error:y}=yield j(r,u(t),o,n),d=(null==o?void 0:o.bootstrap)&&"localStorage"!==o.bootstrap?o.bootstrap:p;return({children:t})=>{const[r,o]=e.useState((()=>Q({unproxiedFlags:d},C(c,d,i,n))));e.useEffect((()=>{function e(e){const t=f(e,n);Object.keys(t).length>0&&o((({unproxiedFlags:e})=>{const r=Q(Q({},e),t);return Q({unproxiedFlags:r},C(c,r,i,n))}))}return c.on("change",e),function(){c.off("change",e)}}),[]);const{flags:s,flagKeyMap:a}=r;return e.createElement(l,{value:{flags:s,flagKeyMap:a,ldClient:c,error:y}},t)}},new Promise(((e,t)=>{var s=e=>{try{i(o.next(e))}catch(e){t(e)}},a=e=>{try{i(o.throw(e))}catch(e){t(e)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,a);i((o=o.apply(r,n)).next())}));var r,n,o},exports.camelCaseKeys=p,exports.defaultReactOptions=a,exports.useFlags=()=>{const{flags:t}=e.useContext(i);return t},exports.useLDClient=()=>{const{ldClient:t}=e.useContext(i);return t},exports.useLDClientError=function(){const{error:t}=e.useContext(i);return t},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){return r=>s.createElement(c,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,te({ldClient:o},r)):s.createElement(t,te({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=W(W({},a),r),i=(l=W({},e),z(l,T({reactOptions:o})));var l;function c(e){return s.createElement(R,W({},i),s.createElement(t,W({},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 s,useContext as a}from"react";import{initialize as l}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import i from"lodash.camelcase";import c from"hoist-non-react-statics";const p={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},u=r({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:f,Consumer:y}=u,d=e=>{var t;return null!=(t=e.context)?t:e.user},g=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[i(r)]=e[r]);return t},b=(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};g.camelCaseKeys=g;var O=Object.defineProperty,m=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,w=(e,t)=>{for(var r in t||(t={}))v.call(t,r)&&P(e,r,t[r]);if(m)for(var r of m(t))j.call(t,r)&&P(e,r,t[r]);return e};const C={wrapperName:"react-client-sdk",wrapperVersion:"3.0.10",sendEventsOnlyForVariation:!0},x=(e,...t)=>{return r=void 0,n=[e,...t],o=function*(e,t={anonymous:!0,kind:"user"},r,n){const o=l(e,t,w(w({},C),r));return new Promise((e=>{function t(){o.off("ready",s),o.off("failed",r)}function r(r){t(),e({flags:{},ldClient:o,error:r})}function s(){t();const r=h(o,n);e({flags:r,ldClient:o})}o.on("failed",r),o.on("ready",s)}))},new Promise(((e,t)=>{var s=e=>{try{l(o.next(e))}catch(e){t(e)}},a=e=>{try{l(o.throw(e))}catch(e){t(e)}},l=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,a);l((o=o.apply(r,n)).next())}));var r,n,o};function F(e,t,r=p,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(E(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:s=!0}=r,[a,l={}]=s?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=i(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?K(e,a,l,s):a,flagKeyMap:l}}function E(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function K(e,t,r,n){return new Proxy(t,{get(t,o,s){const a=Reflect.get(t,o,s),l=n&&E(r,o)||E(t,o);if("symbol"==typeof o||!l)return a;if(void 0===a)return;const i=n?r[o]:o;return e.variation(i,a)}})}var S=Object.defineProperty,k=Object.defineProperties,D=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,L=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,z=(e,t)=>{for(var r in t||(t={}))M.call(t,r)&&L(e,r,t[r]);if(I)for(var r of I(t))R.call(t,r)&&L(e,r,t[r]);return e},T=(e,t,r)=>(L(e,"symbol"!=typeof t?t+"":t,r),r),V=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{l(r.next(e))}catch(e){o(e)}},a=e=>{try{l(r.throw(e))}catch(e){o(e)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);l((r=r.apply(e,t)).next())}));class $ extends n{constructor(e){super(e),T(this,"state"),T(this,"getReactOptions",(()=>z(z({},p),this.props.reactOptions))),T(this,"subscribeToChanges",(e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=b(r,t),s=z(z({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState(z({unproxiedFlags:s},F(e,s,n,t)))}))})),T(this,"initLDClient",(()=>V(this,null,(function*(){const{clientSideID:e,flags:t,options:r}=this.props;let n=yield this.props.ldClient;const o=this.getReactOptions();let s,a=this.state.unproxiedFlags;if(n)a=h(n,t);else{const o=yield x(e,d(this.props),r,t);s=o.error,s||(a=o.flags),n=o.ldClient}var l;this.setState((l=z({unproxiedFlags:a},F(n,a,o,t)),k(l,D({ldClient:n,error:s})))),this.subscribeToChanges(n)}))));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{},ldClient:void 0},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?g(e):e,unproxiedFlags:e,flagKeyMap:{},ldClient:void 0}}}}componentDidMount(){return V(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!d(this.props)||(yield this.initLDClient())}))}componentDidUpdate(e){return V(this,null,(function*(){const{deferInitialization:t}=this.props,r=!d(e)&&d(this.props);t&&r&&(yield this.initLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state;return t.createElement(f,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}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};function Q(t){return function(r){const{reactOptions:n}=t,o=J(J({},p),n),s=(a=J({},t),U(a,q({reactOptions:o})));var a;function l(t){return e.createElement($,J({},s),e.createElement(r,J({},t)))}return c(l,r),l}}var W=Object.defineProperty,X=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,_=(e,t,r)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ee=(e,t)=>{for(var r in t||(t={}))Y.call(t,r)&&_(e,r,t[r]);if(X)for(var r of X(t))Z.call(t,r)&&_(e,r,t[r]);return e};function te(e){return r=this,n=null,a=function*(){const{clientSideID:r,flags:n,options:a,reactOptions:l}=e,i=ee(ee({},p),l),{ldClient:c,flags:u,error:y}=yield x(r,d(e),a,n),g=(null==a?void 0:a.bootstrap)&&"localStorage"!==a.bootstrap?a.bootstrap:u;return({children:e})=>{const[r,a]=o((()=>ee({unproxiedFlags:g},F(c,g,i,n))));s((()=>{function e(e){const t=b(e,n);Object.keys(t).length>0&&a((({unproxiedFlags:e})=>{const r=ee(ee({},e),t);return ee({unproxiedFlags:r},F(c,r,i,n))}))}return c.on("change",e),function(){c.off("change",e)}}),[]);const{flags:l,flagKeyMap:p}=r;return t.createElement(f,{value:{flags:l,flagKeyMap:p,ldClient:c,error:y}},e)}},new Promise(((e,t)=>{var o=e=>{try{l(a.next(e))}catch(e){t(e)}},s=e=>{try{l(a.throw(e))}catch(e){t(e)}},l=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,s);l((a=a.apply(r,n)).next())}));var r,n,a}var re=Object.defineProperty,ne=Object.getOwnPropertySymbols,oe=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ae=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,le=(e,t)=>{for(var r in t||(t={}))oe.call(t,r)&&ae(e,r,t[r]);if(ne)for(var r of ne(t))se.call(t,r)&&ae(e,r,t[r]);return e};function ie(t={clientOnly:!1}){return function(r){return n=>e.createElement(y,null,(({flags:o,ldClient:s})=>t.clientOnly?e.createElement(r,le({ldClient:s},n)):e.createElement(r,le({flags:o,ldClient:s},n))))}}const ce=()=>{const{flags:e}=a(u);return e},pe=()=>{const{ldClient:e}=a(u);return e};function ue(){const{error:e}=a(u);return e}export{$ as LDProvider,te as asyncWithLDProvider,g as camelCaseKeys,p as defaultReactOptions,ce as useFlags,pe as useLDClient,ue as useLDClientError,ie as withLDConsumer,Q as withLDProvider}; | ||
import*as e from"react";import t,{createContext as r,Component as n,useState as o,useEffect as s,useContext as a}from"react";import{initialize as l}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import i from"lodash.camelcase";import c from"hoist-non-react-statics";const p={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},u=r({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:f,Consumer:y}=u,d=e=>{var t;return null!=(t=e.context)?t:e.user},g=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[i(r)]=e[r]);return t},b=(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};g.camelCaseKeys=g;var O=Object.defineProperty,m=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,w=(e,t)=>{for(var r in t||(t={}))v.call(t,r)&&P(e,r,t[r]);if(m)for(var r of m(t))j.call(t,r)&&P(e,r,t[r]);return e};const C={wrapperName:"react-client-sdk",wrapperVersion:"3.1.0",sendEventsOnlyForVariation:!0},x=(e,...t)=>{return r=void 0,n=[e,...t],o=function*(e,t={anonymous:!0,kind:"user"},r,n){const o=l(e,t,w(w({},C),r));return new Promise((e=>{function t(){o.off("ready",s),o.off("failed",r)}function r(r){t(),e({flags:{},ldClient:o,error:r})}function s(){t();const r=h(o,n);e({flags:r,ldClient:o})}o.on("failed",r),o.on("ready",s)}))},new Promise(((e,t)=>{var s=e=>{try{l(o.next(e))}catch(e){t(e)}},a=e=>{try{l(o.throw(e))}catch(e){t(e)}},l=t=>t.done?e(t.value):Promise.resolve(t.value).then(s,a);l((o=o.apply(r,n)).next())}));var r,n,o};function F(e,t,r=p,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(E(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:s=!0}=r,[a,l={}]=s?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=i(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?K(e,a,l,s):a,flagKeyMap:l}}function E(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function K(e,t,r,n){return new Proxy(t,{get(t,o,s){const a=Reflect.get(t,o,s),l=n&&E(r,o)||E(t,o);if("symbol"==typeof o||!l)return a;if(void 0===a)return;const i=n?r[o]:o;return e.variation(i,a)}})}var S=Object.defineProperty,k=Object.defineProperties,D=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,L=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,z=(e,t)=>{for(var r in t||(t={}))M.call(t,r)&&L(e,r,t[r]);if(I)for(var r of I(t))R.call(t,r)&&L(e,r,t[r]);return e},T=(e,t,r)=>(L(e,"symbol"!=typeof t?t+"":t,r),r),V=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{l(r.next(e))}catch(e){o(e)}},a=e=>{try{l(r.throw(e))}catch(e){o(e)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);l((r=r.apply(e,t)).next())}));class $ extends n{constructor(e){super(e),T(this,"state"),T(this,"getReactOptions",(()=>z(z({},p),this.props.reactOptions))),T(this,"subscribeToChanges",(e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=b(r,t),s=z(z({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState(z({unproxiedFlags:s},F(e,s,n,t)))}))})),T(this,"initLDClient",(()=>V(this,null,(function*(){const{clientSideID:e,flags:t,options:r}=this.props;let n=yield this.props.ldClient;const o=this.getReactOptions();let s,a=this.state.unproxiedFlags;if(n)a=h(n,t);else{const o=yield x(e,d(this.props),r,t);s=o.error,s||(a=o.flags),n=o.ldClient}var l;this.setState((l=z({unproxiedFlags:a},F(n,a,o,t)),k(l,D({ldClient:n,error:s})))),this.subscribeToChanges(n)}))));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{},ldClient:void 0},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?g(e):e,unproxiedFlags:e,flagKeyMap:{},ldClient:void 0}}}}componentDidMount(){return V(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!d(this.props)||(yield this.initLDClient())}))}componentDidUpdate(e){return V(this,null,(function*(){const{deferInitialization:t}=this.props,r=!d(e)&&d(this.props);t&&r&&(yield this.initLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state;return t.createElement(f,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}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};function Q(t){return function(r){const{reactOptions:n}=t,o=J(J({},p),n),s=(a=J({},t),U(a,q({reactOptions:o})));var a;function l(t){return e.createElement($,J({},s),e.createElement(r,J({},t)))}return c(l,r),l}}var W=Object.defineProperty,X=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,_=(e,t,r)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ee=(e,t)=>{for(var r in t||(t={}))Y.call(t,r)&&_(e,r,t[r]);if(X)for(var r of X(t))Z.call(t,r)&&_(e,r,t[r]);return e};function te(e){return r=this,n=null,a=function*(){const{clientSideID:r,flags:n,options:a,reactOptions:l}=e,i=ee(ee({},p),l),{ldClient:c,flags:u,error:y}=yield x(r,d(e),a,n),g=(null==a?void 0:a.bootstrap)&&"localStorage"!==a.bootstrap?a.bootstrap:u;return({children:e})=>{const[r,a]=o((()=>ee({unproxiedFlags:g},F(c,g,i,n))));s((()=>{function e(e){const t=b(e,n);Object.keys(t).length>0&&a((({unproxiedFlags:e})=>{const r=ee(ee({},e),t);return ee({unproxiedFlags:r},F(c,r,i,n))}))}return c.on("change",e),function(){c.off("change",e)}}),[]);const{flags:l,flagKeyMap:p}=r;return t.createElement(f,{value:{flags:l,flagKeyMap:p,ldClient:c,error:y}},e)}},new Promise(((e,t)=>{var o=e=>{try{l(a.next(e))}catch(e){t(e)}},s=e=>{try{l(a.throw(e))}catch(e){t(e)}},l=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,s);l((a=a.apply(r,n)).next())}));var r,n,a}var re=Object.defineProperty,ne=Object.getOwnPropertySymbols,oe=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ae=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,le=(e,t)=>{for(var r in t||(t={}))oe.call(t,r)&&ae(e,r,t[r]);if(ne)for(var r of ne(t))se.call(t,r)&&ae(e,r,t[r]);return e};function ie(t={clientOnly:!1}){return function(r){return n=>e.createElement(y,null,(({flags:o,ldClient:s})=>t.clientOnly?e.createElement(r,le({ldClient:s},n)):e.createElement(r,le({flags:o,ldClient:s},n))))}}const ce=()=>{const{flags:e}=a(u);return e},pe=()=>{const{ldClient:e}=a(u);return e};function ue(){const{error:e}=a(u);return e}export{$ as LDProvider,te as asyncWithLDProvider,g as camelCaseKeys,p as defaultReactOptions,ce as useFlags,pe as useLDClient,ue as useLDClientError,ie as withLDConsumer,Q as withLDProvider}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "launchdarkly-react-client-sdk", | ||
"version": "3.0.10", | ||
"version": "3.1.0", | ||
"description": "LaunchDarkly SDK for React", | ||
@@ -58,2 +58,3 @@ "author": "LaunchDarkly <team@launchdarkly.com>", | ||
"@types/lodash.camelcase": "^4.3.6", | ||
"@types/node": "^14.14.31", | ||
"@types/prop-types": "^15.7.4", | ||
@@ -86,3 +87,3 @@ "@types/react": "^18.0.3", | ||
"hoist-non-react-statics": "^3.3.2", | ||
"launchdarkly-js-client-sdk": "^3.1.4", | ||
"launchdarkly-js-client-sdk": "^3.2.0", | ||
"lodash.camelcase": "^4.3.0" | ||
@@ -89,0 +90,0 @@ }, |
@@ -43,3 +43,4 @@ # LaunchDarkly Client-side SDK for React | ||
* Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file. | ||
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline. | ||
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). | ||
* Disable parts of your application to facilitate maintenance, without taking everything offline. | ||
* LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list. | ||
@@ -46,0 +47,0 @@ * Explore LaunchDarkly |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137137
51
34