neo.mjs 6.5.3 → 6.5.4

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.
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
20
20
  */
21
21
  singleton: true,
22
22
  /**
23
- * @member {String} version='6.5.3'
23
+ * @member {String} version='6.5.4'
24
24
  */
25
- version: '6.5.3'
25
+ version: '6.5.4'
26
26
  }
27
27
 
28
28
  /**
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
20
20
  */
21
21
  singleton: true,
22
22
  /**
23
- * @member {String} version='6.5.3'
23
+ * @member {String} version='6.5.4'
24
24
  */
25
- version: '6.5.3'
25
+ version: '6.5.4'
26
26
  }
27
27
 
28
28
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "6.5.3",
3
+ "version": "6.5.4",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -236,12 +236,12 @@ const DefaultConfig = {
236
236
  useVdomWorker: true,
237
237
  /**
238
238
  * buildScripts/injectPackageVersion.mjs will update this value
239
- * @default '6.5.3'
239
+ * @default '6.5.4'
240
240
  * @memberOf! module:Neo
241
241
  * @name config.version
242
242
  * @type String
243
243
  */
244
- version: '6.5.3'
244
+ version: '6.5.4'
245
245
  };
246
246
 
247
247
  Object.assign(DefaultConfig, {
package/src/core/Base.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {debounce} from '../util/Function.mjs';
2
- import IdGenerator from './IdGenerator.mjs'
1
+ import {debounce, throttle} from '../util/Function.mjs';
2
+ import IdGenerator from './IdGenerator.mjs'
3
3
 
4
4
  const configSymbol = Symbol.for('configSymbol'),
5
5
  forceAssignConfigs = Symbol('forceAssignConfigs'),
@@ -182,9 +182,8 @@ class Base {
182
182
 
183
183
  Object.entries(me.constructor.delayable).forEach(([key, value]) => {
184
184
  let map = {
185
- debounce() {
186
- me[key] = new debounce(me[key], me, value.timer)
187
- }
185
+ debounce() {me[key] = new debounce(me[key], me, value.timer)},
186
+ throttle() {me[key] = new throttle(me[key], me, value.timer)}
188
187
  };
189
188
 
190
189
  map[value.type]?.()
@@ -45,30 +45,30 @@ export function createSequence(target, methodName, fn, scope) {
45
45
  }
46
46
 
47
47
  /**
48
- * @param {Function} func
48
+ * @param {Function} callback
49
49
  * @param {Neo.core.Base} scope
50
- * @param {Number} timeout=300
50
+ * @param {Number} delay=300
51
51
  * @returns {Function}
52
52
  */
53
- export function debounce(func, scope, timeout=300) {
53
+ export function debounce(callback, scope, delay=300) {
54
54
  let debounceTimer;
55
55
 
56
56
  return function(...args) {
57
57
  // leading edge => trigger the first call right away
58
58
  if (!Neo.isNumber(debounceTimer)) {
59
59
  // we need to check if the scope (instance) did not get destroyed yet
60
- scope?.id && func.apply(scope, args);
60
+ scope?.id && callback.apply(scope, args);
61
61
 
62
62
  // we still want to start a timer, do delay the 2nd+ update
63
- debounceTimer = setTimeout(() => {debounceTimer = null}, timeout)
63
+ debounceTimer = setTimeout(() => {debounceTimer = null}, delay)
64
64
  } else {
65
65
  clearTimeout(debounceTimer);
66
66
 
67
67
  debounceTimer = setTimeout(() => {
68
68
  // we need to check if the scope (instance) did not get destroyed yet
69
- scope?.id && func.apply(scope, args);
70
- debounceTimer = setTimeout(() => {debounceTimer = null}, timeout)
71
- }, timeout)
69
+ scope?.id && callback.apply(scope, args);
70
+ debounceTimer = setTimeout(() => {debounceTimer = null}, delay)
71
+ }, delay)
72
72
  }
73
73
  }
74
74
  }
@@ -91,3 +91,24 @@ export function intercept(target, targetMethodName, interceptFunction, scope, pr
91
91
  : targetMethod.apply(target, arguments)
92
92
  })
93
93
  }
94
+
95
+ /**
96
+ * @param {Function} callback
97
+ * @param {Neo.core.Base} scope
98
+ * @param {Number} delay=300
99
+ * @returns {Function}
100
+ */
101
+ export function throttle(callback, scope, delay=300) {
102
+ let wait = false;
103
+
104
+ return function(...args) {
105
+ if (!wait) {
106
+ wait = true;
107
+
108
+ // we need to check if the scope (instance) did not get destroyed yet
109
+ scope?.id && callback.apply(scope, args);
110
+
111
+ setTimeout(() => {wait = false}, delay)
112
+ }
113
+ }
114
+ }