@enact/core 4.6.1 → 4.7.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/CHANGELOG.md +11 -1
- package/README.md +1 -1
- package/dispatcher/dispatcher.d.ts +21 -0
- package/handle/handle.d.ts +618 -0
- package/handle/handle.js +21 -21
- package/handle/tests/handle-specs.js +102 -1
- package/hoc/hoc.d.ts +43 -0
- package/hoc/tests/hoc-specs.js +3 -1
- package/index.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.js +10 -4
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +3 -1
- package/internal/Registry/Registry.d.ts +0 -0
- package/internal/Registry/tests/Registry-specs.js +4 -2
- package/internal/deprecate/deprecate.d.ts +0 -0
- package/internal/prop-types/prop-types.d.ts +0 -0
- package/internal/prop-types/tests/prop-types-specs.js +3 -1
- package/keymap/index.d.ts +37 -0
- package/kind/kind.d.ts +126 -0
- package/kind/kind.js +24 -15
- package/kind/tests/kind-specs.js +5 -3
- package/package.json +1 -1
- package/platform/platform.d.ts +45 -0
- package/platform/platform.js +18 -2
- package/platform/tests/platform-specs.js +10 -0
- package/snapshot/snapshot.d.ts +30 -0
- package/useChainRefs/tests/useChainRefs-specs.js +1 -1
- package/useChainRefs/useChainRefs.d.ts +0 -0
- package/useClass/tests/useClass-specs.js +3 -1
- package/useClass/useClass.d.ts +0 -0
- package/useHandlers/Handlers.js +3 -1
- package/useHandlers/tests/useHandlers-specs.js +3 -1
- package/useHandlers/useHandlers.d.ts +0 -0
- package/usePublicClassNames/usePublicClassNames.d.ts +0 -0
- package/util/Job.js +121 -1
- package/util/util.d.ts +162 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact core module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [4.7.0] - 2023-04-25
|
|
6
|
+
|
|
7
|
+
### Deprecated
|
|
8
|
+
|
|
9
|
+
- `windowsPhone` platform in `core/platform.platforms` to be removed in 5.0.0
|
|
10
|
+
|
|
11
|
+
## [4.6.2] - 2023-03-09
|
|
12
|
+
|
|
13
|
+
No significant changes.
|
|
14
|
+
|
|
5
15
|
## [4.6.1] - 2023-02-03
|
|
6
16
|
|
|
7
17
|
No significant changes.
|
|
@@ -10,7 +20,7 @@ No significant changes.
|
|
|
10
20
|
|
|
11
21
|
### Fixed
|
|
12
22
|
|
|
13
|
-
- `core/dispatcher`
|
|
23
|
+
- `core/dispatcher` to set the default target for event listeners properly when built with the snapshot option
|
|
14
24
|
|
|
15
25
|
## [4.0.12] - 2022-09-16
|
|
16
26
|
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npm test
|
|
|
24
24
|
|
|
25
25
|
Unless otherwise specified, all content, including all source code files and documentation files in this repository are:
|
|
26
26
|
|
|
27
|
-
Copyright (c) 2012-
|
|
27
|
+
Copyright (c) 2012-2023 LG Electronics
|
|
28
28
|
|
|
29
29
|
Unless otherwise specified or set forth in the NOTICE file, all content, including all source code files and documentation files in this repository are: Licensed under the Apache License, Version 2.0 (the "License"); you may not use this content except in compliance with the License. You may obtain a copy of the License at
|
|
30
30
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Type definitions for core/dispatcher
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Adds a new global event listener. Duplicate event handlers will be discarded.
|
|
8
|
+
*/
|
|
9
|
+
export function on(name: string, fn: Function, target: React.ReactNode): void;
|
|
10
|
+
/**
|
|
11
|
+
* Removes a global event listener.
|
|
12
|
+
*/
|
|
13
|
+
export function off(name: string, fn: Function, target: React.ReactNode): void;
|
|
14
|
+
/**
|
|
15
|
+
* Adds a new global event listener that removes itself after handling one event.
|
|
16
|
+
*/
|
|
17
|
+
export function once(
|
|
18
|
+
name: string,
|
|
19
|
+
fn: Function,
|
|
20
|
+
target?: React.ReactNode
|
|
21
|
+
): Function;
|
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
// Type definitions for core/handle
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The signature for event handlers
|
|
8
|
+
*/
|
|
9
|
+
export interface EventHandler {
|
|
10
|
+
(event: any): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The signature for event handling functions supported by `handle` and related functions
|
|
14
|
+
*/
|
|
15
|
+
export interface HandlerFunction {
|
|
16
|
+
(
|
|
17
|
+
event: any,
|
|
18
|
+
props: { [key: string]: any },
|
|
19
|
+
context: { [key: string]: any }
|
|
20
|
+
): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The signature for parameter `adapter`
|
|
24
|
+
*/
|
|
25
|
+
export interface EventAdapter {
|
|
26
|
+
(
|
|
27
|
+
event: any,
|
|
28
|
+
props: { [key: string]: any },
|
|
29
|
+
context: { [key: string]: any }
|
|
30
|
+
): any;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Allows generating event handlers by chaining input functions to filter or short-circuit the
|
|
34
|
+
handling flow. Any input function that returns a falsy value will stop the chain.
|
|
35
|
+
*
|
|
36
|
+
* The returned handler function has a `finally()` member that accepts a function and returns a new
|
|
37
|
+
handler function. The accepted function is called once the original handler completes regardless
|
|
38
|
+
of the returned value.
|
|
39
|
+
*/
|
|
40
|
+
export function handle(...handlers: HandlerFunction[]): EventHandler;
|
|
41
|
+
/**
|
|
42
|
+
* Calls the first handler whose condition passes. Each branch must be passed as an array with the
|
|
43
|
+
first element being the condition function and the second being the handler function. The same
|
|
44
|
+
arguments are passed to both the condition function and the handler function. The value returned
|
|
45
|
+
from the handler is returned.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
* ```
|
|
49
|
+
const handler = oneOf(
|
|
50
|
+
[forKey('enter'), handleEnter],
|
|
51
|
+
[forKey('left'), handleLeft],
|
|
52
|
+
[forKey('right'), handleRight]
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
*/
|
|
56
|
+
export function oneOf(
|
|
57
|
+
...handlers: [HandlerFunction, HandlerFunction][]
|
|
58
|
+
): HandlerFunction;
|
|
59
|
+
/**
|
|
60
|
+
* A function that always returns `true` . Optionally accepts a `handler` function which is called
|
|
61
|
+
before returning `true` .
|
|
62
|
+
*
|
|
63
|
+
* Example:
|
|
64
|
+
* ```
|
|
65
|
+
// Used to coerce an existing function into a handler
|
|
66
|
+
const coercedHandler = handle(
|
|
67
|
+
returnsTrue(doesSomething),
|
|
68
|
+
willAlwaysBeCalled
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Used to emulate if/else blocks with `oneOf`
|
|
72
|
+
const ifElseHandler = oneOf(
|
|
73
|
+
[forKey('enter'), handleEnter],
|
|
74
|
+
[returnsTrue, handleOtherwise]
|
|
75
|
+
);
|
|
76
|
+
```
|
|
77
|
+
*/
|
|
78
|
+
export function returnsTrue(handler?: Function): HandlerFunction;
|
|
79
|
+
/**
|
|
80
|
+
* Allows handling to continue if the value of `prop` on the event strictly equals `value`
|
|
81
|
+
*
|
|
82
|
+
* Example:
|
|
83
|
+
* ```
|
|
84
|
+
import {forEventProp, handle} from '@enact/core/handle';
|
|
85
|
+
|
|
86
|
+
const logWhenXEqualsZero = handle(
|
|
87
|
+
forEventProp('x', 0),
|
|
88
|
+
(ev) => console.log('ev.x was equal to zero', ev)
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
*/
|
|
92
|
+
export function forEventProp(prop: string, value: any, ev: object): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Allows handling to continue if the value of `prop` on the event strictly equals `value`
|
|
95
|
+
*
|
|
96
|
+
* Example:
|
|
97
|
+
* ```
|
|
98
|
+
import {forEventProp, handle} from '@enact/core/handle';
|
|
99
|
+
|
|
100
|
+
const logWhenXEqualsZero = handle(
|
|
101
|
+
forEventProp('x', 0),
|
|
102
|
+
(ev) => console.log('ev.x was equal to zero', ev)
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
*/
|
|
106
|
+
export function forEventProp(prop: string): (value: any, ev: object) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Allows handling to continue if the value of `prop` on the event strictly equals `value`
|
|
109
|
+
*
|
|
110
|
+
* Example:
|
|
111
|
+
* ```
|
|
112
|
+
import {forEventProp, handle} from '@enact/core/handle';
|
|
113
|
+
|
|
114
|
+
const logWhenXEqualsZero = handle(
|
|
115
|
+
forEventProp('x', 0),
|
|
116
|
+
(ev) => console.log('ev.x was equal to zero', ev)
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
*/
|
|
120
|
+
export function forEventProp(
|
|
121
|
+
prop: string
|
|
122
|
+
): (value: any) => (ev: object) => boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Allows handling to continue if the value of `prop` on the event strictly equals `value`
|
|
125
|
+
*
|
|
126
|
+
* Example:
|
|
127
|
+
* ```
|
|
128
|
+
import {forEventProp, handle} from '@enact/core/handle';
|
|
129
|
+
|
|
130
|
+
const logWhenXEqualsZero = handle(
|
|
131
|
+
forEventProp('x', 0),
|
|
132
|
+
(ev) => console.log('ev.x was equal to zero', ev)
|
|
133
|
+
);
|
|
134
|
+
```
|
|
135
|
+
*/
|
|
136
|
+
export function forEventProp(prop: string, value: any): (ev: object) => boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Forwards the event to a function at `name` on `props` . If the specified prop is `undefined` or
|
|
139
|
+
is not a function, it is ignored. The return value of the forwarded function is ignored and
|
|
140
|
+
`true` is always returned instead.
|
|
141
|
+
*
|
|
142
|
+
* Example:
|
|
143
|
+
* ```
|
|
144
|
+
import {forward, handle} from '@enact/core/handle';
|
|
145
|
+
|
|
146
|
+
const forwardAndLog = handle(
|
|
147
|
+
forward('onClick'),
|
|
148
|
+
(ev) => console.log('event forwarded to onClick from props', ev)
|
|
149
|
+
);
|
|
150
|
+
```
|
|
151
|
+
*/
|
|
152
|
+
export function forward(name: string, ev: object, props: object): true;
|
|
153
|
+
/**
|
|
154
|
+
* Forwards the event to a function at `name` on `props` . If the specified prop is `undefined` or
|
|
155
|
+
is not a function, it is ignored. The return value of the forwarded function is ignored and
|
|
156
|
+
`true` is always returned instead.
|
|
157
|
+
*
|
|
158
|
+
* Example:
|
|
159
|
+
* ```
|
|
160
|
+
import {forward, handle} from '@enact/core/handle';
|
|
161
|
+
|
|
162
|
+
const forwardAndLog = handle(
|
|
163
|
+
forward('onClick'),
|
|
164
|
+
(ev) => console.log('event forwarded to onClick from props', ev)
|
|
165
|
+
);
|
|
166
|
+
```
|
|
167
|
+
*/
|
|
168
|
+
export function forward(name: string): (ev: object, props: object) => true;
|
|
169
|
+
/**
|
|
170
|
+
* Forwards the event to a function at `name` on `props` . If the specified prop is `undefined` or
|
|
171
|
+
is not a function, it is ignored. The return value of the forwarded function is ignored and
|
|
172
|
+
`true` is always returned instead.
|
|
173
|
+
*
|
|
174
|
+
* Example:
|
|
175
|
+
* ```
|
|
176
|
+
import {forward, handle} from '@enact/core/handle';
|
|
177
|
+
|
|
178
|
+
const forwardAndLog = handle(
|
|
179
|
+
forward('onClick'),
|
|
180
|
+
(ev) => console.log('event forwarded to onClick from props', ev)
|
|
181
|
+
);
|
|
182
|
+
```
|
|
183
|
+
*/
|
|
184
|
+
export function forward(name: string): (ev: object) => (props: object) => true;
|
|
185
|
+
/**
|
|
186
|
+
* Forwards the event to a function at `name` on `props` . If the specified prop is `undefined` or
|
|
187
|
+
is not a function, it is ignored. The return value of the forwarded function is ignored and
|
|
188
|
+
`true` is always returned instead.
|
|
189
|
+
*
|
|
190
|
+
* Example:
|
|
191
|
+
* ```
|
|
192
|
+
import {forward, handle} from '@enact/core/handle';
|
|
193
|
+
|
|
194
|
+
const forwardAndLog = handle(
|
|
195
|
+
forward('onClick'),
|
|
196
|
+
(ev) => console.log('event forwarded to onClick from props', ev)
|
|
197
|
+
);
|
|
198
|
+
```
|
|
199
|
+
*/
|
|
200
|
+
export function forward(name: string, ev: object): (props: object) => true;
|
|
201
|
+
/**
|
|
202
|
+
* Calls `event.preventDefault()` and returns `true` .
|
|
203
|
+
*
|
|
204
|
+
* Example:
|
|
205
|
+
* ```
|
|
206
|
+
import {handle, preventDefault} from '@enact/core/handle';
|
|
207
|
+
|
|
208
|
+
const preventAndLog = handle(
|
|
209
|
+
preventDefault,
|
|
210
|
+
(ev) => console.log('preventDefault called', ev)
|
|
211
|
+
);
|
|
212
|
+
```
|
|
213
|
+
*/
|
|
214
|
+
export function preventDefault(ev: object): true;
|
|
215
|
+
/**
|
|
216
|
+
* Calls `event.stopPropagation()` and returns `true`
|
|
217
|
+
*
|
|
218
|
+
* Example:
|
|
219
|
+
* ```
|
|
220
|
+
import {handle, stop} from '@enact/core/handle';
|
|
221
|
+
|
|
222
|
+
const stopAndLog = handle(
|
|
223
|
+
stop,
|
|
224
|
+
(ev) => console.log('stopPropagation called', ev)
|
|
225
|
+
);
|
|
226
|
+
```
|
|
227
|
+
*/
|
|
228
|
+
export function stop(ev: object): true;
|
|
229
|
+
/**
|
|
230
|
+
* Calls `event.stopImmediatePropagation()` and returns `true`
|
|
231
|
+
*
|
|
232
|
+
* Example:
|
|
233
|
+
* ```
|
|
234
|
+
import {handle, stopImmediate} from '@enact/core/handle';
|
|
235
|
+
|
|
236
|
+
const stopImmediateAndLog = handle(
|
|
237
|
+
stopImmediate,
|
|
238
|
+
(ev) => console.log('stopImmediatePropagation called', ev)
|
|
239
|
+
);
|
|
240
|
+
```
|
|
241
|
+
*/
|
|
242
|
+
export function stopImmediate(ev: object): true;
|
|
243
|
+
/**
|
|
244
|
+
* Allows event handling to continue if `event.keyCode === value` .
|
|
245
|
+
*
|
|
246
|
+
* Example:
|
|
247
|
+
* ```
|
|
248
|
+
import {forKeyCode, handle} from '@enact/core/handle';
|
|
249
|
+
|
|
250
|
+
const logForEscapeKey = handle(
|
|
251
|
+
forKeyCode(27),
|
|
252
|
+
(ev) => console.log('Escape key pressed down', ev)
|
|
253
|
+
);
|
|
254
|
+
```
|
|
255
|
+
*/
|
|
256
|
+
export function forKeyCode(value: number, ev: object): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Allows event handling to continue if `event.keyCode === value` .
|
|
259
|
+
*
|
|
260
|
+
* Example:
|
|
261
|
+
* ```
|
|
262
|
+
import {forKeyCode, handle} from '@enact/core/handle';
|
|
263
|
+
|
|
264
|
+
const logForEscapeKey = handle(
|
|
265
|
+
forKeyCode(27),
|
|
266
|
+
(ev) => console.log('Escape key pressed down', ev)
|
|
267
|
+
);
|
|
268
|
+
```
|
|
269
|
+
*/
|
|
270
|
+
export function forKeyCode(value: number): (ev: object) => boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Allows handling to continue if the event's keyCode is mapped to `name` within
|
|
273
|
+
.
|
|
274
|
+
*
|
|
275
|
+
* Example:
|
|
276
|
+
* ```
|
|
277
|
+
import {forKey, handle} from '@enact/core/handle';
|
|
278
|
+
|
|
279
|
+
const logForEnterKey = handle(
|
|
280
|
+
forKey('enter'),
|
|
281
|
+
(ev) => console.log('Enter key pressed down', ev)
|
|
282
|
+
);
|
|
283
|
+
```
|
|
284
|
+
*/
|
|
285
|
+
export function forKey(name: string, ev: object): boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Allows handling to continue if the event's keyCode is mapped to `name` within
|
|
288
|
+
.
|
|
289
|
+
*
|
|
290
|
+
* Example:
|
|
291
|
+
* ```
|
|
292
|
+
import {forKey, handle} from '@enact/core/handle';
|
|
293
|
+
|
|
294
|
+
const logForEnterKey = handle(
|
|
295
|
+
forKey('enter'),
|
|
296
|
+
(ev) => console.log('Enter key pressed down', ev)
|
|
297
|
+
);
|
|
298
|
+
```
|
|
299
|
+
*/
|
|
300
|
+
export function forKey(name: string): (ev: object) => boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
303
|
+
*
|
|
304
|
+
* Example:
|
|
305
|
+
* ```
|
|
306
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
307
|
+
|
|
308
|
+
const logWhenChecked = handle(
|
|
309
|
+
forProp('checked', true),
|
|
310
|
+
(ev) => console.log('checked prop is true', ev)
|
|
311
|
+
);
|
|
312
|
+
```
|
|
313
|
+
*/
|
|
314
|
+
export function forProp(
|
|
315
|
+
prop: string,
|
|
316
|
+
value: any,
|
|
317
|
+
ev: object,
|
|
318
|
+
props: object
|
|
319
|
+
): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
322
|
+
*
|
|
323
|
+
* Example:
|
|
324
|
+
* ```
|
|
325
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
326
|
+
|
|
327
|
+
const logWhenChecked = handle(
|
|
328
|
+
forProp('checked', true),
|
|
329
|
+
(ev) => console.log('checked prop is true', ev)
|
|
330
|
+
);
|
|
331
|
+
```
|
|
332
|
+
*/
|
|
333
|
+
export function forProp(
|
|
334
|
+
prop: string
|
|
335
|
+
): (value: any, ev: object, props: object) => boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
338
|
+
*
|
|
339
|
+
* Example:
|
|
340
|
+
* ```
|
|
341
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
342
|
+
|
|
343
|
+
const logWhenChecked = handle(
|
|
344
|
+
forProp('checked', true),
|
|
345
|
+
(ev) => console.log('checked prop is true', ev)
|
|
346
|
+
);
|
|
347
|
+
```
|
|
348
|
+
*/
|
|
349
|
+
export function forProp(
|
|
350
|
+
prop: string
|
|
351
|
+
): (value: any) => (ev: object, props: object) => boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
354
|
+
*
|
|
355
|
+
* Example:
|
|
356
|
+
* ```
|
|
357
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
358
|
+
|
|
359
|
+
const logWhenChecked = handle(
|
|
360
|
+
forProp('checked', true),
|
|
361
|
+
(ev) => console.log('checked prop is true', ev)
|
|
362
|
+
);
|
|
363
|
+
```
|
|
364
|
+
*/
|
|
365
|
+
export function forProp(
|
|
366
|
+
prop: string
|
|
367
|
+
): (value: any) => (ev: object) => (props: object) => boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
370
|
+
*
|
|
371
|
+
* Example:
|
|
372
|
+
* ```
|
|
373
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
374
|
+
|
|
375
|
+
const logWhenChecked = handle(
|
|
376
|
+
forProp('checked', true),
|
|
377
|
+
(ev) => console.log('checked prop is true', ev)
|
|
378
|
+
);
|
|
379
|
+
```
|
|
380
|
+
*/
|
|
381
|
+
export function forProp(
|
|
382
|
+
prop: string
|
|
383
|
+
): (value: any, ev: object) => (props: object) => boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
386
|
+
*
|
|
387
|
+
* Example:
|
|
388
|
+
* ```
|
|
389
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
390
|
+
|
|
391
|
+
const logWhenChecked = handle(
|
|
392
|
+
forProp('checked', true),
|
|
393
|
+
(ev) => console.log('checked prop is true', ev)
|
|
394
|
+
);
|
|
395
|
+
```
|
|
396
|
+
*/
|
|
397
|
+
export function forProp(
|
|
398
|
+
prop: string,
|
|
399
|
+
value: any
|
|
400
|
+
): (ev: object, props: object) => boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
403
|
+
*
|
|
404
|
+
* Example:
|
|
405
|
+
* ```
|
|
406
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
407
|
+
|
|
408
|
+
const logWhenChecked = handle(
|
|
409
|
+
forProp('checked', true),
|
|
410
|
+
(ev) => console.log('checked prop is true', ev)
|
|
411
|
+
);
|
|
412
|
+
```
|
|
413
|
+
*/
|
|
414
|
+
export function forProp(
|
|
415
|
+
prop: string,
|
|
416
|
+
value: any
|
|
417
|
+
): (ev: object) => (props: object) => boolean;
|
|
418
|
+
/**
|
|
419
|
+
* Allows handling to continue if the value of `prop` on the props strictly equals `value` .
|
|
420
|
+
*
|
|
421
|
+
* Example:
|
|
422
|
+
* ```
|
|
423
|
+
import {forProp, handle} from '@enact/core/handle';
|
|
424
|
+
|
|
425
|
+
const logWhenChecked = handle(
|
|
426
|
+
forProp('checked', true),
|
|
427
|
+
(ev) => console.log('checked prop is true', ev)
|
|
428
|
+
);
|
|
429
|
+
```
|
|
430
|
+
*/
|
|
431
|
+
export function forProp(
|
|
432
|
+
prop: string,
|
|
433
|
+
value: any,
|
|
434
|
+
ev: object
|
|
435
|
+
): (props: object) => boolean;
|
|
436
|
+
/**
|
|
437
|
+
* Logs the event, props, and context optionally preceded by a custom message. Will only log in
|
|
438
|
+
development mode.
|
|
439
|
+
*
|
|
440
|
+
* Example:
|
|
441
|
+
* ```
|
|
442
|
+
import {forProp, handle, log} from '@enact/core/handle';
|
|
443
|
+
|
|
444
|
+
const logWhenChecked = handle(
|
|
445
|
+
forProp('checked', true),
|
|
446
|
+
log('checked props is true')
|
|
447
|
+
);
|
|
448
|
+
```
|
|
449
|
+
*/
|
|
450
|
+
export function log(message: string, ev: object, args?: any[]): true;
|
|
451
|
+
/**
|
|
452
|
+
* Logs the event, props, and context optionally preceded by a custom message. Will only log in
|
|
453
|
+
development mode.
|
|
454
|
+
*
|
|
455
|
+
* Example:
|
|
456
|
+
* ```
|
|
457
|
+
import {forProp, handle, log} from '@enact/core/handle';
|
|
458
|
+
|
|
459
|
+
const logWhenChecked = handle(
|
|
460
|
+
forProp('checked', true),
|
|
461
|
+
log('checked props is true')
|
|
462
|
+
);
|
|
463
|
+
```
|
|
464
|
+
*/
|
|
465
|
+
export function log(message: string): (ev: object, args?: any[]) => true;
|
|
466
|
+
/**
|
|
467
|
+
* Logs the event, props, and context optionally preceded by a custom message. Will only log in
|
|
468
|
+
development mode.
|
|
469
|
+
*
|
|
470
|
+
* Example:
|
|
471
|
+
* ```
|
|
472
|
+
import {forProp, handle, log} from '@enact/core/handle';
|
|
473
|
+
|
|
474
|
+
const logWhenChecked = handle(
|
|
475
|
+
forProp('checked', true),
|
|
476
|
+
log('checked props is true')
|
|
477
|
+
);
|
|
478
|
+
```
|
|
479
|
+
*/
|
|
480
|
+
export function log(message: string): (ev: object) => (args?: any[]) => true;
|
|
481
|
+
/**
|
|
482
|
+
* Logs the event, props, and context optionally preceded by a custom message. Will only log in
|
|
483
|
+
development mode.
|
|
484
|
+
*
|
|
485
|
+
* Example:
|
|
486
|
+
* ```
|
|
487
|
+
import {forProp, handle, log} from '@enact/core/handle';
|
|
488
|
+
|
|
489
|
+
const logWhenChecked = handle(
|
|
490
|
+
forProp('checked', true),
|
|
491
|
+
log('checked props is true')
|
|
492
|
+
);
|
|
493
|
+
```
|
|
494
|
+
*/
|
|
495
|
+
export function log(message: string, ev: object): (args?: any[]) => true;
|
|
496
|
+
/**
|
|
497
|
+
* Invokes a method by name on the component to which is bound.
|
|
498
|
+
*
|
|
499
|
+
* If the methods exists on the object, it is called with the event, props, and context and its
|
|
500
|
+
return value is returned.
|
|
501
|
+
*
|
|
502
|
+
* If the method does not exist or handle isn't bound to an instance, it returns `false` .
|
|
503
|
+
*
|
|
504
|
+
* Example:
|
|
505
|
+
* ```
|
|
506
|
+
import {call, handle, forProp} from '@enact/core/handle';
|
|
507
|
+
|
|
508
|
+
const incrementIfEnabled = handle(
|
|
509
|
+
forProp('disabled', false),
|
|
510
|
+
call('increment')
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
class Counter extends React.Component {
|
|
514
|
+
constructor () {
|
|
515
|
+
super();
|
|
516
|
+
|
|
517
|
+
this.handleIncrement = incrementIfEnabled.bind(this);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
render () {
|
|
521
|
+
// ...
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
*/
|
|
526
|
+
export function call(method: string): HandlerFunction;
|
|
527
|
+
/**
|
|
528
|
+
* Adapts an event with `adapter` before calling `handler` .
|
|
529
|
+
*
|
|
530
|
+
* The `adapter` function receives the same arguments as any handler. The value returned from
|
|
531
|
+
`adapter` is passed as the first argument to `handler` with the remaining arguments kept the
|
|
532
|
+
same. This is often useful to generate a custom event payload before forwarding on to a callback.
|
|
533
|
+
*
|
|
534
|
+
* Example:
|
|
535
|
+
* ```
|
|
536
|
+
import {adaptEvent, forward} from '@enact/core/handle';
|
|
537
|
+
|
|
538
|
+
// calls the onChange callback with an event payload containing a type and value member
|
|
539
|
+
const incrementAndChange = adaptEvent(
|
|
540
|
+
(ev, props) => ({
|
|
541
|
+
type: 'onChange',
|
|
542
|
+
value: props.value + 1
|
|
543
|
+
}),
|
|
544
|
+
forward('onChange')
|
|
545
|
+
)
|
|
546
|
+
```
|
|
547
|
+
*/
|
|
548
|
+
export function adaptEvent(
|
|
549
|
+
adapter: EventAdapter,
|
|
550
|
+
handler: HandlerFunction
|
|
551
|
+
): HandlerFunction;
|
|
552
|
+
/**
|
|
553
|
+
* Adapts an event with `adapter` before calling `handler` .
|
|
554
|
+
*
|
|
555
|
+
* The `adapter` function receives the same arguments as any handler. The value returned from
|
|
556
|
+
`adapter` is passed as the first argument to `handler` with the remaining arguments kept the
|
|
557
|
+
same. This is often useful to generate a custom event payload before forwarding on to a callback.
|
|
558
|
+
*
|
|
559
|
+
* Example:
|
|
560
|
+
* ```
|
|
561
|
+
import {adaptEvent, forward} from '@enact/core/handle';
|
|
562
|
+
|
|
563
|
+
// calls the onChange callback with an event payload containing a type and value member
|
|
564
|
+
const incrementAndChange = adaptEvent(
|
|
565
|
+
(ev, props) => ({
|
|
566
|
+
type: 'onChange',
|
|
567
|
+
value: props.value + 1
|
|
568
|
+
}),
|
|
569
|
+
forward('onChange')
|
|
570
|
+
)
|
|
571
|
+
```
|
|
572
|
+
*/
|
|
573
|
+
export function adaptEvent(
|
|
574
|
+
adapter: EventAdapter
|
|
575
|
+
): (handler: HandlerFunction) => HandlerFunction;
|
|
576
|
+
/**
|
|
577
|
+
* Creates a handler that will forward the event to a function at `name` on `props` .
|
|
578
|
+
*
|
|
579
|
+
* If `adapter` is not specified, a new event payload will be generated with a `type` member with
|
|
580
|
+
the `name` of the custom event. If `adapter` is specified, the `type` member is added to the
|
|
581
|
+
value returned by `adapter` .
|
|
582
|
+
*
|
|
583
|
+
* The `adapter` function receives the same arguments as any handler. The value returned from
|
|
584
|
+
`adapter` is passed as the first argument to `handler` with the remaining arguments kept the
|
|
585
|
+
same. This is often useful to generate a custom event payload before forwarding on to a callback.
|
|
586
|
+
*
|
|
587
|
+
* Example:
|
|
588
|
+
* ```
|
|
589
|
+
import {forwardCustom} from '@enact/core/handle';
|
|
590
|
+
|
|
591
|
+
// calls the onChange callback with the event: {type: 'onChange'}
|
|
592
|
+
const forwardChange = forwardCustom('onChange');
|
|
593
|
+
|
|
594
|
+
// calls the onChange callback with the event: {type: 'onChange', index}
|
|
595
|
+
const forwardChangeWithIndex = forwardCustom('onChange', (ev, {index}) => ({index}));
|
|
596
|
+
```
|
|
597
|
+
*/
|
|
598
|
+
export function forwardCustom(
|
|
599
|
+
name: string,
|
|
600
|
+
adapter?: EventAdapter
|
|
601
|
+
): HandlerFunction;
|
|
602
|
+
/**
|
|
603
|
+
* Accepts a handler and returns the logical complement of the value returned from the handler.
|
|
604
|
+
*
|
|
605
|
+
* Example:
|
|
606
|
+
* ```
|
|
607
|
+
import {forProp, forward, not, handle} from '@enact/core/handle';
|
|
608
|
+
|
|
609
|
+
// calls the onChange callback when disabled is not true
|
|
610
|
+
const handleChange = handle(
|
|
611
|
+
not(forProp('disabled', true)),
|
|
612
|
+
forward('onChange')
|
|
613
|
+
)
|
|
614
|
+
```
|
|
615
|
+
*/
|
|
616
|
+
export function not(handler: HandlerFunction): HandlerFunction;
|
|
617
|
+
|
|
618
|
+
export default handle;
|