@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
|
@@ -1,143 +0,0 @@
|
|
|
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 }; }
|
|
15
|
-
|
|
16
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
-
|
|
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); }
|
|
35
|
-
|
|
36
|
-
// Gets a property from `provider`
|
|
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`
|
|
44
|
-
|
|
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
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Default config for {@link core/internal/ApiDecorator.ApiDecorator}.
|
|
55
|
-
*
|
|
56
|
-
* @memberof core/internal/ApiDecorator.ApiDecorator
|
|
57
|
-
* @hocconfig
|
|
58
|
-
*/
|
|
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
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* {@link core/internal/ApiDecorator.ApiDecorator} is a higher-order component that exposes an
|
|
73
|
-
* imperative API for a contained component. ApiDecorator accepts an array of API endpoints in the
|
|
74
|
-
* `api` config parameter. Each is then mapped to the underlying component instance as either a
|
|
75
|
-
* function call or property getter/setter pair. The component passes a reference to itself to the
|
|
76
|
-
* ApiDecorator by a `setApiProvider` prop added by the HOC.
|
|
77
|
-
*
|
|
78
|
-
* ```
|
|
79
|
-
* import ApiDecorator from '@enact/core/internal/ApiDecorator';
|
|
80
|
-
*
|
|
81
|
-
* const MyComponent = class extends React.Component {
|
|
82
|
-
* static displayName = 'MyComponent';
|
|
83
|
-
*
|
|
84
|
-
* doSomething = () => {
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
*
|
|
88
|
-
* @class ApiDecorator
|
|
89
|
-
* @memberof core/internal/ApiDecorator
|
|
90
|
-
* @hoc
|
|
91
|
-
* @private
|
|
92
|
-
*/
|
|
93
|
-
|
|
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;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = _interopRequireDefault(require("react"));
|
|
4
|
-
|
|
5
|
-
var _enzyme = require("enzyme");
|
|
6
|
-
|
|
7
|
-
var _ApiDecorator = _interopRequireDefault(require("../ApiDecorator"));
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
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); } }
|
|
14
|
-
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
16
|
-
|
|
17
|
-
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); }
|
|
18
|
-
|
|
19
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
-
|
|
21
|
-
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); }; }
|
|
22
|
-
|
|
23
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
24
|
-
|
|
25
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
-
|
|
27
|
-
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; } }
|
|
28
|
-
|
|
29
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
30
|
-
|
|
31
|
-
describe('ApiDecorator', function () {
|
|
32
|
-
var _class, _temp;
|
|
33
|
-
|
|
34
|
-
var ApiProvider = (_temp = _class = /*#__PURE__*/function (_React$Component) {
|
|
35
|
-
_inherits(ApiProvider, _React$Component);
|
|
36
|
-
|
|
37
|
-
var _super = _createSuper(ApiProvider);
|
|
38
|
-
|
|
39
|
-
function ApiProvider(props) {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, ApiProvider);
|
|
43
|
-
|
|
44
|
-
_this = _super.call(this); // eslint-disable-next-line
|
|
45
|
-
|
|
46
|
-
_this.arrowFunction = function () {
|
|
47
|
-
return 'arrow';
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
_this.instanceProperty = 'property';
|
|
51
|
-
props.setApiProvider(_assertThisInitialized(_this));
|
|
52
|
-
return _this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
_createClass(ApiProvider, [{
|
|
56
|
-
key: "instanceFunction",
|
|
57
|
-
value: function instanceFunction() {
|
|
58
|
-
return 'instance';
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: "render",
|
|
62
|
-
value: function render() {
|
|
63
|
-
return /*#__PURE__*/_react["default"].createElement("div", null);
|
|
64
|
-
}
|
|
65
|
-
}]);
|
|
66
|
-
|
|
67
|
-
return ApiProvider;
|
|
68
|
-
}(_react["default"].Component), _class.displayName = 'ApiProvider', _temp);
|
|
69
|
-
test('should invoke arrow function on wrapped component', function () {
|
|
70
|
-
var Component = (0, _ApiDecorator["default"])({
|
|
71
|
-
api: ['arrowFunction']
|
|
72
|
-
}, ApiProvider);
|
|
73
|
-
var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
|
|
74
|
-
var expected = 'arrow';
|
|
75
|
-
var actual = subject.instance().arrowFunction();
|
|
76
|
-
expect(actual).toBe(expected);
|
|
77
|
-
});
|
|
78
|
-
test('should invoke instance function on wrapped component', function () {
|
|
79
|
-
var Component = (0, _ApiDecorator["default"])({
|
|
80
|
-
api: ['instanceFunction']
|
|
81
|
-
}, ApiProvider);
|
|
82
|
-
var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
|
|
83
|
-
var expected = 'instance';
|
|
84
|
-
var actual = subject.instance().instanceFunction();
|
|
85
|
-
expect(actual).toBe(expected);
|
|
86
|
-
});
|
|
87
|
-
test('should get an instance property on wrapped component', function () {
|
|
88
|
-
var Component = (0, _ApiDecorator["default"])({
|
|
89
|
-
api: ['instanceProperty']
|
|
90
|
-
}, ApiProvider);
|
|
91
|
-
var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
|
|
92
|
-
var expected = 'property';
|
|
93
|
-
var actual = subject.instance().instanceProperty;
|
|
94
|
-
expect(actual).toBe(expected);
|
|
95
|
-
});
|
|
96
|
-
test('should set an instance property on wrapped component', function () {
|
|
97
|
-
var Component = (0, _ApiDecorator["default"])({
|
|
98
|
-
api: ['instanceProperty']
|
|
99
|
-
}, ApiProvider);
|
|
100
|
-
var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
|
|
101
|
-
subject.instance().instanceProperty = 'updated';
|
|
102
|
-
var expected = 'updated';
|
|
103
|
-
var actual = subject.instance().instanceProperty;
|
|
104
|
-
expect(actual).toBe(expected);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Registry = exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Allows components to register parents to cascade context changes and trigger functions
|
|
10
|
-
*
|
|
11
|
-
* @type Object
|
|
12
|
-
* @memberof core/Registry
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
var Registry = {
|
|
16
|
-
create: function create(handler) {
|
|
17
|
-
var instances = [];
|
|
18
|
-
var currentParent;
|
|
19
|
-
var registry = Object.freeze({
|
|
20
|
-
set parent(register) {
|
|
21
|
-
if (currentParent && currentParent.unregister) {
|
|
22
|
-
currentParent.unregister();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (register && typeof register === 'function') {
|
|
26
|
-
currentParent = register(registry.notify);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
notify: function notify(ev) {
|
|
31
|
-
var exclude = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
|
32
|
-
return true;
|
|
33
|
-
};
|
|
34
|
-
instances.filter(exclude).forEach(function (f) {
|
|
35
|
-
return f(ev);
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
register: function register(instance) {
|
|
39
|
-
if (instances.indexOf(instance) === -1) {
|
|
40
|
-
instances.push(instance);
|
|
41
|
-
|
|
42
|
-
if (handler) {
|
|
43
|
-
handler({
|
|
44
|
-
action: 'register'
|
|
45
|
-
}, instance);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
notify: function notify(ev) {
|
|
51
|
-
if (handler) {
|
|
52
|
-
handler(ev, instance);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
unregister: function unregister() {
|
|
56
|
-
var i = instances.indexOf(instance);
|
|
57
|
-
|
|
58
|
-
if (i >= 0) {
|
|
59
|
-
instances.splice(i, 1);
|
|
60
|
-
|
|
61
|
-
if (handler) {
|
|
62
|
-
handler({
|
|
63
|
-
action: 'register'
|
|
64
|
-
}, instance);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return registry;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
exports.Registry = Registry;
|
|
75
|
-
var _default = Registry;
|
|
76
|
-
exports["default"] = _default;
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = _interopRequireDefault(require("react"));
|
|
4
|
-
|
|
5
|
-
var _enzyme = require("enzyme");
|
|
6
|
-
|
|
7
|
-
var _Registry = _interopRequireDefault(require("../Registry"));
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
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); } }
|
|
14
|
-
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
16
|
-
|
|
17
|
-
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); }
|
|
18
|
-
|
|
19
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
-
|
|
21
|
-
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); }; }
|
|
22
|
-
|
|
23
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
24
|
-
|
|
25
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
-
|
|
27
|
-
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; } }
|
|
28
|
-
|
|
29
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
30
|
-
|
|
31
|
-
var SomeContext = /*#__PURE__*/_react["default"].createContext();
|
|
32
|
-
|
|
33
|
-
describe('Registry', function () {
|
|
34
|
-
var NotifiesTree = /*#__PURE__*/function (_React$Component) {
|
|
35
|
-
_inherits(NotifiesTree, _React$Component);
|
|
36
|
-
|
|
37
|
-
var _super = _createSuper(NotifiesTree);
|
|
38
|
-
|
|
39
|
-
function NotifiesTree() {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, NotifiesTree);
|
|
43
|
-
|
|
44
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
|
-
args[_key] = arguments[_key];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
49
|
-
_this.registry = _Registry["default"].create();
|
|
50
|
-
|
|
51
|
-
_this.handleClick = function () {
|
|
52
|
-
_this.registry.notify({});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return _this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_createClass(NotifiesTree, [{
|
|
59
|
-
key: "componentDidMount",
|
|
60
|
-
value: function componentDidMount() {
|
|
61
|
-
this.registry.parent = this.context;
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "render",
|
|
65
|
-
value: function render() {
|
|
66
|
-
return /*#__PURE__*/_react["default"].createElement(SomeContext.Provider, {
|
|
67
|
-
value: this.registry.register
|
|
68
|
-
}, /*#__PURE__*/_react["default"].createElement("button", Object.assign({}, this.props, {
|
|
69
|
-
onClick: this.handleClick
|
|
70
|
-
}), "Notify!"), this.props.children);
|
|
71
|
-
}
|
|
72
|
-
}]);
|
|
73
|
-
|
|
74
|
-
return NotifiesTree;
|
|
75
|
-
}(_react["default"].Component);
|
|
76
|
-
|
|
77
|
-
NotifiesTree.contextType = SomeContext;
|
|
78
|
-
|
|
79
|
-
var HandlesNotification = /*#__PURE__*/function (_React$Component2) {
|
|
80
|
-
_inherits(HandlesNotification, _React$Component2);
|
|
81
|
-
|
|
82
|
-
var _super2 = _createSuper(HandlesNotification);
|
|
83
|
-
|
|
84
|
-
function HandlesNotification() {
|
|
85
|
-
var _this2;
|
|
86
|
-
|
|
87
|
-
_classCallCheck(this, HandlesNotification);
|
|
88
|
-
|
|
89
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
90
|
-
args[_key2] = arguments[_key2];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
94
|
-
_this2.state = {
|
|
95
|
-
number: 0
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
_this2.handleResize = function () {
|
|
99
|
-
_this2.setState(function (prevState) {
|
|
100
|
-
var number = prevState.number + 1;
|
|
101
|
-
return {
|
|
102
|
-
number: number
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return _this2;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
_createClass(HandlesNotification, [{
|
|
111
|
-
key: "componentDidMount",
|
|
112
|
-
value: function componentDidMount() {
|
|
113
|
-
if (this.context && typeof this.context === 'function') {
|
|
114
|
-
this.registry = this.context(this.handleResize);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "componentWillUnmount",
|
|
119
|
-
value: function componentWillUnmount() {
|
|
120
|
-
if (this.registry) {
|
|
121
|
-
this.registry.unregister();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "render",
|
|
126
|
-
value: function render() {
|
|
127
|
-
return /*#__PURE__*/_react["default"].createElement("div", this.props, this.state.number);
|
|
128
|
-
}
|
|
129
|
-
}]);
|
|
130
|
-
|
|
131
|
-
return HandlesNotification;
|
|
132
|
-
}(_react["default"].Component);
|
|
133
|
-
|
|
134
|
-
HandlesNotification.contextType = SomeContext;
|
|
135
|
-
test('should increment child on click', function () {
|
|
136
|
-
var RegistryApp = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
137
|
-
id: "a-btn"
|
|
138
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
139
|
-
id: "a"
|
|
140
|
-
})));
|
|
141
|
-
RegistryApp.find('button#a-btn').simulate('click');
|
|
142
|
-
var expected = '1';
|
|
143
|
-
var actual = RegistryApp.find('div#a').text();
|
|
144
|
-
expect(expected).toBe(actual);
|
|
145
|
-
});
|
|
146
|
-
test('should increment both children on top click', function () {
|
|
147
|
-
var RegistryApp = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
148
|
-
id: "a-btn"
|
|
149
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
150
|
-
id: "a"
|
|
151
|
-
}), /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
152
|
-
id: "b-btn"
|
|
153
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
154
|
-
id: "b"
|
|
155
|
-
}))));
|
|
156
|
-
RegistryApp.find('button#a-btn').simulate('click');
|
|
157
|
-
var expected = '1';
|
|
158
|
-
var actualA = RegistryApp.find('div#a').text();
|
|
159
|
-
var actualB = RegistryApp.find('div#b').text();
|
|
160
|
-
expect(expected).toBe(actualA);
|
|
161
|
-
expect(expected).toBe(actualB);
|
|
162
|
-
});
|
|
163
|
-
test('should increment the deepest child when we click child button', function () {
|
|
164
|
-
var RegistryApp = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
165
|
-
id: "a-btn"
|
|
166
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
167
|
-
id: "a"
|
|
168
|
-
}), /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
169
|
-
id: "b-btn"
|
|
170
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
171
|
-
id: "b"
|
|
172
|
-
}))));
|
|
173
|
-
RegistryApp.find('button#b-btn').simulate('click');
|
|
174
|
-
var expectedA = '0';
|
|
175
|
-
var expectedB = '1';
|
|
176
|
-
var actualA = RegistryApp.find('div#a').text();
|
|
177
|
-
var actualB = RegistryApp.find('div#b').text();
|
|
178
|
-
expect(expectedA).toBe(actualA);
|
|
179
|
-
expect(expectedB).toBe(actualB);
|
|
180
|
-
});
|
|
181
|
-
test('should support removing children without error', function () {
|
|
182
|
-
var RegistryApp = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(NotifiesTree, {
|
|
183
|
-
id: "a-btn"
|
|
184
|
-
}, /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
185
|
-
id: "a"
|
|
186
|
-
}), /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
187
|
-
id: "b"
|
|
188
|
-
})));
|
|
189
|
-
RegistryApp.find('button#a-btn').simulate('click'); // changing children should be safe and not throw errors when notifying instances
|
|
190
|
-
|
|
191
|
-
RegistryApp.setProps({
|
|
192
|
-
children: /*#__PURE__*/_react["default"].createElement(HandlesNotification, {
|
|
193
|
-
id: "c"
|
|
194
|
-
})
|
|
195
|
-
});
|
|
196
|
-
RegistryApp.find('button#a-btn').simulate('click');
|
|
197
|
-
var expectedC = '1';
|
|
198
|
-
var actualC = RegistryApp.find('div#c').text();
|
|
199
|
-
expect(expectedC).toBe(actualC);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.deprecate = exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Provides the `deprecate` method
|
|
10
|
-
*
|
|
11
|
-
* @module core/internal/deprecate
|
|
12
|
-
* @private
|
|
13
|
-
*/
|
|
14
|
-
// Utility method to format deprecate message
|
|
15
|
-
var formatMsg = function formatMsg(_ref) {
|
|
16
|
-
var message = _ref.message,
|
|
17
|
-
name = _ref.name,
|
|
18
|
-
until = _ref.until,
|
|
19
|
-
replacedBy = _ref.replacedBy,
|
|
20
|
-
since = _ref.since;
|
|
21
|
-
var msg = 'DEPRECATED:';
|
|
22
|
-
|
|
23
|
-
if (name) {
|
|
24
|
-
msg += " ".concat(name);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (since) {
|
|
28
|
-
msg += " since ".concat(since);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (until) {
|
|
32
|
-
if (name || since) {
|
|
33
|
-
msg += '.';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
msg += " Will be removed in ".concat(until);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (replacedBy) {
|
|
40
|
-
if (name || since || until) {
|
|
41
|
-
msg += '.';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
msg += " Replaced by ".concat(replacedBy);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (name || since || until || replacedBy) {
|
|
48
|
-
msg += '.';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (message) {
|
|
52
|
-
msg += " ".concat(message, ".");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return msg;
|
|
56
|
-
}; // Utility method for console warning
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var warn = function warn(msg) {
|
|
60
|
-
if (typeof console !== 'undefined') {
|
|
61
|
-
console.warn(msg); // eslint-disable-line no-console
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Marks a function, component or property (via `propTypes`) as deprecated. Deprecated items will
|
|
66
|
-
* log a message on first invocation. Can also be used 'stand-alone' to issue a deprecation warning.
|
|
67
|
-
* In stand-alone mode it currently will log every time. In production mode, the deprecation
|
|
68
|
-
* warning disappears.
|
|
69
|
-
*
|
|
70
|
-
* @function
|
|
71
|
-
* @param {*} thing - The thing to be wrapped, or the deprecation config in stand-alone
|
|
72
|
-
* @param {Object?} config - The deprecation config
|
|
73
|
-
* @param {String?} config.name - An optional name for the deprecated item
|
|
74
|
-
* @param {String?} config.message - An optional message to display
|
|
75
|
-
* @param {String?} config.since - The version where deprecation started (optional)
|
|
76
|
-
* @param {String?} config.until - The version where the functionality will be removed (optional)
|
|
77
|
-
* @param {String?} config.replacedBy - An optional alternative
|
|
78
|
-
* @param {Boolean?} config.alwaysWarn - If `true`, a warning will be issued for every access
|
|
79
|
-
* @returns {*} Either a wrapped version of `thing` or an unwrapped version of `thing` in
|
|
80
|
-
* production or stand-alone mode
|
|
81
|
-
* @memberof core/internal/deprecate
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var deprecate = function deprecate(thing, config) {
|
|
87
|
-
if (process.env.NODE_ENV !== "production") {
|
|
88
|
-
if (!config) {
|
|
89
|
-
// If no config, config only invocation, just log message
|
|
90
|
-
var msg = formatMsg(thing);
|
|
91
|
-
warn(msg);
|
|
92
|
-
return thing;
|
|
93
|
-
} else {
|
|
94
|
-
var displayed, _msg;
|
|
95
|
-
|
|
96
|
-
return function () {
|
|
97
|
-
if (!displayed || config.alwaysWarn) {
|
|
98
|
-
if (!_msg) {
|
|
99
|
-
_msg = formatMsg(config);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
warn(_msg);
|
|
103
|
-
displayed = true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return thing.apply(void 0, arguments);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
return thing;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
exports.deprecate = deprecate;
|
|
115
|
-
var _default = deprecate;
|
|
116
|
-
exports["default"] = _default;
|