@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,60 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _react2 = require("react");
|
|
6
|
-
|
|
7
5
|
var _ApiDecorator = _interopRequireDefault(require("../ApiDecorator"));
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
|
|
15
9
|
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); } }
|
|
16
|
-
|
|
17
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
-
|
|
19
11
|
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); }
|
|
20
|
-
|
|
21
12
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
-
|
|
23
13
|
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); }; }
|
|
24
|
-
|
|
25
14
|
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); }
|
|
26
|
-
|
|
27
15
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
28
|
-
|
|
29
16
|
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; } }
|
|
30
|
-
|
|
31
17
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
32
|
-
|
|
33
18
|
describe('ApiDecorator', function () {
|
|
34
|
-
var _class;
|
|
35
|
-
|
|
36
|
-
var data = [];
|
|
19
|
+
var _class, _class2;
|
|
37
20
|
var ApiProvider = (_class = /*#__PURE__*/function (_ReactComponent) {
|
|
38
21
|
_inherits(ApiProvider, _ReactComponent);
|
|
39
|
-
|
|
40
22
|
var _super = _createSuper(ApiProvider);
|
|
41
|
-
|
|
42
23
|
function ApiProvider(props) {
|
|
43
24
|
var _this;
|
|
44
|
-
|
|
45
25
|
_classCallCheck(this, ApiProvider);
|
|
46
|
-
|
|
47
26
|
_this = _super.call(this);
|
|
48
|
-
|
|
49
27
|
_this.arrowFunction = function () {
|
|
50
28
|
return 'arrow';
|
|
51
29
|
};
|
|
52
|
-
|
|
53
30
|
_this.instanceProperty = 'property';
|
|
54
31
|
props.setApiProvider(_assertThisInitialized(_this));
|
|
55
32
|
return _this;
|
|
56
33
|
}
|
|
57
|
-
|
|
58
34
|
_createClass(ApiProvider, [{
|
|
59
35
|
key: "instanceFunction",
|
|
60
36
|
value: function instanceFunction() {
|
|
@@ -63,52 +39,105 @@ describe('ApiDecorator', function () {
|
|
|
63
39
|
}, {
|
|
64
40
|
key: "render",
|
|
65
41
|
value: function render() {
|
|
66
|
-
data = {
|
|
67
|
-
arrowFunction: this.arrowFunction,
|
|
68
|
-
instanceFunction: this.instanceFunction,
|
|
69
|
-
instanceProperty: this.instanceProperty
|
|
70
|
-
};
|
|
71
42
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
72
43
|
}
|
|
73
44
|
}]);
|
|
74
|
-
|
|
75
45
|
return ApiProvider;
|
|
76
46
|
}(_react2.Component), _class.displayName = 'ApiProvider', _class);
|
|
47
|
+
var WrongApiProvider = (_class2 = /*#__PURE__*/function (_ReactComponent2) {
|
|
48
|
+
_inherits(WrongApiProvider, _ReactComponent2);
|
|
49
|
+
var _super2 = _createSuper(WrongApiProvider);
|
|
50
|
+
function WrongApiProvider(props) {
|
|
51
|
+
var _this2;
|
|
52
|
+
_classCallCheck(this, WrongApiProvider);
|
|
53
|
+
_this2 = _super2.call(this);
|
|
54
|
+
props.setApiProvider();
|
|
55
|
+
return _this2;
|
|
56
|
+
}
|
|
57
|
+
_createClass(WrongApiProvider, [{
|
|
58
|
+
key: "render",
|
|
59
|
+
value: function render() {
|
|
60
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
return WrongApiProvider;
|
|
64
|
+
}(_react2.Component), _class2.displayName = 'WrongApiProvider', _class2);
|
|
77
65
|
test('should invoke arrow function on wrapped component', function () {
|
|
66
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
78
67
|
var Component = (0, _ApiDecorator["default"])({
|
|
79
68
|
api: ['arrowFunction']
|
|
80
69
|
}, ApiProvider);
|
|
81
|
-
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
70
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
71
|
+
ref: ref
|
|
72
|
+
}));
|
|
82
73
|
var expected = 'arrow';
|
|
83
|
-
var actual =
|
|
74
|
+
var actual = ref.current.arrowFunction();
|
|
84
75
|
expect(actual).toBe(expected);
|
|
85
76
|
});
|
|
86
77
|
test('should invoke instance function on wrapped component', function () {
|
|
78
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
87
79
|
var Component = (0, _ApiDecorator["default"])({
|
|
88
80
|
api: ['instanceFunction']
|
|
89
81
|
}, ApiProvider);
|
|
90
|
-
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
82
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
83
|
+
ref: ref
|
|
84
|
+
}));
|
|
91
85
|
var expected = 'instance';
|
|
92
|
-
var actual =
|
|
86
|
+
var actual = ref.current.instanceFunction();
|
|
93
87
|
expect(actual).toBe(expected);
|
|
94
88
|
});
|
|
95
89
|
test('should get an instance property on wrapped component', function () {
|
|
90
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
96
91
|
var Component = (0, _ApiDecorator["default"])({
|
|
97
92
|
api: ['instanceProperty']
|
|
98
93
|
}, ApiProvider);
|
|
99
|
-
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
94
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
95
|
+
ref: ref
|
|
96
|
+
}));
|
|
100
97
|
var expected = 'property';
|
|
101
|
-
var actual =
|
|
98
|
+
var actual = ref.current.instanceProperty;
|
|
102
99
|
expect(actual).toBe(expected);
|
|
103
100
|
});
|
|
104
101
|
test('should set an instance property on wrapped component', function () {
|
|
102
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
105
103
|
var Component = (0, _ApiDecorator["default"])({
|
|
106
104
|
api: ['instanceProperty']
|
|
107
105
|
}, ApiProvider);
|
|
108
|
-
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
109
|
-
|
|
106
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
107
|
+
ref: ref
|
|
108
|
+
}));
|
|
109
|
+
ref.current.instanceProperty = 'updated';
|
|
110
110
|
var expected = 'updated';
|
|
111
|
-
var actual =
|
|
111
|
+
var actual = ref.current.instanceProperty;
|
|
112
|
+
expect(actual).toBe(expected);
|
|
113
|
+
});
|
|
114
|
+
test('should not get an instance property on wrapped component if the parameter of setApiProvider is missing', function () {
|
|
115
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
116
|
+
var Component = (0, _ApiDecorator["default"])({
|
|
117
|
+
api: ['instanceProperty']
|
|
118
|
+
}, WrongApiProvider);
|
|
119
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
120
|
+
ref: ref
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
// eslint-disable-next-line no-undefined
|
|
124
|
+
var expected = undefined;
|
|
125
|
+
var actual = ref.current.instanceProperty;
|
|
126
|
+
expect(actual).toBe(expected);
|
|
127
|
+
});
|
|
128
|
+
test('should not set an instance property on wrapped component if the parameter of setApiProvider is missing', function () {
|
|
129
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
130
|
+
var Component = (0, _ApiDecorator["default"])({
|
|
131
|
+
api: ['instanceProperty']
|
|
132
|
+
}, WrongApiProvider);
|
|
133
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
134
|
+
ref: ref
|
|
135
|
+
}));
|
|
136
|
+
ref.current.instanceProperty = 'updated';
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line no-undefined
|
|
139
|
+
var expected = undefined;
|
|
140
|
+
var actual = ref.current.instanceProperty;
|
|
112
141
|
expect(actual).toBe(expected);
|
|
113
142
|
});
|
|
114
143
|
});
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.Registry = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Allows components to register parents to cascade context changes and trigger functions
|
|
10
9
|
*
|
|
@@ -21,12 +20,10 @@ var Registry = {
|
|
|
21
20
|
if (currentParent && currentParent.unregister) {
|
|
22
21
|
currentParent.unregister();
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
if (register && typeof register === 'function') {
|
|
26
24
|
currentParent = register(registry.notify);
|
|
27
25
|
}
|
|
28
26
|
},
|
|
29
|
-
|
|
30
27
|
notify: function notify(ev) {
|
|
31
28
|
var exclude = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
|
32
29
|
return true;
|
|
@@ -38,14 +35,12 @@ var Registry = {
|
|
|
38
35
|
register: function register(instance) {
|
|
39
36
|
if (instances.indexOf(instance) === -1) {
|
|
40
37
|
instances.push(instance);
|
|
41
|
-
|
|
42
38
|
if (handler) {
|
|
43
39
|
handler({
|
|
44
40
|
action: 'register'
|
|
45
41
|
}, instance);
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
|
-
|
|
49
44
|
return {
|
|
50
45
|
notify: function notify(ev) {
|
|
51
46
|
if (handler) {
|
|
@@ -54,10 +49,8 @@ var Registry = {
|
|
|
54
49
|
},
|
|
55
50
|
unregister: function unregister() {
|
|
56
51
|
var i = instances.indexOf(instance);
|
|
57
|
-
|
|
58
52
|
if (i >= 0) {
|
|
59
53
|
instances.splice(i, 1);
|
|
60
|
-
|
|
61
54
|
if (handler) {
|
|
62
55
|
handler({
|
|
63
56
|
action: 'register'
|
|
@@ -1,71 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("react");
|
|
4
|
-
|
|
5
4
|
require("@testing-library/jest-dom");
|
|
6
|
-
|
|
7
5
|
var _react2 = require("@testing-library/react");
|
|
8
|
-
|
|
9
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
10
|
-
|
|
11
7
|
var _Registry = _interopRequireDefault(require("../Registry"));
|
|
12
|
-
|
|
13
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
|
|
15
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
|
-
|
|
17
10
|
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; }
|
|
18
|
-
|
|
19
11
|
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; }
|
|
20
|
-
|
|
21
12
|
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; }
|
|
22
|
-
|
|
23
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
24
|
-
|
|
25
14
|
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); } }
|
|
26
|
-
|
|
27
15
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
28
|
-
|
|
29
16
|
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); }
|
|
30
|
-
|
|
31
17
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
32
|
-
|
|
33
18
|
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); }; }
|
|
34
|
-
|
|
35
19
|
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); }
|
|
36
|
-
|
|
37
20
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
38
|
-
|
|
39
21
|
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; } }
|
|
40
|
-
|
|
41
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
42
|
-
|
|
43
23
|
var SomeContext = /*#__PURE__*/(0, _react.createContext)();
|
|
44
24
|
describe('Registry', function () {
|
|
45
25
|
var NotifiesTree = /*#__PURE__*/function (_Component) {
|
|
46
26
|
_inherits(NotifiesTree, _Component);
|
|
47
|
-
|
|
48
27
|
var _super = _createSuper(NotifiesTree);
|
|
49
|
-
|
|
50
28
|
function NotifiesTree() {
|
|
51
29
|
var _this;
|
|
52
|
-
|
|
53
30
|
_classCallCheck(this, NotifiesTree);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
_this = _super.call(this);
|
|
32
|
+
_this.handleNotify = function (_ref) {
|
|
33
|
+
var action = _ref.action;
|
|
34
|
+
if (action === 'update') {
|
|
35
|
+
_this.registry.parent = _this.context;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
62
38
|
_this.handleClick = function () {
|
|
63
|
-
_this.registry.notify({
|
|
39
|
+
_this.registry.notify({
|
|
40
|
+
action: 'notify'
|
|
41
|
+
});
|
|
64
42
|
};
|
|
65
|
-
|
|
43
|
+
_this.registry = _Registry["default"].create(_this.handleNotify);
|
|
66
44
|
return _this;
|
|
67
45
|
}
|
|
68
|
-
|
|
69
46
|
_createClass(NotifiesTree, [{
|
|
70
47
|
key: "componentDidMount",
|
|
71
48
|
value: function componentDidMount() {
|
|
@@ -83,43 +60,35 @@ describe('Registry', function () {
|
|
|
83
60
|
});
|
|
84
61
|
}
|
|
85
62
|
}]);
|
|
86
|
-
|
|
87
63
|
return NotifiesTree;
|
|
88
64
|
}(_react.Component);
|
|
89
|
-
|
|
90
65
|
NotifiesTree.contextType = SomeContext;
|
|
91
|
-
|
|
92
66
|
var HandlesNotification = /*#__PURE__*/function (_Component2) {
|
|
93
67
|
_inherits(HandlesNotification, _Component2);
|
|
94
|
-
|
|
95
68
|
var _super2 = _createSuper(HandlesNotification);
|
|
96
|
-
|
|
97
69
|
function HandlesNotification() {
|
|
98
70
|
var _this2;
|
|
99
|
-
|
|
100
71
|
_classCallCheck(this, HandlesNotification);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
args[_key2] = arguments[_key2];
|
|
72
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
73
|
+
args[_key] = arguments[_key];
|
|
104
74
|
}
|
|
105
|
-
|
|
106
75
|
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
107
76
|
_this2.state = {
|
|
108
77
|
number: 0
|
|
109
78
|
};
|
|
110
|
-
|
|
111
79
|
_this2.handleResize = function () {
|
|
112
80
|
_this2.setState(function (prevState) {
|
|
113
81
|
var number = prevState.number + 1;
|
|
82
|
+
_this2.registry.notify({
|
|
83
|
+
action: 'update'
|
|
84
|
+
});
|
|
114
85
|
return {
|
|
115
86
|
number: number
|
|
116
87
|
};
|
|
117
88
|
});
|
|
118
89
|
};
|
|
119
|
-
|
|
120
90
|
return _this2;
|
|
121
91
|
}
|
|
122
|
-
|
|
123
92
|
_createClass(HandlesNotification, [{
|
|
124
93
|
key: "componentDidMount",
|
|
125
94
|
value: function componentDidMount() {
|
|
@@ -142,10 +111,8 @@ describe('Registry', function () {
|
|
|
142
111
|
}));
|
|
143
112
|
}
|
|
144
113
|
}]);
|
|
145
|
-
|
|
146
114
|
return HandlesNotification;
|
|
147
115
|
}(_react.Component);
|
|
148
|
-
|
|
149
116
|
HandlesNotification.contextType = SomeContext;
|
|
150
117
|
test('should increment child on click', function () {
|
|
151
118
|
(0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
@@ -154,13 +121,9 @@ describe('Registry', function () {
|
|
|
154
121
|
"data-testid": "a"
|
|
155
122
|
})
|
|
156
123
|
}));
|
|
157
|
-
|
|
158
124
|
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
159
|
-
|
|
160
125
|
var expected = '1';
|
|
161
|
-
|
|
162
126
|
var child = _react2.screen.getByTestId('a');
|
|
163
|
-
|
|
164
127
|
expect(child).toHaveTextContent(expected);
|
|
165
128
|
});
|
|
166
129
|
test('should increment both children on top click', function () {
|
|
@@ -175,15 +138,10 @@ describe('Registry', function () {
|
|
|
175
138
|
})
|
|
176
139
|
})]
|
|
177
140
|
}));
|
|
178
|
-
|
|
179
141
|
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
180
|
-
|
|
181
142
|
var expected = '1';
|
|
182
|
-
|
|
183
143
|
var childA = _react2.screen.getByTestId('a');
|
|
184
|
-
|
|
185
144
|
var childB = _react2.screen.getByTestId('b');
|
|
186
|
-
|
|
187
145
|
expect(childA).toHaveTextContent(expected);
|
|
188
146
|
expect(childB).toHaveTextContent(expected);
|
|
189
147
|
});
|
|
@@ -199,46 +157,36 @@ describe('Registry', function () {
|
|
|
199
157
|
})
|
|
200
158
|
})]
|
|
201
159
|
}));
|
|
202
|
-
|
|
203
160
|
_userEvent["default"].click(_react2.screen.getByTestId('b-btn'));
|
|
204
|
-
|
|
205
161
|
var expectedA = '0';
|
|
206
162
|
var expectedB = '1';
|
|
207
|
-
|
|
208
163
|
var childA = _react2.screen.getByTestId('a');
|
|
209
|
-
|
|
210
164
|
var childB = _react2.screen.getByTestId('b');
|
|
211
|
-
|
|
212
165
|
expect(childA).toHaveTextContent(expectedA);
|
|
213
166
|
expect(childB).toHaveTextContent(expectedB);
|
|
214
167
|
});
|
|
215
168
|
test('should support removing children without error', function () {
|
|
216
169
|
var _render = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
_userEvent["default"].click(_react2.screen.getByTestId('a-btn')); // changing children should be safe and not throw errors when notifying instances
|
|
227
|
-
|
|
170
|
+
"data-testid": "a-btn",
|
|
171
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
172
|
+
"data-testid": "a"
|
|
173
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
174
|
+
"data-testid": "b"
|
|
175
|
+
})]
|
|
176
|
+
})),
|
|
177
|
+
rerender = _render.rerender;
|
|
178
|
+
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
228
179
|
|
|
180
|
+
// changing children should be safe and not throw errors when notifying instances
|
|
229
181
|
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
230
182
|
"data-testid": "a-btn",
|
|
231
183
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
232
184
|
"data-testid": "c"
|
|
233
185
|
})
|
|
234
186
|
}));
|
|
235
|
-
|
|
236
187
|
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
237
|
-
|
|
238
188
|
var expectedC = '1';
|
|
239
|
-
|
|
240
189
|
var childC = _react2.screen.getByTestId('c');
|
|
241
|
-
|
|
242
190
|
expect(childC).toHaveTextContent(expectedC);
|
|
243
191
|
});
|
|
244
192
|
});
|
|
@@ -4,63 +4,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deprecate = exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Provides the `deprecate` method
|
|
10
9
|
*
|
|
11
10
|
* @module core/internal/deprecate
|
|
12
11
|
* @private
|
|
13
12
|
*/
|
|
13
|
+
|
|
14
14
|
// Utility method to format deprecate message
|
|
15
15
|
var formatMsg = function formatMsg(_ref) {
|
|
16
16
|
var message = _ref.message,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
name = _ref.name,
|
|
18
|
+
until = _ref.until,
|
|
19
|
+
replacedBy = _ref.replacedBy,
|
|
20
|
+
since = _ref.since;
|
|
21
21
|
var msg = 'DEPRECATED:';
|
|
22
|
-
|
|
23
22
|
if (name) {
|
|
24
23
|
msg += " ".concat(name);
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
if (since) {
|
|
28
26
|
msg += " since ".concat(since);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
if (until) {
|
|
32
29
|
if (name || since) {
|
|
33
30
|
msg += '.';
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
msg += " Will be removed in ".concat(until);
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
if (replacedBy) {
|
|
40
35
|
if (name || since || until) {
|
|
41
36
|
msg += '.';
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
msg += " Replaced by ".concat(replacedBy);
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
if (name || since || until || replacedBy) {
|
|
48
41
|
msg += '.';
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
if (message) {
|
|
52
44
|
msg += " ".concat(message, ".");
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
return msg;
|
|
56
|
-
};
|
|
57
|
-
|
|
47
|
+
};
|
|
58
48
|
|
|
49
|
+
// Utility method for console warning
|
|
59
50
|
var warn = function warn(msg) {
|
|
60
51
|
if (typeof console !== 'undefined') {
|
|
61
52
|
console.warn(msg); // eslint-disable-line no-console
|
|
62
53
|
}
|
|
63
54
|
};
|
|
55
|
+
|
|
64
56
|
/**
|
|
65
57
|
* Marks a function, component or property (via `propTypes`) as deprecated. Deprecated items will
|
|
66
58
|
* log a message on first invocation. Can also be used 'stand-alone' to issue a deprecation warning.
|
|
@@ -81,8 +73,6 @@ var warn = function warn(msg) {
|
|
|
81
73
|
* @memberof core/internal/deprecate
|
|
82
74
|
* @private
|
|
83
75
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
76
|
var deprecate = function deprecate(thing, config) {
|
|
87
77
|
if (process.env.NODE_ENV !== "production") {
|
|
88
78
|
if (!config) {
|
|
@@ -92,25 +82,22 @@ var deprecate = function deprecate(thing, config) {
|
|
|
92
82
|
return thing;
|
|
93
83
|
} else {
|
|
94
84
|
var displayed, _msg;
|
|
95
|
-
|
|
96
85
|
return function () {
|
|
97
86
|
if (!displayed || config.alwaysWarn) {
|
|
98
87
|
if (!_msg) {
|
|
99
88
|
_msg = formatMsg(config);
|
|
100
89
|
}
|
|
101
|
-
|
|
102
90
|
warn(_msg);
|
|
103
91
|
displayed = true;
|
|
104
92
|
}
|
|
105
|
-
|
|
106
93
|
return thing.apply(void 0, arguments);
|
|
107
94
|
};
|
|
108
95
|
}
|
|
109
96
|
} else {
|
|
97
|
+
/* istanbul ignore next */
|
|
110
98
|
return thing;
|
|
111
99
|
}
|
|
112
100
|
};
|
|
113
|
-
|
|
114
101
|
exports.deprecate = deprecate;
|
|
115
102
|
var _default = deprecate;
|
|
116
103
|
exports["default"] = _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _deprecate = _interopRequireDefault(require("../deprecate"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
5
|
+
describe('deprecate', function () {
|
|
6
|
+
var Thing = function Thing() {
|
|
7
|
+
return 'return';
|
|
8
|
+
};
|
|
9
|
+
var config = {
|
|
10
|
+
name: 'DeprecatedThing',
|
|
11
|
+
message: 'No more information',
|
|
12
|
+
since: '0.0.0',
|
|
13
|
+
until: '0.0.1',
|
|
14
|
+
replacedBy: 'ValidThing',
|
|
15
|
+
alwaysWarn: true
|
|
16
|
+
};
|
|
17
|
+
var expectedMessage = 'DEPRECATED: DeprecatedThing since 0.0.0. Will be removed in 0.0.1. Replaced by ValidThing. No more information.';
|
|
18
|
+
var consoleWarnMock = null;
|
|
19
|
+
beforeEach(function () {
|
|
20
|
+
consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
21
|
+
});
|
|
22
|
+
afterEach(function () {
|
|
23
|
+
consoleWarnMock.mockRestore();
|
|
24
|
+
});
|
|
25
|
+
test('should call console.warn with a warning message for deprecated function', function () {
|
|
26
|
+
var WarningThing = (0, _deprecate["default"])(Thing, config);
|
|
27
|
+
var expected = Thing();
|
|
28
|
+
var actual = WarningThing();
|
|
29
|
+
expect(actual).toBe(expected);
|
|
30
|
+
expect(consoleWarnMock).toHaveBeenCalledWith(expect.stringContaining(expectedMessage));
|
|
31
|
+
});
|
|
32
|
+
test('should call console.warn with a warning message for stand-alone usage', function () {
|
|
33
|
+
var expected = config;
|
|
34
|
+
var actual = (0, _deprecate["default"])(config);
|
|
35
|
+
expect(actual).toBe(expected);
|
|
36
|
+
expect(consoleWarnMock).toHaveBeenCalledWith(expect.stringContaining(expectedMessage));
|
|
37
|
+
});
|
|
38
|
+
});
|