@flagship.io/react-sdk 3.0.0 → 3.0.1

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.
@@ -157,8 +157,8 @@ export var useFsModificationInfo = function useFsModificationInfo(key) {
157
157
  });
158
158
  };
159
159
 
160
- var fsSynchronizeModifications = /*#__PURE__*/function () {
161
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(functionName, visitor, config) {
160
+ var fsActivate = /*#__PURE__*/function () {
161
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(params, functionName, visitor, config) {
162
162
  return regeneratorRuntime.wrap(function _callee$(_context) {
163
163
  while (1) {
164
164
  switch (_context.prev = _context.next) {
@@ -170,12 +170,12 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
170
170
  break;
171
171
  }
172
172
 
173
- reportNoVisitor(config, functionName);
173
+ logWarn(config, noVisitorMessage, functionName);
174
174
  return _context.abrupt("return");
175
175
 
176
176
  case 4:
177
177
  _context.next = 6;
178
- return visitor.synchronizeModifications();
178
+ return visitor.activateModifications(params);
179
179
 
180
180
  case 6:
181
181
  _context.next = 11;
@@ -184,7 +184,7 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
184
184
  case 8:
185
185
  _context.prev = 8;
186
186
  _context.t0 = _context["catch"](0);
187
- logError(config, _context.t0.message || _context.t0, functionName);
187
+ logWarn(config, _context.t0.message || _context.t0, functionName);
188
188
 
189
189
  case 11:
190
190
  case "end":
@@ -194,52 +194,10 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
194
194
  }, _callee, null, [[0, 8]]);
195
195
  }));
196
196
 
197
- return function fsSynchronizeModifications(_x, _x2, _x3) {
197
+ return function fsActivate(_x, _x2, _x3, _x4) {
198
198
  return _ref.apply(this, arguments);
199
199
  };
200
200
  }();
201
-
202
- var fsActivate = /*#__PURE__*/function () {
203
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params, functionName, visitor, config) {
204
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
205
- while (1) {
206
- switch (_context2.prev = _context2.next) {
207
- case 0:
208
- _context2.prev = 0;
209
-
210
- if (visitor) {
211
- _context2.next = 4;
212
- break;
213
- }
214
-
215
- logWarn(config, noVisitorMessage, functionName);
216
- return _context2.abrupt("return");
217
-
218
- case 4:
219
- _context2.next = 6;
220
- return visitor.activateModifications(params);
221
-
222
- case 6:
223
- _context2.next = 11;
224
- break;
225
-
226
- case 8:
227
- _context2.prev = 8;
228
- _context2.t0 = _context2["catch"](0);
229
- logWarn(config, _context2.t0.message || _context2.t0, functionName);
230
-
231
- case 11:
232
- case "end":
233
- return _context2.stop();
234
- }
235
- }
236
- }, _callee2, null, [[0, 8]]);
237
- }));
238
-
239
- return function fsActivate(_x4, _x5, _x6, _x7) {
240
- return _ref2.apply(this, arguments);
241
- };
242
- }();
243
201
  /**
244
202
  * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
245
203
  * @param key
@@ -268,29 +226,29 @@ export var useFsFlag = function useFsFlag(key, defaultValue) {
268
226
  */
269
227
 
270
228
  export var useFsActivate = /*#__PURE__*/function () {
271
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params) {
229
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params) {
272
230
  var _useContext5, state, visitor, config, functionName;
273
231
 
274
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
232
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
275
233
  while (1) {
276
- switch (_context3.prev = _context3.next) {
234
+ switch (_context2.prev = _context2.next) {
277
235
  case 0:
278
236
  _useContext5 = useContext(FlagshipContext), state = _useContext5.state;
279
237
  visitor = state.visitor, config = state.config;
280
238
  functionName = 'useFsModifications';
281
- _context3.next = 5;
239
+ _context2.next = 5;
282
240
  return fsActivate(params, functionName, visitor, config);
283
241
 
284
242
  case 5:
285
243
  case "end":
286
- return _context3.stop();
244
+ return _context2.stop();
287
245
  }
288
246
  }
289
- }, _callee3);
247
+ }, _callee2);
290
248
  }));
291
249
 
292
- return function useFsActivate(_x8) {
293
- return _ref3.apply(this, arguments);
250
+ return function useFsActivate(_x5) {
251
+ return _ref2.apply(this, arguments);
294
252
  };
295
253
  }();
296
254
  export var useFlagship = function useFlagship() {
@@ -379,60 +337,67 @@ export var useFlagship = function useFlagship() {
379
337
 
380
338
  if (!state.status.isSdkReady && state.modifications) {
381
339
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
382
- modifications = Array.from(state.modifications, function (_ref4) {
383
- var _ref5 = _slicedToArray(_ref4, 2),
384
- _key = _ref5[0],
385
- item = _ref5[1];
340
+ modifications = Array.from(state.modifications, function (_ref3) {
341
+ var _ref4 = _slicedToArray(_ref3, 2),
342
+ _key = _ref4[0],
343
+ item = _ref4[1];
386
344
 
387
345
  return item;
388
346
  });
389
347
  }
390
348
 
391
349
  var activateModification = /*#__PURE__*/function () {
392
- var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(params) {
350
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params) {
393
351
  var functionName;
394
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
352
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
395
353
  while (1) {
396
- switch (_context4.prev = _context4.next) {
354
+ switch (_context3.prev = _context3.next) {
397
355
  case 0:
398
356
  functionName = 'activateModification';
399
- _context4.next = 3;
357
+ _context3.next = 3;
400
358
  return fsActivate(params, functionName, visitor, config);
401
359
 
402
360
  case 3:
403
361
  case "end":
404
- return _context4.stop();
362
+ return _context3.stop();
405
363
  }
406
364
  }
407
- }, _callee4);
365
+ }, _callee3);
408
366
  }));
409
367
 
410
- return function activateModification(_x9) {
411
- return _ref6.apply(this, arguments);
368
+ return function activateModification(_x6) {
369
+ return _ref5.apply(this, arguments);
412
370
  };
413
371
  }();
414
372
 
415
373
  var synchronizeModifications = /*#__PURE__*/function () {
416
- var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
417
- var functionName;
418
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
374
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
375
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
419
376
  while (1) {
420
- switch (_context5.prev = _context5.next) {
377
+ switch (_context4.prev = _context4.next) {
421
378
  case 0:
422
- functionName = 'synchronizeModifications';
423
- _context5.next = 3;
424
- return fsSynchronizeModifications(functionName, visitor, config);
379
+ if (visitor) {
380
+ _context4.next = 3;
381
+ break;
382
+ }
383
+
384
+ logWarn(config, noVisitorMessage, 'synchronizeModifications');
385
+ return _context4.abrupt("return");
425
386
 
426
387
  case 3:
388
+ _context4.next = 5;
389
+ return visitor.synchronizeModifications();
390
+
391
+ case 5:
427
392
  case "end":
428
- return _context5.stop();
393
+ return _context4.stop();
429
394
  }
430
395
  }
431
- }, _callee5);
396
+ }, _callee4);
432
397
  }));
433
398
 
434
399
  return function synchronizeModifications() {
435
- return _ref7.apply(this, arguments);
400
+ return _ref6.apply(this, arguments);
436
401
  };
437
402
  }();
438
403
 
@@ -470,7 +435,7 @@ export var useFlagship = function useFlagship() {
470
435
  return Promise.resolve();
471
436
  }
472
437
 
473
- return visitor === null || visitor === void 0 ? void 0 : visitor.fetchFlags();
438
+ return visitor.fetchFlags();
474
439
  }
475
440
 
476
441
  function setConsent(hasConsented) {
@@ -506,8 +471,4 @@ export var useFlagship = function useFlagship() {
506
471
  getFlag: getFlag,
507
472
  fetchFlags: fetchFlags
508
473
  };
509
- };
510
-
511
- var reportNoVisitor = function reportNoVisitor(config, tag) {
512
- logError(config, noVisitorMessage, tag);
513
474
  };
@@ -1,2 +1,2 @@
1
- export var noVisitorMessage = 'sdk not correctly initialized... Make sure fsVisitor is ready.';
1
+ export var noVisitorMessage = 'flagship Visitor not initialized.';
2
2
  export var noVisitorDefault = 'fsVisitor not initialized, returns default value';
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { LogLevel } from '@flagship.io/js-sdk';
2
+ import { useEffect, useRef } from 'react';
2
3
  export function logError(config, message, tag) {
3
4
  if (!config || !config.logManager || typeof config.logManager.error !== 'function' || !config.logLevel || config.logLevel < LogLevel.ERROR) {
4
5
  return;
@@ -60,4 +61,17 @@ export function uuidV4() {
60
61
  var value = char === 'x' ? rand : rand & 0x3 | 0x8;
61
62
  return value.toString(16);
62
63
  });
64
+ }
65
+ export function useNonInitialEffect(effect, deps) {
66
+ var initialRender = useRef(true);
67
+ useEffect(function () {
68
+ if (initialRender.current) {
69
+ initialRender.current = false;
70
+ return;
71
+ }
72
+
73
+ if (typeof effect === 'function') {
74
+ return effect();
75
+ }
76
+ }, deps);
63
77
  }