@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.
- package/CHANGELOG.md +16 -0
- package/{build/dispatcher → dispatcher}/dispatcher.d.ts +0 -0
- package/dispatcher/dispatcher.js +76 -57
- package/dispatcher/listeners.js +31 -19
- package/dispatcher/tests/dispatcher-specs.js +75 -100
- package/{build/handle → handle}/handle.d.ts +0 -0
- package/handle/handle.js +260 -212
- package/handle/tests/handle-specs.js +476 -601
- package/{build/hoc → hoc}/hoc.d.ts +0 -0
- package/hoc/hoc.js +47 -33
- package/hoc/tests/hoc-specs.js +85 -126
- package/{build/index.d.ts → index.d.ts} +0 -0
- package/index.js +1 -0
- package/{build/internal → internal}/ApiDecorator/ApiDecorator.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.js +107 -61
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +106 -97
- package/{build/internal → internal}/Registry/Registry.d.ts +0 -0
- package/internal/Registry/Registry.js +68 -51
- package/internal/Registry/tests/Registry-specs.js +201 -143
- package/{build/internal → internal}/deprecate/deprecate.d.ts +0 -0
- package/internal/deprecate/deprecate.js +85 -60
- package/{build/internal → internal}/prop-types/prop-types.d.ts +0 -0
- package/internal/prop-types/prop-types.js +68 -61
- package/{build/keymap → keymap}/index.d.ts +0 -0
- package/keymap/index.js +27 -15
- package/keymap/keymap.js +67 -52
- package/keymap/tests/keymap-specs.js +75 -104
- package/kind/computed.js +29 -16
- package/{build/kind → kind}/kind.d.ts +0 -0
- package/kind/kind.js +150 -114
- package/kind/styles.js +62 -47
- package/kind/tests/computed-specs.js +87 -86
- package/kind/tests/kind-specs.js +216 -214
- package/kind/tests/styles-specs.js +170 -223
- package/kind/util.js +15 -7
- package/package.json +1 -1
- package/{build/platform → platform}/platform.d.ts +0 -0
- package/platform/platform.js +263 -169
- package/platform/tests/platform-specs.js +92 -90
- package/{build/snapshot → snapshot}/snapshot.d.ts +0 -0
- package/snapshot/snapshot.js +34 -27
- package/useChainRefs/tests/useChainRefs-specs.js +46 -30
- package/{build/useChainRefs → useChainRefs}/useChainRefs.d.ts +0 -0
- package/useChainRefs/useChainRefs.js +49 -29
- package/useClass/tests/useClass-specs.js +51 -46
- package/{build/useClass → useClass}/useClass.d.ts +0 -0
- package/useClass/useClass.js +27 -9
- package/useHandlers/Handlers.js +55 -30
- package/useHandlers/tests/useHandlers-specs.js +79 -95
- package/{build/useHandlers → useHandlers}/useHandlers.d.ts +0 -0
- package/useHandlers/useHandlers.js +18 -11
- package/util/Job.js +203 -241
- package/util/tests/Job-specs.js +216 -204
- package/util/tests/util-specs.js +123 -146
- package/{build/util → util}/util.d.ts +0 -0
- package/util/util.js +146 -103
- package/build/CHANGELOG.md +0 -699
- package/build/README.md +0 -33
- package/build/dispatcher/dispatcher.js +0 -160
- package/build/dispatcher/listeners.js +0 -37
- package/build/dispatcher/package.json +0 -3
- package/build/dispatcher/tests/dispatcher-specs.js +0 -75
- package/build/handle/handle.js +0 -846
- package/build/handle/package.json +0 -3
- package/build/handle/tests/handle-specs.js +0 -476
- package/build/hoc/hoc.js +0 -102
- package/build/hoc/package.json +0 -3
- package/build/hoc/tests/hoc-specs.js +0 -90
- package/build/index.js +0 -2
- package/build/internal/ApiDecorator/ApiDecorator.js +0 -143
- package/build/internal/ApiDecorator/package.json +0 -3
- package/build/internal/ApiDecorator/tests/ApiDecorator-specs.js +0 -106
- package/build/internal/Registry/Registry.js +0 -76
- package/build/internal/Registry/package.json +0 -3
- package/build/internal/Registry/tests/Registry-specs.js +0 -201
- package/build/internal/deprecate/deprecate.js +0 -116
- package/build/internal/deprecate/package.json +0 -3
- package/build/internal/prop-types/package.json +0 -3
- package/build/internal/prop-types/prop-types.js +0 -90
- package/build/keymap/index.js +0 -54
- package/build/keymap/keymap.js +0 -201
- package/build/keymap/package.json +0 -3
- package/build/keymap/tests/keymap-specs.js +0 -75
- package/build/kind/computed.js +0 -60
- package/build/kind/kind.js +0 -266
- package/build/kind/package.json +0 -3
- package/build/kind/styles.js +0 -105
- package/build/kind/tests/computed-specs.js +0 -87
- package/build/kind/tests/kind-specs.js +0 -216
- package/build/kind/tests/styles-specs.js +0 -170
- package/build/kind/util.js +0 -17
- package/build/package-lock.json +0 -206
- package/build/package.json +0 -38
- package/build/platform/package.json +0 -3
- package/build/platform/platform.js +0 -306
- package/build/platform/tests/platform-specs.js +0 -92
- package/build/snapshot/package.json +0 -3
- package/build/snapshot/snapshot.js +0 -89
- package/build/useChainRefs/package.json +0 -3
- package/build/useChainRefs/tests/useChainRefs-specs.js +0 -57
- package/build/useChainRefs/useChainRefs.js +0 -78
- package/build/useClass/package.json +0 -3
- package/build/useClass/tests/useClass-specs.js +0 -51
- package/build/useClass/useClass.js +0 -59
- package/build/useHandlers/Handlers.js +0 -55
- package/build/useHandlers/package.json +0 -3
- package/build/useHandlers/tests/useHandlers-specs.js +0 -84
- package/build/useHandlers/useHandlers.js +0 -36
- package/build/util/Job.js +0 -211
- package/build/util/package.json +0 -3
- package/build/util/tests/Job-specs.js +0 -216
- package/build/util/tests/util-specs.js +0 -123
- package/build/util/util.js +0 -322
|
File without changes
|
package/hoc/hoc.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
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
|
+
|
|
1
14
|
/**
|
|
2
15
|
* Provides the {@link core/hoc.hoc} method to create higher-order components (HOCs).
|
|
3
16
|
*
|
|
4
17
|
* @module core/hoc
|
|
5
18
|
* @exports hoc
|
|
6
19
|
*/
|
|
20
|
+
var mergeFn = function mergeFn(key, defaultValue, userValue) {
|
|
21
|
+
// eslint-disable-next-line no-undefined
|
|
22
|
+
if (userValue === undefined) {
|
|
23
|
+
return defaultValue;
|
|
24
|
+
}
|
|
7
25
|
|
|
8
|
-
|
|
9
|
-
import mergeDeepWithKey from 'ramda/src/mergeDeepWithKey';
|
|
10
|
-
|
|
11
|
-
const mergeFn = (key, defaultValue, userValue) => {
|
|
12
|
-
// eslint-disable-next-line no-undefined
|
|
13
|
-
if (userValue === undefined) {
|
|
14
|
-
return defaultValue;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return userValue;
|
|
26
|
+
return userValue;
|
|
18
27
|
};
|
|
19
|
-
|
|
20
28
|
/**
|
|
21
29
|
* Constructs a higher-order component (HOC) using an optional set of default configuration parameters and
|
|
22
30
|
* a factory method that accepts instance configuration parameters and a component to wrap. The
|
|
@@ -60,29 +68,35 @@ const mergeFn = (key, defaultValue, userValue) => {
|
|
|
60
68
|
* @memberof core/hoc
|
|
61
69
|
* @public
|
|
62
70
|
*/
|
|
63
|
-
const hoc = (defaultConfig, hawk) => {
|
|
64
71
|
|
|
65
|
-
// normalize arguments to allow defaultConfig to be omitted
|
|
66
|
-
let factory = hawk;
|
|
67
|
-
let defaults = defaultConfig;
|
|
68
|
-
if (!factory && typeof defaultConfig === 'function') {
|
|
69
|
-
factory = defaultConfig;
|
|
70
|
-
defaults = null;
|
|
71
|
-
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
};
|
|
85
98
|
};
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
exports.hoc = hoc;
|
|
101
|
+
var _default = hoc;
|
|
102
|
+
exports["default"] = _default;
|
package/hoc/tests/hoc-specs.js
CHANGED
|
@@ -1,131 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {shallow, mount} from 'enzyme';
|
|
5
|
-
import hoc from '../hoc';
|
|
6
|
-
|
|
7
|
-
describe('hoc', () => {
|
|
8
|
-
|
|
9
|
-
const defaultConfig = {
|
|
10
|
-
color: 'blue'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const HoC = hoc(defaultConfig, (config, Wrapped) => {
|
|
14
|
-
return (props) => <Wrapped {...props} {...config} />;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const NullHoC = hoc(null, (config, Wrapped) => {
|
|
18
|
-
return () => <Wrapped {...config} />;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test(
|
|
22
|
-
'should support HoC factory function as first argument to hoc()',
|
|
23
|
-
() => {
|
|
24
|
-
const ImplicitNullHoC = hoc((config, Wrapped) => {
|
|
25
|
-
return () => <Wrapped {...config} />;
|
|
26
|
-
});
|
|
27
|
-
const Component = ImplicitNullHoC('span');
|
|
28
|
-
|
|
29
|
-
const subject = shallow(
|
|
30
|
-
<Component />
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const expected = 'span';
|
|
34
|
-
const actual = subject.name();
|
|
35
|
-
|
|
36
|
-
expect(actual).toBe(expected);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
test('should support DOM node name as first argument to HoC', () => {
|
|
42
|
-
const Component = HoC('span');
|
|
43
|
-
|
|
44
|
-
const subject = shallow(
|
|
45
|
-
<Component />
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const expected = 'span';
|
|
49
|
-
const actual = subject.name();
|
|
50
|
-
|
|
51
|
-
expect(actual).toBe(expected);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should support React component as first argument to HoC', () => {
|
|
55
|
-
function Thing () {
|
|
56
|
-
return <div />;
|
|
57
|
-
}
|
|
58
|
-
const Component = HoC(Thing);
|
|
1
|
+
"use strict";
|
|
59
2
|
|
|
60
|
-
|
|
61
|
-
<Component />
|
|
62
|
-
);
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
63
4
|
|
|
64
|
-
|
|
65
|
-
const actual = subject.name();
|
|
5
|
+
var _enzyme = require("enzyme");
|
|
66
6
|
|
|
67
|
-
|
|
68
|
-
});
|
|
7
|
+
var _hoc = _interopRequireDefault(require("../hoc"));
|
|
69
8
|
|
|
70
|
-
|
|
71
|
-
const Component = HoC('span');
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
72
10
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
});
|
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
|
@@ -1,46 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ApiDecorator = exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _hoc = _interopRequireDefault(require("../../hoc"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
7
15
|
|
|
8
|
-
|
|
9
|
-
import React from 'react';
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
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); } }
|
|
19
|
+
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
21
|
+
|
|
22
|
+
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
23
|
+
|
|
24
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
|
+
|
|
26
|
+
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); }; }
|
|
27
|
+
|
|
28
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
29
|
+
|
|
30
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
31
|
+
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
33
|
+
|
|
34
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12
35
|
|
|
13
36
|
// Gets a property from `provider`
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
37
|
+
var get = function get(provider, name) {
|
|
38
|
+
return function () {
|
|
39
|
+
if (provider) {
|
|
40
|
+
return provider[name];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}; // Sets a property on `provider`
|
|
19
44
|
|
|
20
|
-
// Sets a property on `provider`
|
|
21
|
-
const set = (provider, name) => (value) => {
|
|
22
|
-
if (provider && typeof provider[name] !== 'function') {
|
|
23
|
-
return (provider[name] = value);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
45
|
|
|
46
|
+
var set = function set(provider, name) {
|
|
47
|
+
return function (value) {
|
|
48
|
+
if (provider && typeof provider[name] !== 'function') {
|
|
49
|
+
return provider[name] = value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
27
53
|
/**
|
|
28
54
|
* Default config for {@link core/internal/ApiDecorator.ApiDecorator}.
|
|
29
55
|
*
|
|
30
56
|
* @memberof core/internal/ApiDecorator.ApiDecorator
|
|
31
57
|
* @hocconfig
|
|
32
58
|
*/
|
|
33
|
-
const defaultConfig = {
|
|
34
|
-
/**
|
|
35
|
-
* Configures the API endpoints to be exposed
|
|
36
|
-
*
|
|
37
|
-
* @type {String[]}
|
|
38
|
-
* @required
|
|
39
|
-
* @memberof core/internal/ApiDecorator.ApiDecorator.defaultConfig
|
|
40
|
-
*/
|
|
41
|
-
api: null
|
|
42
|
-
};
|
|
43
59
|
|
|
60
|
+
|
|
61
|
+
var defaultConfig = {
|
|
62
|
+
/**
|
|
63
|
+
* Configures the API endpoints to be exposed
|
|
64
|
+
*
|
|
65
|
+
* @type {String[]}
|
|
66
|
+
* @required
|
|
67
|
+
* @memberof core/internal/ApiDecorator.ApiDecorator.defaultConfig
|
|
68
|
+
*/
|
|
69
|
+
api: null
|
|
70
|
+
};
|
|
44
71
|
/**
|
|
45
72
|
* {@link core/internal/ApiDecorator.ApiDecorator} is a higher-order component that exposes an
|
|
46
73
|
* imperative API for a contained component. ApiDecorator accepts an array of API endpoints in the
|
|
@@ -63,35 +90,54 @@ const defaultConfig = {
|
|
|
63
90
|
* @hoc
|
|
64
91
|
* @private
|
|
65
92
|
*/
|
|
66
|
-
const ApiDecorator = hoc(defaultConfig, (config, Wrapped) => {
|
|
67
|
-
const {api} = config;
|
|
68
|
-
|
|
69
|
-
invariant(
|
|
70
|
-
api != null,
|
|
71
|
-
'ApiDecorator: api is a required config property'
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
return class extends React.Component {
|
|
75
|
-
static displayName = 'ApiDecorator';
|
|
76
|
-
|
|
77
|
-
setProvider = (provider) => {
|
|
78
|
-
api.forEach(key => {
|
|
79
|
-
Object.defineProperty(this, key, {
|
|
80
|
-
get: get(provider, key),
|
|
81
|
-
set: set(provider, key),
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
render () {
|
|
89
|
-
return <Wrapped setApiProvider={this.setProvider} {...this.props} />;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
95
|
+
var _class, _temp;
|
|
96
|
+
|
|
97
|
+
var api = config.api;
|
|
98
|
+
!(api != null) ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'ApiDecorator: api is a required config property') : invariant(false) : void 0;
|
|
99
|
+
return _temp = _class = /*#__PURE__*/function (_React$Component) {
|
|
100
|
+
_inherits(_class, _React$Component);
|
|
101
|
+
|
|
102
|
+
var _super = _createSuper(_class);
|
|
103
|
+
|
|
104
|
+
function _class() {
|
|
105
|
+
var _this;
|
|
106
|
+
|
|
107
|
+
_classCallCheck(this, _class);
|
|
108
|
+
|
|
109
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
110
|
+
args[_key] = arguments[_key];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
114
|
+
|
|
115
|
+
_this.setProvider = function (provider) {
|
|
116
|
+
api.forEach(function (key) {
|
|
117
|
+
Object.defineProperty(_assertThisInitialized(_this), key, {
|
|
118
|
+
get: get(provider, key),
|
|
119
|
+
set: set(provider, key),
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return _this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_createClass(_class, [{
|
|
130
|
+
key: "render",
|
|
131
|
+
value: function render() {
|
|
132
|
+
return /*#__PURE__*/_react["default"].createElement(Wrapped, Object.assign({
|
|
133
|
+
setApiProvider: this.setProvider
|
|
134
|
+
}, this.props));
|
|
135
|
+
}
|
|
136
|
+
}]);
|
|
137
|
+
|
|
138
|
+
return _class;
|
|
139
|
+
}(_react["default"].Component), _class.displayName = 'ApiDecorator', _temp;
|
|
140
|
+
});
|
|
141
|
+
exports.ApiDecorator = ApiDecorator;
|
|
142
|
+
var _default = ApiDecorator;
|
|
143
|
+
exports["default"] = _default;
|