neo.mjs 6.5.3 → 6.5.5
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/apps/ServiceWorker.mjs +2 -2
- package/examples/ServiceWorker.mjs +2 -2
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +2 -2
- package/src/core/Base.mjs +4 -5
- package/src/form/field/Text.mjs +0 -11
- package/src/util/Function.mjs +38 -8
package/apps/ServiceWorker.mjs
CHANGED
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -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.
|
239
|
+
* @default '6.5.5'
|
240
240
|
* @memberOf! module:Neo
|
241
241
|
* @name config.version
|
242
242
|
* @type String
|
243
243
|
*/
|
244
|
-
version: '6.5.
|
244
|
+
version: '6.5.5'
|
245
245
|
};
|
246
246
|
|
247
247
|
Object.assign(DefaultConfig, {
|
package/src/core/Base.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {debounce}
|
2
|
-
import IdGenerator
|
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
|
-
|
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]?.()
|
package/src/form/field/Text.mjs
CHANGED
@@ -17,17 +17,6 @@ class Text extends Base {
|
|
17
17
|
* @static
|
18
18
|
*/
|
19
19
|
static autoCapitalizeValues = ['characters', 'none', 'on', 'off', 'sentences', 'words']
|
20
|
-
/**
|
21
|
-
* @member {Object} delayable
|
22
|
-
* @protected
|
23
|
-
* @static
|
24
|
-
*/
|
25
|
-
static delayable = {
|
26
|
-
fireChangeEvent: {
|
27
|
-
type : 'debounce',
|
28
|
-
timer: 300
|
29
|
-
}
|
30
|
-
}
|
31
20
|
/**
|
32
21
|
* Valid values for labelPosition
|
33
22
|
* @member {String[]} labelPositions=['bottom','inline','left','right','top']
|
package/src/util/Function.mjs
CHANGED
@@ -45,30 +45,30 @@ export function createSequence(target, methodName, fn, scope) {
|
|
45
45
|
}
|
46
46
|
|
47
47
|
/**
|
48
|
-
* @param {Function}
|
48
|
+
* @param {Function} callback
|
49
49
|
* @param {Neo.core.Base} scope
|
50
|
-
* @param {Number}
|
50
|
+
* @param {Number} delay=300
|
51
51
|
* @returns {Function}
|
52
52
|
*/
|
53
|
-
export function debounce(
|
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 &&
|
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},
|
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 &&
|
70
|
-
debounceTimer = setTimeout(() => {debounceTimer = null},
|
71
|
-
},
|
69
|
+
scope?.id && callback.apply(scope, args);
|
70
|
+
debounceTimer = setTimeout(() => {debounceTimer = null}, delay)
|
71
|
+
}, delay)
|
72
72
|
}
|
73
73
|
}
|
74
74
|
}
|
@@ -91,3 +91,33 @@ 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 lastRanDate, timeoutId;
|
103
|
+
|
104
|
+
return function(...args) {
|
105
|
+
if (!lastRanDate) {
|
106
|
+
// we need to check if the scope (instance) did not get destroyed yet
|
107
|
+
scope?.id && callback.apply(scope, args);
|
108
|
+
|
109
|
+
lastRanDate = Date.now()
|
110
|
+
} else {
|
111
|
+
clearTimeout(timeoutId)
|
112
|
+
|
113
|
+
timeoutId = setTimeout(function() {
|
114
|
+
if ((Date.now() - lastRanDate) >= delay) {
|
115
|
+
// we need to check if the scope (instance) did not get destroyed yet
|
116
|
+
scope?.id && callback.apply(scope, args);
|
117
|
+
|
118
|
+
lastRanDate = Date.now()
|
119
|
+
}
|
120
|
+
}, delay - (Date.now() - lastRanDate))
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|