UNPKG

featuretoggle-react

Version:

Library to use Feature Toggles of your choice in a React application

58 lines (44 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.launchdarklyClient = exports.LaunchdarklyClientClass = void 0; var _launchdarklyJsClientSdk = require("launchdarkly-js-client-sdk"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var LaunchdarklyClientClass = /*#__PURE__*/function () { function LaunchdarklyClientClass(_ref) { var clientSideId = _ref.clientSideId, user = _ref.user; _classCallCheck(this, LaunchdarklyClientClass); this.fetching = false; this.clientSideId = clientSideId; this.user = user; this.init = this.init.bind(this); } _createClass(LaunchdarklyClientClass, [{ key: "init", value: function init(handler) { if (!this.fetching) { var client = (0, _launchdarklyJsClientSdk.initialize)(this.clientSideId, this.user); client.on('ready', function () { var features = client.allFlags(); handler(features); }); } this.fetching = true; } }]); return LaunchdarklyClientClass; }(); exports.LaunchdarklyClientClass = LaunchdarklyClientClass; var launchdarklyClient = function launchdarklyClient(_ref2) { var clientSideId = _ref2.clientSideId, user = _ref2.user; return new LaunchdarklyClientClass({ clientSideId: clientSideId, user: user }); }; exports.launchdarklyClient = launchdarklyClient;