@suprsend/web-sdk 1.0.0 → 1.2.0

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.
package/src/user.js CHANGED
@@ -2,10 +2,12 @@ import utils from "./utils";
2
2
  import config from "./config";
3
3
  import { regex, constants } from "./constants";
4
4
  import { parsePhoneNumber } from "libphonenumber-js";
5
+ import Preferences from "./preferences";
5
6
 
6
7
  class User {
7
- constructor(instance) {
8
+ constructor(instance, emitter) {
8
9
  this.instance = instance;
10
+ this.preferences = new Preferences(this.instance, emitter);
9
11
  }
10
12
 
11
13
  _call_indentity(properties) {
package/src/utils.js CHANGED
@@ -257,6 +257,35 @@ const is_empty = (value) => {
257
257
  }
258
258
  };
259
259
 
260
+ function debounce(func, timeOut) {
261
+ let timer;
262
+
263
+ return (...args) => {
264
+ if (timer) clearTimeout(timer);
265
+ timer = setTimeout(() => {
266
+ func.apply(this, args);
267
+ }, timeOut);
268
+ return timer;
269
+ };
270
+ }
271
+
272
+ // https://gist.github.com/nzvtrk/1a444cdf6a86a5a6e6d6a34f0db19065
273
+ function debounce_by_type(func, wait, options) {
274
+ const memory = {};
275
+
276
+ return (...args) => {
277
+ const [searchType] = args;
278
+ const payload = args.slice(1);
279
+
280
+ if (typeof memory[searchType] === "function") {
281
+ return memory[searchType](...payload);
282
+ }
283
+
284
+ memory[searchType] = debounce(func, wait, { ...options, leading: true });
285
+ return memory[searchType](...payload);
286
+ };
287
+ }
288
+
260
289
  export default {
261
290
  uuid,
262
291
  epoch_milliseconds,
@@ -281,4 +310,5 @@ export default {
281
310
  bulk_call_api,
282
311
  is_internal_event,
283
312
  api,
313
+ debounce_by_type,
284
314
  };