@enact/core 4.5.2 → 4.6.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.
- package/CHANGELOG.md +30 -0
- package/dispatcher/dispatcher.js +15 -27
- package/dispatcher/listeners.js +0 -8
- package/dispatcher/tests/dispatcher-specs.js +0 -3
- package/handle/handle.js +40 -98
- package/handle/tests/handle-specs.js +21 -42
- package/hoc/hoc.js +2 -13
- package/hoc/tests/hoc-specs.js +0 -23
- package/internal/ApiDecorator/ApiDecorator.js +4 -34
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +69 -40
- package/internal/Registry/Registry.js +0 -7
- package/internal/Registry/tests/Registry-specs.js +26 -78
- package/internal/deprecate/deprecate.js +9 -22
- package/internal/deprecate/tests/deprecate-specs.js +38 -0
- package/internal/prop-types/prop-types.js +3 -20
- package/internal/prop-types/tests/prop-types-specs.js +265 -0
- package/keymap/index.js +2 -3
- package/keymap/keymap.js +10 -18
- package/keymap/tests/keymap-specs.js +0 -3
- package/kind/computed.js +2 -9
- package/kind/kind.js +14 -53
- package/kind/styles.js +6 -19
- package/kind/tests/computed-specs.js +4 -6
- package/kind/tests/kind-specs.js +9 -44
- package/kind/tests/styles-specs.js +12 -7
- package/kind/util.js +0 -2
- package/package.json +8 -2
- package/platform/platform.js +51 -57
- package/platform/tests/platform-specs.js +31 -3
- package/snapshot/snapshot.js +4 -9
- package/snapshot/tests/snapshot-specs.js +56 -0
- package/useChainRefs/tests/useChainRefs-specs.js +0 -14
- package/useChainRefs/useChainRefs.js +3 -11
- package/useClass/tests/useClass-specs.js +6 -21
- package/useClass/useClass.js +0 -8
- package/useHandlers/Handlers.js +0 -11
- package/useHandlers/tests/useHandlers-specs.js +11 -23
- package/useHandlers/useHandlers.js +0 -5
- package/usePublicClassNames/tests/usePublicClassNames-specs.js +21 -28
- package/usePublicClassNames/usePublicClassNames.js +4 -10
- package/util/Job.js +1 -43
- package/util/tests/Job-specs.js +48 -14
- package/util/tests/util-specs.js +125 -10
- package/util/util.js +15 -54
- package/dispatcher/dispatcher.d.ts +0 -21
- package/handle/handle.d.ts +0 -618
- package/hoc/hoc.d.ts +0 -44
- package/index.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.d.ts +0 -0
- package/internal/Registry/Registry.d.ts +0 -0
- package/internal/deprecate/deprecate.d.ts +0 -0
- package/internal/prop-types/prop-types.d.ts +0 -0
- package/keymap/index.d.ts +0 -37
- package/kind/kind.d.ts +0 -90
- package/platform/platform.d.ts +0 -45
- package/snapshot/snapshot.d.ts +0 -32
- package/useChainRefs/useChainRefs.d.ts +0 -0
- package/useClass/useClass.d.ts +0 -0
- package/useHandlers/useHandlers.d.ts +0 -0
- package/usePublicClassNames/usePublicClassNames.d.ts +0 -0
- package/util/util.d.ts +0 -162
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _handle = require("../handle");
|
|
4
|
-
|
|
5
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
|
|
9
6
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
-
|
|
11
7
|
describe('handle', function () {
|
|
12
8
|
var makeEvent = function makeEvent(payload) {
|
|
13
9
|
return _objectSpread({
|
|
@@ -15,15 +11,12 @@ describe('handle', function () {
|
|
|
15
11
|
stopPropagation: jest.fn()
|
|
16
12
|
}, payload);
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
var returnsTrue = function returnsTrue() {
|
|
20
15
|
return true;
|
|
21
16
|
};
|
|
22
|
-
|
|
23
17
|
var returnsFalse = function returnsFalse() {
|
|
24
18
|
return false;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
test('should call only handler', function () {
|
|
28
21
|
var handler = jest.fn(returnsTrue);
|
|
29
22
|
var callback = (0, _handle.handle)(handler);
|
|
@@ -97,29 +90,35 @@ describe('handle', function () {
|
|
|
97
90
|
var handler = jest.fn();
|
|
98
91
|
var prop = 'index';
|
|
99
92
|
var value = 0;
|
|
100
|
-
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler);
|
|
93
|
+
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler);
|
|
101
94
|
|
|
95
|
+
// undefined shouldn't pass
|
|
102
96
|
callback(makeEvent());
|
|
103
|
-
expect(handler).not.toHaveBeenCalled();
|
|
97
|
+
expect(handler).not.toHaveBeenCalled();
|
|
104
98
|
|
|
99
|
+
// == check shouldn't pass
|
|
105
100
|
callback(makeEvent(_defineProperty({}, prop, false)));
|
|
106
|
-
expect(handler).not.toHaveBeenCalled();
|
|
101
|
+
expect(handler).not.toHaveBeenCalled();
|
|
107
102
|
|
|
103
|
+
// === should pass
|
|
108
104
|
callback(makeEvent(_defineProperty({}, prop, value)));
|
|
109
105
|
expect(handler).toHaveBeenCalled();
|
|
110
106
|
});
|
|
111
107
|
test('should only call handler for specified prop', function () {
|
|
112
108
|
var handler = jest.fn();
|
|
113
|
-
var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler);
|
|
109
|
+
var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler);
|
|
114
110
|
|
|
111
|
+
// undefined shouldn't pass
|
|
115
112
|
callback({}, {});
|
|
116
|
-
expect(handler).not.toHaveBeenCalled();
|
|
113
|
+
expect(handler).not.toHaveBeenCalled();
|
|
117
114
|
|
|
115
|
+
// == check shouldn't pass
|
|
118
116
|
callback({}, {
|
|
119
117
|
checked: 1
|
|
120
118
|
});
|
|
121
|
-
expect(handler).not.toHaveBeenCalled();
|
|
119
|
+
expect(handler).not.toHaveBeenCalled();
|
|
122
120
|
|
|
121
|
+
// === should pass
|
|
123
122
|
callback({}, {
|
|
124
123
|
checked: true
|
|
125
124
|
});
|
|
@@ -130,11 +129,8 @@ describe('handle', function () {
|
|
|
130
129
|
var prop = 'index';
|
|
131
130
|
var propValue = 0;
|
|
132
131
|
var spy = jest.fn();
|
|
133
|
-
|
|
134
132
|
var props = _defineProperty({}, event, spy);
|
|
135
|
-
|
|
136
133
|
var payload = _defineProperty({}, prop, propValue);
|
|
137
|
-
|
|
138
134
|
(0, _handle.handle)((0, _handle.forward)(event))(payload, props);
|
|
139
135
|
var expected = true;
|
|
140
136
|
var actual = spy.mock.calls[0][0][prop] === propValue;
|
|
@@ -150,8 +146,9 @@ describe('handle', function () {
|
|
|
150
146
|
test('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () {
|
|
151
147
|
var event = 'onMyClick';
|
|
152
148
|
var handler = jest.fn();
|
|
153
|
-
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler);
|
|
149
|
+
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler);
|
|
154
150
|
|
|
151
|
+
// should stop chain when `preventDefault()` has been called
|
|
155
152
|
callback({}, {
|
|
156
153
|
'onMyClick': function onMyClick(ev) {
|
|
157
154
|
return ev.preventDefault();
|
|
@@ -167,9 +164,7 @@ describe('handle', function () {
|
|
|
167
164
|
}
|
|
168
165
|
};
|
|
169
166
|
var handler = jest.fn();
|
|
170
|
-
|
|
171
167
|
var h = _handle.handle.bind(componentInstance);
|
|
172
|
-
|
|
173
168
|
var callback = h(handler);
|
|
174
169
|
callback();
|
|
175
170
|
var expected = 1;
|
|
@@ -184,9 +179,7 @@ describe('handle', function () {
|
|
|
184
179
|
props: {}
|
|
185
180
|
};
|
|
186
181
|
var handler = jest.fn();
|
|
187
|
-
|
|
188
182
|
var h = _handle.handle.bind(componentInstance);
|
|
189
|
-
|
|
190
183
|
var callback = h(handler);
|
|
191
184
|
callback();
|
|
192
185
|
var expected = 1;
|
|
@@ -213,12 +206,11 @@ describe('handle', function () {
|
|
|
213
206
|
var callback = (0, _handle.handle)(function () {
|
|
214
207
|
throw new Error('Something has gone awry ...');
|
|
215
208
|
})["finally"](finallyCallback);
|
|
216
|
-
|
|
217
209
|
try {
|
|
218
210
|
callback(makeEvent());
|
|
219
|
-
} catch (e) {
|
|
211
|
+
} catch (e) {
|
|
212
|
+
// we don't want the error to interrupt the test
|
|
220
213
|
}
|
|
221
|
-
|
|
222
214
|
var expected = 1;
|
|
223
215
|
expect(finallyCallback).toHaveBeenCalledTimes(expected);
|
|
224
216
|
});
|
|
@@ -292,9 +284,7 @@ describe('handle', function () {
|
|
|
292
284
|
}
|
|
293
285
|
};
|
|
294
286
|
var handler = jest.fn();
|
|
295
|
-
|
|
296
287
|
var h = _handle.handle.bind(componentInstance);
|
|
297
|
-
|
|
298
288
|
var callback = (0, _handle.oneOf)([returnsTrue, h(handler)]);
|
|
299
289
|
callback();
|
|
300
290
|
var expected = 1;
|
|
@@ -309,9 +299,7 @@ describe('handle', function () {
|
|
|
309
299
|
context: {}
|
|
310
300
|
};
|
|
311
301
|
var handler = jest.fn();
|
|
312
|
-
|
|
313
302
|
var o = _handle.oneOf.bind(componentInstance);
|
|
314
|
-
|
|
315
303
|
var callback = o([returnsTrue, handler]);
|
|
316
304
|
callback();
|
|
317
305
|
var expected = 1;
|
|
@@ -326,9 +314,7 @@ describe('handle', function () {
|
|
|
326
314
|
}
|
|
327
315
|
};
|
|
328
316
|
var handler = jest.fn();
|
|
329
|
-
|
|
330
317
|
var o = _handle.oneOf.bind(componentInstance);
|
|
331
|
-
|
|
332
318
|
var callback = o([returnsTrue, handler]);
|
|
333
319
|
callback();
|
|
334
320
|
var expected = 1;
|
|
@@ -346,14 +332,12 @@ describe('handle', function () {
|
|
|
346
332
|
describe('#adaptEvent', function () {
|
|
347
333
|
test('should pass the adapted event payload to the provided handler', function () {
|
|
348
334
|
var handler = jest.fn();
|
|
349
|
-
|
|
350
335
|
var onlyValue = function onlyValue(_ref) {
|
|
351
336
|
var value = _ref.value;
|
|
352
337
|
return {
|
|
353
338
|
value: value
|
|
354
339
|
};
|
|
355
340
|
};
|
|
356
|
-
|
|
357
341
|
var ev = {
|
|
358
342
|
value: 1,
|
|
359
343
|
message: 'ok'
|
|
@@ -367,11 +351,9 @@ describe('handle', function () {
|
|
|
367
351
|
});
|
|
368
352
|
test('should pass additional arguments to the provided handler', function () {
|
|
369
353
|
var handler = jest.fn();
|
|
370
|
-
|
|
371
354
|
var returnOne = function returnOne() {
|
|
372
355
|
return 1;
|
|
373
356
|
};
|
|
374
|
-
|
|
375
357
|
(0, _handle.adaptEvent)(returnOne, handler)(0, 2, 3);
|
|
376
358
|
var expected = [1, 2, 3];
|
|
377
359
|
var actual = handler.mock.calls[0];
|
|
@@ -394,11 +376,9 @@ describe('handle', function () {
|
|
|
394
376
|
var obj = {
|
|
395
377
|
handler: jest.fn()
|
|
396
378
|
};
|
|
397
|
-
|
|
398
379
|
var returnOne = function returnOne() {
|
|
399
380
|
return 1;
|
|
400
381
|
};
|
|
401
|
-
|
|
402
382
|
var fn = (0, _handle.adaptEvent)(returnOne, (0, _handle.call)('handler')).bind(obj);
|
|
403
383
|
fn(0, 2, 3);
|
|
404
384
|
var expected = [1, 2, 3];
|
|
@@ -420,13 +400,11 @@ describe('handle', function () {
|
|
|
420
400
|
});
|
|
421
401
|
test('should add `type` to object returned by adapter', function () {
|
|
422
402
|
var handler = jest.fn();
|
|
423
|
-
|
|
424
403
|
var adapter = function adapter() {
|
|
425
404
|
return {
|
|
426
405
|
index: 0
|
|
427
406
|
};
|
|
428
407
|
};
|
|
429
|
-
|
|
430
408
|
(0, _handle.forwardCustom)('onCustomEvent', adapter)(null, {
|
|
431
409
|
onCustomEvent: handler
|
|
432
410
|
});
|
|
@@ -439,11 +417,9 @@ describe('handle', function () {
|
|
|
439
417
|
});
|
|
440
418
|
test('should create an event payload if the adapter returns nothing', function () {
|
|
441
419
|
var handler = jest.fn();
|
|
442
|
-
|
|
443
420
|
var adapter = function adapter() {
|
|
444
421
|
return null;
|
|
445
422
|
};
|
|
446
|
-
|
|
447
423
|
(0, _handle.forwardCustom)('onCustomEvent', adapter)(null, {
|
|
448
424
|
onCustomEvent: handler
|
|
449
425
|
});
|
|
@@ -455,10 +431,13 @@ describe('handle', function () {
|
|
|
455
431
|
});
|
|
456
432
|
test('should pass event, props, and context args to adapter', function () {
|
|
457
433
|
var adapter = jest.fn();
|
|
458
|
-
var args = [1,
|
|
459
|
-
|
|
434
|
+
var args = [1,
|
|
435
|
+
// ev,
|
|
436
|
+
2,
|
|
437
|
+
// props,
|
|
460
438
|
3 // context
|
|
461
439
|
];
|
|
440
|
+
|
|
462
441
|
(0, _handle.forwardCustom)('onCustomEvent', adapter).apply(void 0, args);
|
|
463
442
|
var expected = args;
|
|
464
443
|
var actual = adapter.mock.calls[0];
|
package/hoc/hoc.js
CHANGED
|
@@ -4,27 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hoc = exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("../util");
|
|
9
|
-
|
|
10
8
|
var _mergeDeepWithKey = _interopRequireDefault(require("ramda/src/mergeDeepWithKey"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Provides the {@link core/hoc.hoc} method to create higher-order components (HOCs).
|
|
16
12
|
*
|
|
17
13
|
* @module core/hoc
|
|
18
14
|
* @exports hoc
|
|
19
15
|
*/
|
|
16
|
+
|
|
20
17
|
var mergeFn = function mergeFn(key, defaultValue, userValue) {
|
|
21
18
|
// eslint-disable-next-line no-undefined
|
|
22
19
|
if (userValue === undefined) {
|
|
23
20
|
return defaultValue;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
return userValue;
|
|
27
23
|
};
|
|
24
|
+
|
|
28
25
|
/**
|
|
29
26
|
* Constructs a higher-order component (HOC) using an optional set of default configuration parameters and
|
|
30
27
|
* a factory method that accepts instance configuration parameters and a component to wrap. The
|
|
@@ -68,24 +65,19 @@ var mergeFn = function mergeFn(key, defaultValue, userValue) {
|
|
|
68
65
|
* @memberof core/hoc
|
|
69
66
|
* @public
|
|
70
67
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
68
|
var hoc = function hoc(defaultConfig, hawk) {
|
|
74
69
|
// normalize arguments to allow defaultConfig to be omitted
|
|
75
70
|
var factory = hawk;
|
|
76
71
|
var defaults = defaultConfig;
|
|
77
|
-
|
|
78
72
|
if (!factory && typeof defaultConfig === 'function') {
|
|
79
73
|
factory = defaultConfig;
|
|
80
74
|
defaults = null;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
var Component = function Component(config, maybeWrapped) {
|
|
84
77
|
if ((0, _util.isRenderable)(config)) {
|
|
85
78
|
return factory(defaults, config);
|
|
86
79
|
} else {
|
|
87
80
|
var cfg = (0, _mergeDeepWithKey["default"])(mergeFn, defaults, config);
|
|
88
|
-
|
|
89
81
|
if ((0, _util.isRenderable)(maybeWrapped)) {
|
|
90
82
|
return factory(cfg, maybeWrapped);
|
|
91
83
|
} else {
|
|
@@ -95,15 +87,12 @@ var hoc = function hoc(defaultConfig, hawk) {
|
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
89
|
};
|
|
98
|
-
|
|
99
90
|
if (defaults) {
|
|
100
91
|
Component.displayName = 'HOC';
|
|
101
92
|
Component.defaultConfig = defaults;
|
|
102
93
|
}
|
|
103
|
-
|
|
104
94
|
return Component;
|
|
105
95
|
};
|
|
106
|
-
|
|
107
96
|
exports.hoc = hoc;
|
|
108
97
|
var _default = hoc;
|
|
109
98
|
exports["default"] = _default;
|
package/hoc/tests/hoc-specs.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _hoc = _interopRequireDefault(require("../hoc"));
|
|
8
|
-
|
|
9
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
|
|
11
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
-
|
|
13
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
|
|
15
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
-
|
|
17
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
-
|
|
19
11
|
describe('hoc', function () {
|
|
20
12
|
var data;
|
|
21
13
|
var testID = 'test-HoC';
|
|
@@ -47,9 +39,7 @@ describe('hoc', function () {
|
|
|
47
39
|
});
|
|
48
40
|
var Component = ImplicitNullHoC('span');
|
|
49
41
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
50
|
-
|
|
51
42
|
var component = _react.screen.getByTestId(testID);
|
|
52
|
-
|
|
53
43
|
var expected = 'SPAN';
|
|
54
44
|
var actual = component.nodeName;
|
|
55
45
|
expect(actual).toBe(expected);
|
|
@@ -57,9 +47,7 @@ describe('hoc', function () {
|
|
|
57
47
|
test('should support DOM node name as first argument to HoC', function () {
|
|
58
48
|
var Component = HoC('span');
|
|
59
49
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
60
|
-
|
|
61
50
|
var component = _react.screen.getByTestId(testID);
|
|
62
|
-
|
|
63
51
|
var expected = 'SPAN';
|
|
64
52
|
var actual = component.nodeName;
|
|
65
53
|
expect(actual).toBe(expected);
|
|
@@ -70,12 +58,9 @@ describe('hoc', function () {
|
|
|
70
58
|
"data-testid": testID
|
|
71
59
|
});
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
var Component = HoC(Thing);
|
|
75
62
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
76
|
-
|
|
77
63
|
var component = _react.screen.getByTestId(testID);
|
|
78
|
-
|
|
79
64
|
var expected = 'DIV';
|
|
80
65
|
var actual = component.nodeName;
|
|
81
66
|
var actualWrapped = data;
|
|
@@ -85,9 +70,7 @@ describe('hoc', function () {
|
|
|
85
70
|
test('should use default config when instance config is omitted', function () {
|
|
86
71
|
var Component = HoC('span');
|
|
87
72
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
88
|
-
|
|
89
73
|
var component = _react.screen.getByTestId(testID);
|
|
90
|
-
|
|
91
74
|
var expectedAttribute = 'color';
|
|
92
75
|
var expectedValue = defaultConfig.color;
|
|
93
76
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -98,9 +81,7 @@ describe('hoc', function () {
|
|
|
98
81
|
};
|
|
99
82
|
var Component = HoC(instanceConfig, 'div');
|
|
100
83
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
101
|
-
|
|
102
84
|
var component = _react.screen.getByTestId(testID);
|
|
103
|
-
|
|
104
85
|
var expectedAttribute = 'color';
|
|
105
86
|
var expectedValue = instanceConfig.color;
|
|
106
87
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -108,9 +89,7 @@ describe('hoc', function () {
|
|
|
108
89
|
test('should allow construction without default or instance configs', function () {
|
|
109
90
|
var Component = NullHoC('input');
|
|
110
91
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
111
|
-
|
|
112
92
|
var component = _react.screen.getByTestId(testID);
|
|
113
|
-
|
|
114
93
|
var expected = 'INPUT';
|
|
115
94
|
var actual = component.nodeName;
|
|
116
95
|
expect(actual).toBe(expected);
|
|
@@ -122,9 +101,7 @@ describe('hoc', function () {
|
|
|
122
101
|
};
|
|
123
102
|
var Component = NullHoC(instanceConfig, 'div');
|
|
124
103
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
125
|
-
|
|
126
104
|
var component = _react.screen.getByTestId(testID);
|
|
127
|
-
|
|
128
105
|
var expectedAttribute = 'color';
|
|
129
106
|
var expectedValue = instanceConfig.color;
|
|
130
107
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -4,43 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.ApiDecorator = void 0;
|
|
7
|
-
|
|
8
7
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
9
|
-
|
|
10
8
|
var _react = require("react");
|
|
11
|
-
|
|
12
9
|
var _hoc = _interopRequireDefault(require("../../hoc"));
|
|
13
|
-
|
|
14
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
|
|
18
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
14
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
24
15
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
-
|
|
26
16
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
27
|
-
|
|
28
17
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
|
-
|
|
30
18
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
31
|
-
|
|
32
19
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
-
|
|
34
20
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
35
|
-
|
|
36
21
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
37
|
-
|
|
38
22
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
|
-
|
|
40
23
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
|
-
|
|
42
24
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
|
-
|
|
44
25
|
// Gets a property from `provider`
|
|
45
26
|
var get = function get(provider, name) {
|
|
46
27
|
return function () {
|
|
@@ -48,9 +29,9 @@ var get = function get(provider, name) {
|
|
|
48
29
|
return provider[name];
|
|
49
30
|
}
|
|
50
31
|
};
|
|
51
|
-
};
|
|
52
|
-
|
|
32
|
+
};
|
|
53
33
|
|
|
34
|
+
// Sets a property on `provider`
|
|
54
35
|
var set = function set(provider, name) {
|
|
55
36
|
return function (value) {
|
|
56
37
|
if (provider && typeof provider[name] !== 'function') {
|
|
@@ -58,14 +39,13 @@ var set = function set(provider, name) {
|
|
|
58
39
|
}
|
|
59
40
|
};
|
|
60
41
|
};
|
|
42
|
+
|
|
61
43
|
/**
|
|
62
44
|
* Default config for {@link core/internal/ApiDecorator.ApiDecorator}.
|
|
63
45
|
*
|
|
64
46
|
* @memberof core/internal/ApiDecorator.ApiDecorator
|
|
65
47
|
* @hocconfig
|
|
66
48
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
49
|
var defaultConfig = {
|
|
70
50
|
/**
|
|
71
51
|
* Configures the API endpoints to be exposed
|
|
@@ -76,6 +56,7 @@ var defaultConfig = {
|
|
|
76
56
|
*/
|
|
77
57
|
api: null
|
|
78
58
|
};
|
|
59
|
+
|
|
79
60
|
/**
|
|
80
61
|
* {@link core/internal/ApiDecorator.ApiDecorator} is a higher-order component that exposes an
|
|
81
62
|
* imperative API for a contained component. ApiDecorator accepts an array of API endpoints in the
|
|
@@ -98,28 +79,20 @@ var defaultConfig = {
|
|
|
98
79
|
* @hoc
|
|
99
80
|
* @private
|
|
100
81
|
*/
|
|
101
|
-
|
|
102
82
|
var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
103
83
|
var _class;
|
|
104
|
-
|
|
105
84
|
var api = config.api;
|
|
106
85
|
!(api != null) ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'ApiDecorator: api is a required config property') : (0, _invariant["default"])(false) : void 0;
|
|
107
86
|
return _class = /*#__PURE__*/function (_Component) {
|
|
108
87
|
_inherits(_class, _Component);
|
|
109
|
-
|
|
110
88
|
var _super = _createSuper(_class);
|
|
111
|
-
|
|
112
89
|
function _class() {
|
|
113
90
|
var _this;
|
|
114
|
-
|
|
115
91
|
_classCallCheck(this, _class);
|
|
116
|
-
|
|
117
92
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
118
93
|
args[_key] = arguments[_key];
|
|
119
94
|
}
|
|
120
|
-
|
|
121
95
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
122
|
-
|
|
123
96
|
_this.setProvider = function (provider) {
|
|
124
97
|
api.forEach(function (key) {
|
|
125
98
|
Object.defineProperty(_assertThisInitialized(_this), key, {
|
|
@@ -130,10 +103,8 @@ var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped
|
|
|
130
103
|
});
|
|
131
104
|
});
|
|
132
105
|
};
|
|
133
|
-
|
|
134
106
|
return _this;
|
|
135
107
|
}
|
|
136
|
-
|
|
137
108
|
_createClass(_class, [{
|
|
138
109
|
key: "render",
|
|
139
110
|
value: function render() {
|
|
@@ -142,7 +113,6 @@ var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped
|
|
|
142
113
|
}, this.props));
|
|
143
114
|
}
|
|
144
115
|
}]);
|
|
145
|
-
|
|
146
116
|
return _class;
|
|
147
117
|
}(_react.Component), _class.displayName = 'ApiDecorator', _class;
|
|
148
118
|
});
|