@enact/core 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/{build/dispatcher → dispatcher}/dispatcher.d.ts +0 -0
  3. package/dispatcher/dispatcher.js +76 -57
  4. package/dispatcher/listeners.js +31 -19
  5. package/dispatcher/tests/dispatcher-specs.js +75 -100
  6. package/{build/handle → handle}/handle.d.ts +0 -0
  7. package/handle/handle.js +260 -212
  8. package/handle/tests/handle-specs.js +476 -601
  9. package/{build/hoc → hoc}/hoc.d.ts +0 -0
  10. package/hoc/hoc.js +47 -33
  11. package/hoc/tests/hoc-specs.js +85 -126
  12. package/{build/index.d.ts → index.d.ts} +0 -0
  13. package/index.js +1 -0
  14. package/{build/internal → internal}/ApiDecorator/ApiDecorator.d.ts +0 -0
  15. package/internal/ApiDecorator/ApiDecorator.js +107 -61
  16. package/internal/ApiDecorator/tests/ApiDecorator-specs.js +106 -97
  17. package/{build/internal → internal}/Registry/Registry.d.ts +0 -0
  18. package/internal/Registry/Registry.js +68 -51
  19. package/internal/Registry/tests/Registry-specs.js +201 -143
  20. package/{build/internal → internal}/deprecate/deprecate.d.ts +0 -0
  21. package/internal/deprecate/deprecate.js +85 -60
  22. package/{build/internal → internal}/prop-types/prop-types.d.ts +0 -0
  23. package/internal/prop-types/prop-types.js +68 -61
  24. package/{build/keymap → keymap}/index.d.ts +0 -0
  25. package/keymap/index.js +27 -15
  26. package/keymap/keymap.js +67 -52
  27. package/keymap/tests/keymap-specs.js +75 -104
  28. package/kind/computed.js +29 -16
  29. package/{build/kind → kind}/kind.d.ts +0 -0
  30. package/kind/kind.js +150 -114
  31. package/kind/styles.js +62 -47
  32. package/kind/tests/computed-specs.js +87 -86
  33. package/kind/tests/kind-specs.js +216 -214
  34. package/kind/tests/styles-specs.js +170 -223
  35. package/kind/util.js +15 -7
  36. package/package.json +1 -1
  37. package/{build/platform → platform}/platform.d.ts +0 -0
  38. package/platform/platform.js +263 -169
  39. package/platform/tests/platform-specs.js +92 -90
  40. package/{build/snapshot → snapshot}/snapshot.d.ts +0 -0
  41. package/snapshot/snapshot.js +34 -27
  42. package/useChainRefs/tests/useChainRefs-specs.js +46 -30
  43. package/{build/useChainRefs → useChainRefs}/useChainRefs.d.ts +0 -0
  44. package/useChainRefs/useChainRefs.js +49 -29
  45. package/useClass/tests/useClass-specs.js +51 -46
  46. package/{build/useClass → useClass}/useClass.d.ts +0 -0
  47. package/useClass/useClass.js +27 -9
  48. package/useHandlers/Handlers.js +55 -30
  49. package/useHandlers/tests/useHandlers-specs.js +79 -95
  50. package/{build/useHandlers → useHandlers}/useHandlers.d.ts +0 -0
  51. package/useHandlers/useHandlers.js +18 -11
  52. package/util/Job.js +203 -241
  53. package/util/tests/Job-specs.js +216 -204
  54. package/util/tests/util-specs.js +123 -146
  55. package/{build/util → util}/util.d.ts +0 -0
  56. package/util/util.js +146 -103
  57. package/build/CHANGELOG.md +0 -699
  58. package/build/README.md +0 -33
  59. package/build/dispatcher/dispatcher.js +0 -160
  60. package/build/dispatcher/listeners.js +0 -37
  61. package/build/dispatcher/package.json +0 -3
  62. package/build/dispatcher/tests/dispatcher-specs.js +0 -75
  63. package/build/handle/handle.js +0 -846
  64. package/build/handle/package.json +0 -3
  65. package/build/handle/tests/handle-specs.js +0 -476
  66. package/build/hoc/hoc.js +0 -102
  67. package/build/hoc/package.json +0 -3
  68. package/build/hoc/tests/hoc-specs.js +0 -90
  69. package/build/index.js +0 -2
  70. package/build/internal/ApiDecorator/ApiDecorator.js +0 -143
  71. package/build/internal/ApiDecorator/package.json +0 -3
  72. package/build/internal/ApiDecorator/tests/ApiDecorator-specs.js +0 -106
  73. package/build/internal/Registry/Registry.js +0 -76
  74. package/build/internal/Registry/package.json +0 -3
  75. package/build/internal/Registry/tests/Registry-specs.js +0 -201
  76. package/build/internal/deprecate/deprecate.js +0 -116
  77. package/build/internal/deprecate/package.json +0 -3
  78. package/build/internal/prop-types/package.json +0 -3
  79. package/build/internal/prop-types/prop-types.js +0 -90
  80. package/build/keymap/index.js +0 -54
  81. package/build/keymap/keymap.js +0 -201
  82. package/build/keymap/package.json +0 -3
  83. package/build/keymap/tests/keymap-specs.js +0 -75
  84. package/build/kind/computed.js +0 -60
  85. package/build/kind/kind.js +0 -266
  86. package/build/kind/package.json +0 -3
  87. package/build/kind/styles.js +0 -105
  88. package/build/kind/tests/computed-specs.js +0 -87
  89. package/build/kind/tests/kind-specs.js +0 -216
  90. package/build/kind/tests/styles-specs.js +0 -170
  91. package/build/kind/util.js +0 -17
  92. package/build/package-lock.json +0 -206
  93. package/build/package.json +0 -38
  94. package/build/platform/package.json +0 -3
  95. package/build/platform/platform.js +0 -306
  96. package/build/platform/tests/platform-specs.js +0 -92
  97. package/build/snapshot/package.json +0 -3
  98. package/build/snapshot/snapshot.js +0 -89
  99. package/build/useChainRefs/package.json +0 -3
  100. package/build/useChainRefs/tests/useChainRefs-specs.js +0 -57
  101. package/build/useChainRefs/useChainRefs.js +0 -78
  102. package/build/useClass/package.json +0 -3
  103. package/build/useClass/tests/useClass-specs.js +0 -51
  104. package/build/useClass/useClass.js +0 -59
  105. package/build/useHandlers/Handlers.js +0 -55
  106. package/build/useHandlers/package.json +0 -3
  107. package/build/useHandlers/tests/useHandlers-specs.js +0 -84
  108. package/build/useHandlers/useHandlers.js +0 -36
  109. package/build/util/Job.js +0 -211
  110. package/build/util/package.json +0 -3
  111. package/build/util/tests/Job-specs.js +0 -216
  112. package/build/util/tests/util-specs.js +0 -123
  113. package/build/util/util.js +0 -322
@@ -1,3 +0,0 @@
1
- {
2
- "main": "handle.js"
3
- }
@@ -1,476 +0,0 @@
1
- "use strict";
2
-
3
- var _handle = require("../handle");
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
-
9
- 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
- describe('handle', function () {
12
- var makeEvent = function makeEvent(payload) {
13
- return _objectSpread({
14
- preventDefault: jest.fn(),
15
- stopPropagation: jest.fn()
16
- }, payload);
17
- };
18
-
19
- var returnsTrue = function returnsTrue() {
20
- return true;
21
- };
22
-
23
- var returnsFalse = function returnsFalse() {
24
- return false;
25
- };
26
-
27
- test('should call only handler', function () {
28
- var handler = jest.fn(returnsTrue);
29
- var callback = (0, _handle.handle)(handler);
30
- callback(makeEvent());
31
- var expected = 1;
32
- var actual = handler.mock.calls.length;
33
- expect(actual).toBe(expected);
34
- });
35
- test('should call multiple handlers', function () {
36
- var handler1 = jest.fn(returnsTrue);
37
- var handler2 = jest.fn(returnsTrue);
38
- var callback = (0, _handle.handle)(handler1, handler2);
39
- callback(makeEvent());
40
- var expected = true;
41
- var actual = handler1.mock.calls.length === 1 && handler2.mock.calls.length === 1;
42
- expect(actual).toBe(expected);
43
- });
44
- test('should skip non-function handlers', function () {
45
- var handler = jest.fn(returnsTrue);
46
- var callback = (0, _handle.handle)(null, void 0, 0, 'purple', handler);
47
- callback(makeEvent());
48
- var expected = 1;
49
- var actual = handler.mock.calls.length;
50
- expect(actual).toBe(expected);
51
- });
52
- test('should not call handlers after one that returns false', function () {
53
- var handler1 = jest.fn(returnsTrue);
54
- var handler2 = jest.fn(returnsTrue);
55
- var callback = (0, _handle.handle)(handler1, returnsFalse, handler2);
56
- callback(makeEvent());
57
- var expected = 0;
58
- var actual = handler2.mock.calls.length;
59
- expect(actual).toBe(expected);
60
- });
61
- test('should call stopPropagation on event', function () {
62
- var callback = (0, _handle.handle)(_handle.stop);
63
- var ev = makeEvent();
64
- callback(ev);
65
- var expected = 1;
66
- var actual = ev.stopPropagation.mock.calls.length;
67
- expect(actual).toBe(expected);
68
- });
69
- test('should call preventDefault on event', function () {
70
- var callback = (0, _handle.handle)(_handle.preventDefault);
71
- var ev = makeEvent();
72
- callback(ev);
73
- var expected = 1;
74
- var actual = ev.preventDefault.mock.calls.length;
75
- expect(actual).toBe(expected);
76
- });
77
- test('should call any method on event', function () {
78
- var callback = (0, _handle.handle)((0, _handle.callOnEvent)('customMethod'));
79
- var ev = makeEvent({
80
- customMethod: jest.fn()
81
- });
82
- callback(ev);
83
- var expected = 1;
84
- var actual = ev.customMethod.mock.calls.length;
85
- expect(actual).toBe(expected);
86
- });
87
- test('should only call handler for specified keyCode', function () {
88
- var keyCode = 13;
89
- var handler = jest.fn();
90
- var callback = (0, _handle.handle)((0, _handle.forKeyCode)(keyCode), handler);
91
- callback(makeEvent());
92
- expect(handler).not.toHaveBeenCalled();
93
- callback(makeEvent({
94
- keyCode: keyCode
95
- }));
96
- expect(handler).toHaveBeenCalled();
97
- });
98
- test('should only call handler for specified event prop', function () {
99
- var prop = 'index';
100
- var value = 0;
101
- var handler = jest.fn();
102
- var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler); // undefined shouldn't pass
103
-
104
- callback(makeEvent());
105
- expect(handler).not.toHaveBeenCalled(); // == check shouldn't pass
106
-
107
- callback(makeEvent(_defineProperty({}, prop, false)));
108
- expect(handler).not.toHaveBeenCalled(); // === should pass
109
-
110
- callback(makeEvent(_defineProperty({}, prop, value)));
111
- expect(handler).toHaveBeenCalled();
112
- });
113
- test('should only call handler for specified prop', function () {
114
- var handler = jest.fn();
115
- var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler); // undefined shouldn't pass
116
-
117
- callback({}, {});
118
- expect(handler).not.toHaveBeenCalled(); // == check shouldn't pass
119
-
120
- callback({}, {
121
- checked: 1
122
- });
123
- expect(handler).not.toHaveBeenCalled(); // === should pass
124
-
125
- callback({}, {
126
- checked: true
127
- });
128
- expect(handler).toHaveBeenCalled();
129
- });
130
- test('should forward events to function specified in provided props', function () {
131
- var event = 'onMyClick';
132
- var prop = 'index';
133
- var propValue = 0;
134
- var spy = jest.fn();
135
-
136
- var props = _defineProperty({}, event, spy);
137
-
138
- var payload = _defineProperty({}, prop, propValue);
139
-
140
- (0, _handle.handle)((0, _handle.forward)(event))(payload, props);
141
- var expected = true;
142
- var actual = spy.mock.calls[0][0][prop] === propValue;
143
- expect(actual).toBe(expected);
144
- });
145
- test('should forwardWithPrevent events to function specified in provided props when preventDefault() hasn\'t been called', function () {
146
- var event = 'onMyClick';
147
- var handler = jest.fn();
148
- var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler);
149
- callback();
150
- expect(handler).toHaveBeenCalledTimes(1);
151
- });
152
- test('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () {
153
- var event = 'onMyClick';
154
- var handler = jest.fn();
155
- var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); // should stop chain when `preventDefault()` has been called
156
-
157
- callback({}, {
158
- 'onMyClick': function onMyClick(ev) {
159
- return ev.preventDefault();
160
- }
161
- });
162
- expect(handler).not.toHaveBeenCalled();
163
- });
164
- test('should include object props as second arg when bound', function () {
165
- var componentInstance = {
166
- context: {},
167
- props: {
168
- value: 1
169
- }
170
- };
171
- var handler = jest.fn();
172
-
173
- var h = _handle.handle.bind(componentInstance);
174
-
175
- var callback = h(handler);
176
- callback();
177
- var expected = 1;
178
- var actual = handler.mock.calls[0][1].value;
179
- expect(actual).toBe(expected);
180
- });
181
- test('should include object context as third arg when bound', function () {
182
- var componentInstance = {
183
- context: {
184
- value: 1
185
- },
186
- props: {}
187
- };
188
- var handler = jest.fn();
189
-
190
- var h = _handle.handle.bind(componentInstance);
191
-
192
- var callback = h(handler);
193
- callback();
194
- var expected = 1;
195
- var actual = handler.mock.calls[0][2].value;
196
- expect(actual).toBe(expected);
197
- });
198
- describe('finally', function () {
199
- test('should call the finally callback when handle returns true', function () {
200
- var finallyCallback = jest.fn();
201
- var callback = (0, _handle.handle)(returnsTrue)["finally"](finallyCallback);
202
- callback(makeEvent());
203
- var expected = 1;
204
- var actual = finallyCallback.mock.calls.length;
205
- expect(actual).toBe(expected);
206
- });
207
- test('should call the finally callback when handle returns false', function () {
208
- var finallyCallback = jest.fn();
209
- var callback = (0, _handle.handle)(returnsFalse)["finally"](finallyCallback);
210
- callback(makeEvent());
211
- var expected = 1;
212
- var actual = finallyCallback.mock.calls.length;
213
- expect(actual).toBe(expected);
214
- });
215
- test('should call the finally callback when handle throws an error', function () {
216
- var finallyCallback = jest.fn();
217
- var callback = (0, _handle.handle)(function () {
218
- throw new Error('Something has gone awry ...');
219
- })["finally"](finallyCallback);
220
-
221
- try {
222
- callback(makeEvent());
223
- } catch (e) {// we don't want the error to interrupt the test
224
- }
225
-
226
- var expected = 1;
227
- var actual = finallyCallback.mock.calls.length;
228
- expect(actual).toBe(expected);
229
- });
230
- });
231
- describe('#oneOf', function () {
232
- test('should call each handler until one passes', function () {
233
- var handler = jest.fn(returnsTrue);
234
- var h1 = [returnsFalse, handler];
235
- var h2 = [returnsTrue, handler];
236
- var callback = (0, _handle.oneOf)(h1, h1, h2);
237
- callback();
238
- var expected = 1;
239
- var actual = handler.mock.calls.length;
240
- expect(actual).toBe(expected);
241
- });
242
- test('should stop if the first handler passes', function () {
243
- var handler = jest.fn(returnsTrue);
244
- var callback = (0, _handle.oneOf)([returnsTrue, handler], [returnsTrue, handler], [returnsTrue, handler]);
245
- callback();
246
- var expected = 1;
247
- var actual = handler.mock.calls.length;
248
- expect(actual).toBe(expected);
249
- });
250
- test('should pass args to condition', function () {
251
- var handler = jest.fn(returnsTrue);
252
- var callback = (0, _handle.oneOf)([handler, returnsTrue]);
253
- var ev = {
254
- value: 1
255
- };
256
- callback(ev);
257
- var expected = ev;
258
- var actual = handler.mock.calls[0][0];
259
- expect(actual).toBe(expected);
260
- });
261
- test('should pass args to handlers', function () {
262
- var handler = jest.fn(returnsTrue);
263
- var callback = (0, _handle.oneOf)([returnsTrue, handler]);
264
- var ev = {
265
- value: 1
266
- };
267
- callback(ev);
268
- var expected = ev;
269
- var actual = handler.mock.calls[0][0];
270
- expect(actual).toBe(expected);
271
- });
272
- test('should return true when the passed condition branch returns a truthy value', function () {
273
- var callback = (0, _handle.oneOf)([returnsTrue, function () {
274
- return 'ok';
275
- }]);
276
- var expected = true;
277
- var actual = callback();
278
- expect(actual).toBe(expected);
279
- });
280
- test('should return false when the passed condition branch returns a falsy value', function () {
281
- var callback = (0, _handle.oneOf)([returnsTrue, function () {
282
- return null;
283
- }]);
284
- var expected = false;
285
- var actual = callback();
286
- expect(actual).toBe(expected);
287
- });
288
- test('should return false when no conditions pass', function () {
289
- var callback = (0, _handle.oneOf)([returnsFalse, returnsTrue], [returnsFalse, returnsTrue]);
290
- var expected = false;
291
- var actual = callback();
292
- expect(actual).toBe(expected);
293
- });
294
- test('should support bound handlers', function () {
295
- var componentInstance = {
296
- props: {},
297
- context: {
298
- value: 1
299
- }
300
- };
301
- var handler = jest.fn();
302
-
303
- var h = _handle.handle.bind(componentInstance);
304
-
305
- var callback = (0, _handle.oneOf)([returnsTrue, h(handler)]);
306
- callback();
307
- var expected = 1;
308
- var actual = handler.mock.calls[0][2].value;
309
- expect(actual).toBe(expected);
310
- });
311
- test('should include object props as second arg when bound', function () {
312
- var componentInstance = {
313
- props: {
314
- value: 1
315
- },
316
- context: {}
317
- };
318
- var handler = jest.fn();
319
-
320
- var o = _handle.oneOf.bind(componentInstance);
321
-
322
- var callback = o([returnsTrue, handler]);
323
- callback();
324
- var expected = 1;
325
- var actual = handler.mock.calls[0][1].value;
326
- expect(actual).toBe(expected);
327
- });
328
- test('should include object context as third arg when bound', function () {
329
- var componentInstance = {
330
- props: {},
331
- context: {
332
- value: 1
333
- }
334
- };
335
- var handler = jest.fn();
336
-
337
- var o = _handle.oneOf.bind(componentInstance);
338
-
339
- var callback = o([returnsTrue, handler]);
340
- callback();
341
- var expected = 1;
342
- var actual = handler.mock.calls[0][2].value;
343
- expect(actual).toBe(expected);
344
- });
345
- test('should support finally callback', function () {
346
- var handler = jest.fn();
347
- var callback = (0, _handle.oneOf)([returnsFalse, returnsTrue], [returnsFalse, returnsTrue])["finally"](handler);
348
- callback();
349
- var expected = 1;
350
- var actual = handler.mock.calls.length;
351
- expect(actual).toBe(expected);
352
- });
353
- });
354
- describe('#adaptEvent', function () {
355
- test('should pass the adapted event payload to the provided handler', function () {
356
- var handler = jest.fn();
357
-
358
- var onlyValue = function onlyValue(_ref) {
359
- var value = _ref.value;
360
- return {
361
- value: value
362
- };
363
- };
364
-
365
- var ev = {
366
- value: 1,
367
- message: 'ok'
368
- };
369
- (0, _handle.adaptEvent)(onlyValue, handler)(ev);
370
- var expected = {
371
- value: 1
372
- };
373
- var actual = handler.mock.calls[0][0];
374
- expect(actual).toEqual(expected);
375
- });
376
- test('should pass additional arguments to the provided handler', function () {
377
- var handler = jest.fn();
378
-
379
- var returnOne = function returnOne() {
380
- return 1;
381
- };
382
-
383
- (0, _handle.adaptEvent)(returnOne, handler)(0, 2, 3);
384
- var expected = [1, 2, 3];
385
- var actual = handler.mock.calls[0];
386
- expect(actual).toEqual(expected);
387
- });
388
- test('should support bound adapter function', function () {
389
- var obj = {
390
- adapt: function adapt() {
391
- return 1;
392
- }
393
- };
394
- var handler = jest.fn();
395
- var fn = (0, _handle.adaptEvent)((0, _handle.call)('adapt'), handler).bind(obj);
396
- fn(0, 2, 3);
397
- var expected = [1, 2, 3];
398
- var actual = handler.mock.calls[0];
399
- expect(actual).toEqual(expected);
400
- });
401
- test('should support bound handler function', function () {
402
- var obj = {
403
- handler: jest.fn()
404
- };
405
-
406
- var returnOne = function returnOne() {
407
- return 1;
408
- };
409
-
410
- var fn = (0, _handle.adaptEvent)(returnOne, (0, _handle.call)('handler')).bind(obj);
411
- fn(0, 2, 3);
412
- var expected = [1, 2, 3];
413
- var actual = obj.handler.mock.calls[0];
414
- expect(actual).toEqual(expected);
415
- });
416
- });
417
- describe('#forwardCustom', function () {
418
- test('should pass an object with `type` when no adapter is provided', function () {
419
- var handler = jest.fn();
420
- (0, _handle.forwardCustom)('onCustomEvent')(null, {
421
- onCustomEvent: handler
422
- });
423
- var expected = {
424
- type: 'onCustomEvent'
425
- };
426
- var actual = handler.mock.calls[0][0];
427
- expect(actual).toEqual(expected);
428
- });
429
- test('should add `type` to object returned by adapter', function () {
430
- var handler = jest.fn();
431
-
432
- var adapter = function adapter() {
433
- return {
434
- index: 0
435
- };
436
- };
437
-
438
- (0, _handle.forwardCustom)('onCustomEvent', adapter)(null, {
439
- onCustomEvent: handler
440
- });
441
- var expected = {
442
- type: 'onCustomEvent',
443
- index: 0
444
- };
445
- var actual = handler.mock.calls[0][0];
446
- expect(actual).toEqual(expected);
447
- });
448
- test('should create an event payload if the adapter returns nothing', function () {
449
- var handler = jest.fn();
450
-
451
- var adapter = function adapter() {
452
- return null;
453
- };
454
-
455
- (0, _handle.forwardCustom)('onCustomEvent', adapter)(null, {
456
- onCustomEvent: handler
457
- });
458
- var expected = {
459
- type: 'onCustomEvent'
460
- };
461
- var actual = handler.mock.calls[0][0];
462
- expect(actual).toEqual(expected);
463
- });
464
- test('should pass event, props, and context args to adapter', function () {
465
- var adapter = jest.fn();
466
- var args = [1, // ev,
467
- 2, // props,
468
- 3 // context
469
- ];
470
- (0, _handle.forwardCustom)('onCustomEvent', adapter).apply(void 0, args);
471
- var expected = args;
472
- var actual = adapter.mock.calls[0];
473
- expect(actual).toEqual(expected);
474
- });
475
- });
476
- });
package/build/hoc/hoc.js DELETED
@@ -1,102 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hoc = exports["default"] = void 0;
7
-
8
- var _util = require("../util");
9
-
10
- var _mergeDeepWithKey = _interopRequireDefault(require("ramda/src/mergeDeepWithKey"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- /**
15
- * Provides the {@link core/hoc.hoc} method to create higher-order components (HOCs).
16
- *
17
- * @module core/hoc
18
- * @exports hoc
19
- */
20
- var mergeFn = function mergeFn(key, defaultValue, userValue) {
21
- // eslint-disable-next-line no-undefined
22
- if (userValue === undefined) {
23
- return defaultValue;
24
- }
25
-
26
- return userValue;
27
- };
28
- /**
29
- * Constructs a higher-order component (HOC) using an optional set of default configuration parameters and
30
- * a factory method that accepts instance configuration parameters and a component to wrap. The
31
- * returned function can accept:
32
- * * an instance config and a component constructor to wrap and return a renderable component, or
33
- * * an instance config only and return a decorator function expecting a component constructor
34
- * (like the next bullet), or
35
- * * a component constructor and return a renderable component
36
- *
37
- * Example:
38
- * ```
39
- * const Countable = hoc({prop: 'data-count'}, (config, Wrapped) => {
40
- * return class extends React.Component {
41
- * constructor (props) {
42
- * super(props);
43
- * this.state = {
44
- * count: 0
45
- * };
46
- * },
47
- * inc = () => this.setState({count: this.state.count + 1}),
48
- * render () {
49
- * const props = Object.assign({}, this.props, {
50
- * [config.prop]: this.state.count,
51
- * onClick: this.inc
52
- * });
53
- * return <Wrapped {...props} />
54
- * }
55
- * }
56
- * });
57
- *
58
- * const CountableAsDataNumber({prop: 'data-number'});
59
- * const CountableDiv('div');
60
- * const CountableDivAsDataNumber = CountableAsDataNumber('div');
61
- * ```
62
- *
63
- * @function
64
- * @param {Object} defaultConfig Set of default configuration parameters
65
- * @param {Function} hawk Higher-order component
66
- *
67
- * @returns {Function} HOC Decorator
68
- * @memberof core/hoc
69
- * @public
70
- */
71
-
72
-
73
- var hoc = function hoc(defaultConfig, hawk) {
74
- // normalize arguments to allow defaultConfig to be omitted
75
- var factory = hawk;
76
- var defaults = defaultConfig;
77
-
78
- if (!factory && typeof defaultConfig === 'function') {
79
- factory = defaultConfig;
80
- defaults = null;
81
- }
82
-
83
- return function (config, maybeWrapped) {
84
- if ((0, _util.isRenderable)(config)) {
85
- return factory(defaults, config);
86
- } else {
87
- var cfg = (0, _mergeDeepWithKey["default"])(mergeFn, defaults, config);
88
-
89
- if ((0, _util.isRenderable)(maybeWrapped)) {
90
- return factory(cfg, maybeWrapped);
91
- } else {
92
- return function (Wrapped) {
93
- return factory(cfg, Wrapped);
94
- };
95
- }
96
- }
97
- };
98
- };
99
-
100
- exports.hoc = hoc;
101
- var _default = hoc;
102
- exports["default"] = _default;
@@ -1,3 +0,0 @@
1
- {
2
- "main": "hoc.js"
3
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- var _react = _interopRequireDefault(require("react"));
4
-
5
- var _enzyme = require("enzyme");
6
-
7
- var _hoc = _interopRequireDefault(require("../hoc"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
-
11
- /* eslint-disable enact/display-name */
12
- describe('hoc', function () {
13
- var defaultConfig = {
14
- color: 'blue'
15
- };
16
- var HoC = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
17
- return function (props) {
18
- return /*#__PURE__*/_react["default"].createElement(Wrapped, Object.assign({}, props, config));
19
- };
20
- });
21
- var NullHoC = (0, _hoc["default"])(null, function (config, Wrapped) {
22
- return function () {
23
- return /*#__PURE__*/_react["default"].createElement(Wrapped, config);
24
- };
25
- });
26
- test('should support HoC factory function as first argument to hoc()', function () {
27
- var ImplicitNullHoC = (0, _hoc["default"])(function (config, Wrapped) {
28
- return function () {
29
- return /*#__PURE__*/_react["default"].createElement(Wrapped, config);
30
- };
31
- });
32
- var Component = ImplicitNullHoC('span');
33
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/_react["default"].createElement(Component, null));
34
- var expected = 'span';
35
- var actual = subject.name();
36
- expect(actual).toBe(expected);
37
- });
38
- test('should support DOM node name as first argument to HoC', function () {
39
- var Component = HoC('span');
40
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/_react["default"].createElement(Component, null));
41
- var expected = 'span';
42
- var actual = subject.name();
43
- expect(actual).toBe(expected);
44
- });
45
- test('should support React component as first argument to HoC', function () {
46
- function Thing() {
47
- return /*#__PURE__*/_react["default"].createElement("div", null);
48
- }
49
-
50
- var Component = HoC(Thing);
51
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/_react["default"].createElement(Component, null));
52
- var expected = 'Thing';
53
- var actual = subject.name();
54
- expect(actual).toBe(expected);
55
- });
56
- test('should use default config when instance config is omitted', function () {
57
- var Component = HoC('span');
58
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
59
- var expected = defaultConfig.color;
60
- var actual = subject.find('span').prop('color');
61
- expect(actual).toBe(expected);
62
- });
63
- test('should overwrite default config with instance config', function () {
64
- var instanceConfig = {
65
- color: 'green'
66
- };
67
- var Component = HoC(instanceConfig, 'div');
68
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
69
- var expected = instanceConfig.color;
70
- var actual = subject.find('div').prop('color');
71
- expect(actual).toBe(expected);
72
- });
73
- test('should allow construction without default or instance configs', function () {
74
- var Component = NullHoC('div');
75
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
76
- var expected = 1;
77
- var actual = subject.find('div').length;
78
- expect(actual).toBe(expected);
79
- });
80
- test('should allow construction without default config', function () {
81
- var instanceConfig = {
82
- color: 'green'
83
- };
84
- var Component = NullHoC(instanceConfig, 'div');
85
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
86
- var expected = instanceConfig.color;
87
- var actual = subject.find('div').prop('color');
88
- expect(actual).toBe(expected);
89
- });
90
- });
package/build/index.js DELETED
@@ -1,2 +0,0 @@
1
- // This space intentionally left blank
2
- "use strict";