@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
package/kind/kind.js CHANGED
@@ -1,23 +1,52 @@
1
- /**
2
- * Provides the {@link core/kind.kind} method to create components
3
- *
4
- * @module core/kind
5
- * @exports kind
6
- */
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.kind = exports["default"] = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _useHandlers = _interopRequireDefault(require("../useHandlers"));
11
+
12
+ var _Handlers = _interopRequireDefault(require("../useHandlers/Handlers"));
13
+
14
+ var _computed = _interopRequireDefault(require("./computed"));
15
+
16
+ var _styles = _interopRequireDefault(require("./styles"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ 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); } }
7
23
 
8
- import React from 'react';
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
9
25
 
10
- import useHandlers from '../useHandlers';
11
- import Handlers from '../useHandlers/Handlers';
26
+ 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); }
12
27
 
13
- import computed from './computed';
14
- import styles from './styles';
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ 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); }; }
31
+
32
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ 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; }
41
+
42
+ 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; }
43
+
44
+ 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; }
15
45
 
16
46
  // Because contextType is optional and hooks must be called in the same order, we need a fallback
17
47
  // context when none is specified. This likely has some overhead so we may want to deprecate and
18
48
  // remove contextType support for 4.0 since the context APIs have improved since this was added.
19
- const NoContext = React.createContext(null);
20
-
49
+ var NoContext = /*#__PURE__*/_react["default"].createContext(null);
21
50
  /**
22
51
  * @callback RenderFunction
23
52
  * @memberof core/kind
@@ -125,106 +154,113 @@ const NoContext = React.createContext(null);
125
154
  * @see {@link core/handle}
126
155
  * @public
127
156
  */
128
- const kind = (config) => {
129
- const {
130
- computed: cfgComputed,
131
- contextType = NoContext,
132
- defaultProps,
133
- functional,
134
- handlers,
135
- name,
136
- propTypes, // eslint-disable-line react/forbid-foreign-prop-types
137
- render,
138
- styles: cfgStyles
139
- } = config;
140
-
141
- const renderStyles = cfgStyles ? styles(cfgStyles) : false;
142
- const renderComputed = cfgComputed ? computed(cfgComputed) : false;
143
- const renderKind = (props, context) => {
144
- if (renderStyles) props = renderStyles(props, context);
145
- if (renderComputed) props = renderComputed(props, context);
146
-
147
- return render(props, context);
148
- };
149
-
150
- let Component;
151
-
152
- // In 4.x, this branch will become the only supported version and the class branch will be
153
- // removed.
154
- if (functional) {
155
- Component = function (props) {
156
- const ctx = React.useContext(contextType);
157
- const boundHandlers = useHandlers(handlers, props, ctx);
158
-
159
- const merged = {
160
- ...props,
161
- ...boundHandlers
162
- };
163
-
164
- return renderKind(merged, ctx);
165
- };
166
- } else {
167
- // eslint-disable-next-line enact/display-name
168
- Component = class extends React.Component {
169
- static contextType = contextType;
170
-
171
- constructor () {
172
- super();
173
-
174
- this.handlers = new Handlers(handlers);
175
- }
176
-
177
- render () {
178
- this.handlers.setContext(this.props, this.context);
179
-
180
- const merged = {
181
- ...this.props,
182
- ...this.handlers.handlers
183
- };
184
-
185
- return renderKind(merged, this.context);
186
- }
187
- };
188
- }
189
-
190
- if (name) Component.displayName = name;
191
- if (propTypes) Component.propTypes = propTypes;
192
- if (defaultProps) Component.defaultProps = defaultProps;
193
-
194
- // Decorate the Component with the computed property object in DEV for easier testability
195
- if (__DEV__ && cfgComputed) Component.computed = cfgComputed;
196
-
197
- const defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
198
- const handlerKeys = handlers ? Object.keys(handlers) : null;
199
-
200
- Component.inline = (props, context) => {
201
- let updated = {
202
- ...props
203
- };
204
-
205
- if (defaultPropKeys && defaultPropKeys.length > 0) {
206
- defaultPropKeys.forEach(key => {
207
- // eslint-disable-next-line no-undefined
208
- if (props == null || props[key] === undefined) {
209
- updated[key] = defaultProps[key];
210
- }
211
- });
212
- }
213
-
214
- if (handlerKeys && handlerKeys.length > 0) {
215
- // generate a handler with a clone of updated to ensure each handler receives the same
216
- // props without the kind.handlers injected.
217
- updated = handlerKeys.reduce((_props, key) => {
218
- _props[key] = (ev) => handlers[key](ev, updated, context);
219
- return _props;
220
- }, {...updated});
221
- }
222
-
223
- return renderKind(updated, context);
224
- };
225
-
226
- return Component;
157
+
158
+
159
+ var kind = function kind(config) {
160
+ var cfgComputed = config.computed,
161
+ _config$contextType = config.contextType,
162
+ contextType = _config$contextType === void 0 ? NoContext : _config$contextType,
163
+ defaultProps = config.defaultProps,
164
+ functional = config.functional,
165
+ handlers = config.handlers,
166
+ name = config.name,
167
+ propTypes = config.propTypes,
168
+ render = config.render,
169
+ cfgStyles = config.styles;
170
+ var renderStyles = cfgStyles ? (0, _styles["default"])(cfgStyles) : false;
171
+ var renderComputed = cfgComputed ? (0, _computed["default"])(cfgComputed) : false;
172
+
173
+ var renderKind = function renderKind(props, context) {
174
+ if (renderStyles) props = renderStyles(props, context);
175
+ if (renderComputed) props = renderComputed(props, context);
176
+ return render(props, context);
177
+ };
178
+
179
+ var Component; // In 4.x, this branch will become the only supported version and the class branch will be
180
+ // removed.
181
+
182
+ if (functional) {
183
+ Component = function Component(props) {
184
+ var ctx = _react["default"].useContext(contextType);
185
+
186
+ var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
187
+
188
+ var merged = _objectSpread(_objectSpread({}, props), boundHandlers);
189
+
190
+ return renderKind(merged, ctx);
191
+ };
192
+ } else {
193
+ var _class, _temp;
194
+
195
+ // eslint-disable-next-line enact/display-name
196
+ Component = (_temp = _class = /*#__PURE__*/function (_React$Component) {
197
+ _inherits(Component, _React$Component);
198
+
199
+ var _super = _createSuper(Component);
200
+
201
+ function Component() {
202
+ var _this;
203
+
204
+ _classCallCheck(this, Component);
205
+
206
+ _this = _super.call(this);
207
+ _this.handlers = new _Handlers["default"](handlers);
208
+ return _this;
209
+ }
210
+
211
+ _createClass(Component, [{
212
+ key: "render",
213
+ value: function render() {
214
+ this.handlers.setContext(this.props, this.context);
215
+
216
+ var merged = _objectSpread(_objectSpread({}, this.props), this.handlers.handlers);
217
+
218
+ return renderKind(merged, this.context);
219
+ }
220
+ }]);
221
+
222
+ return Component;
223
+ }(_react["default"].Component), _class.contextType = contextType, _temp);
224
+ }
225
+
226
+ if (name) Component.displayName = name;
227
+ if (propTypes) Component.propTypes = propTypes;
228
+ if (defaultProps) Component.defaultProps = defaultProps; // Decorate the Component with the computed property object in DEV for easier testability
229
+
230
+ if (process.env.NODE_ENV !== "production" && cfgComputed) Component.computed = cfgComputed;
231
+ var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
232
+ var handlerKeys = handlers ? Object.keys(handlers) : null;
233
+
234
+ Component.inline = function (props, context) {
235
+ var updated = _objectSpread({}, props);
236
+
237
+ if (defaultPropKeys && defaultPropKeys.length > 0) {
238
+ defaultPropKeys.forEach(function (key) {
239
+ // eslint-disable-next-line no-undefined
240
+ if (props == null || props[key] === undefined) {
241
+ updated[key] = defaultProps[key];
242
+ }
243
+ });
244
+ }
245
+
246
+ if (handlerKeys && handlerKeys.length > 0) {
247
+ // generate a handler with a clone of updated to ensure each handler receives the same
248
+ // props without the kind.handlers injected.
249
+ updated = handlerKeys.reduce(function (_props, key) {
250
+ _props[key] = function (ev) {
251
+ return handlers[key](ev, updated, context);
252
+ };
253
+
254
+ return _props;
255
+ }, _objectSpread({}, updated));
256
+ }
257
+
258
+ return renderKind(updated, context);
259
+ };
260
+
261
+ return Component;
227
262
  };
228
263
 
229
- export default kind;
230
- export {kind};
264
+ exports.kind = kind;
265
+ var _default = kind;
266
+ exports["default"] = _default;
package/kind/styles.js CHANGED
@@ -1,8 +1,17 @@
1
- import classnames from 'classnames/bind';
1
+ "use strict";
2
2
 
3
- import {mergeClassNameMaps} from '../util';
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.styles = exports["default"] = void 0;
4
7
 
5
- import {addInternalProp} from './util';
8
+ var _bind = _interopRequireDefault(require("classnames/bind"));
9
+
10
+ var _util = require("../util");
11
+
12
+ var _util2 = require("./util");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
15
 
7
16
  /**
8
17
  * Merges external and internal CSS classes and style objects. Internal CSS classes can be
@@ -42,49 +51,55 @@ import {addInternalProp} from './util';
42
51
  * `css` merged class name map
43
52
  * @private
44
53
  */
45
- const styles = (cfg, optProps) => {
46
- const {className, css: configCss, prop = 'className', style} = cfg;
47
- let {publicClassNames: allowedClassNames} = cfg;
48
-
49
- if (configCss && allowedClassNames === true) {
50
- allowedClassNames = Object.keys(configCss);
51
- } else if (typeof allowedClassNames === 'string') {
52
- allowedClassNames = allowedClassNames.split(/\s+/);
53
- }
54
-
55
- const renderStyles = (props) => {
56
- let css = configCss;
57
-
58
- if (style) {
59
- props.style = Object.assign({}, style, props.style);
60
- }
61
-
62
- // if the props includes a css map, merge them together now
63
- if (css && allowedClassNames && props.css) {
64
- css = mergeClassNameMaps(css, props.css, allowedClassNames);
65
- }
66
-
67
- const cn = css ? classnames.bind(css) : classnames;
68
- const joinedClassName = props[prop] = classnames(
69
- className ? cn(className.split(' ')) : null,
70
- props.className
71
- );
72
-
73
- addInternalProp(props, 'css', css);
74
- addInternalProp(props, 'styler', {
75
- join: cn,
76
- append: (...args) => cn(joinedClassName, ...args)
77
- });
78
-
79
- return props;
80
- };
81
-
82
- if (optProps) {
83
- return renderStyles(optProps);
84
- }
85
-
86
- return renderStyles;
54
+ var styles = function styles(cfg, optProps) {
55
+ var className = cfg.className,
56
+ configCss = cfg.css,
57
+ _cfg$prop = cfg.prop,
58
+ prop = _cfg$prop === void 0 ? 'className' : _cfg$prop,
59
+ style = cfg.style;
60
+ var allowedClassNames = cfg.publicClassNames;
61
+
62
+ if (configCss && allowedClassNames === true) {
63
+ allowedClassNames = Object.keys(configCss);
64
+ } else if (typeof allowedClassNames === 'string') {
65
+ allowedClassNames = allowedClassNames.split(/\s+/);
66
+ }
67
+
68
+ var renderStyles = function renderStyles(props) {
69
+ var css = configCss;
70
+
71
+ if (style) {
72
+ props.style = Object.assign({}, style, props.style);
73
+ } // if the props includes a css map, merge them together now
74
+
75
+
76
+ if (css && allowedClassNames && props.css) {
77
+ css = (0, _util.mergeClassNameMaps)(css, props.css, allowedClassNames);
78
+ }
79
+
80
+ var cn = css ? _bind["default"].bind(css) : _bind["default"];
81
+ var joinedClassName = props[prop] = (0, _bind["default"])(className ? cn(className.split(' ')) : null, props.className);
82
+ (0, _util2.addInternalProp)(props, 'css', css);
83
+ (0, _util2.addInternalProp)(props, 'styler', {
84
+ join: cn,
85
+ append: function append() {
86
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
87
+ args[_key] = arguments[_key];
88
+ }
89
+
90
+ return cn.apply(void 0, [joinedClassName].concat(args));
91
+ }
92
+ });
93
+ return props;
94
+ };
95
+
96
+ if (optProps) {
97
+ return renderStyles(optProps);
98
+ }
99
+
100
+ return renderStyles;
87
101
  };
88
102
 
89
- export default styles;
90
- export {styles};
103
+ exports.styles = styles;
104
+ var _default = styles;
105
+ exports["default"] = _default;
@@ -1,86 +1,87 @@
1
- import computed from '../computed';
2
-
3
- describe('computed', () => {
4
-
5
- const exampleCfg = {
6
- sum: ({x, y, z}) => x + y + z,
7
- product: ({x, y, z}) => x * y * z
8
- };
9
-
10
- const exampleProps = {
11
- x: 2,
12
- y: 3,
13
- z: 4
14
- };
15
-
16
- test('should add new props to updated object', () => {
17
- const props = {
18
- value: true
19
- };
20
- const cfg = {
21
- count: () => 1
22
- };
23
-
24
- const updated = computed(cfg, props);
25
-
26
- const expected = 1;
27
- const actual = updated.count;
28
-
29
- expect(actual).toBe(expected);
30
- });
31
-
32
- test('should overwrite properties with computed values', () => {
33
- const props = {
34
- value: true,
35
- count: 2
36
- };
37
- const cfg = {
38
- count: () => 1
39
- };
40
-
41
- const updated = computed(cfg, props);
42
-
43
- const expected = 1;
44
- const actual = updated.count;
45
-
46
- expect(actual).toBe(expected);
47
- });
48
-
49
- test(
50
- 'should not leak updated prop values into other computed props',
51
- () => {
52
- const props = {
53
- count: 1
54
- };
55
- const cfg = {
56
- value: ({count}) => count + 5,
57
- count: ({count}) => count + 1
58
- };
59
-
60
- const updated = computed(cfg, props);
61
-
62
- const expected = 6;
63
- const actual = updated.value;
64
- expect(actual).toBe(expected);
65
- }
66
- );
67
-
68
- test('should work with its documented example - sum', () => {
69
- const updated = computed(exampleCfg, exampleProps);
70
-
71
- const expected = 9;
72
- const actual = updated.sum;
73
-
74
- expect(actual).toBe(expected);
75
- });
76
-
77
- test('should work with its documented example - product', () => {
78
- const updated = computed(exampleCfg, exampleProps);
79
-
80
- const expected = 24;
81
- const actual = updated.product;
82
-
83
- expect(actual).toBe(expected);
84
- });
85
-
86
- });
1
+ "use strict";
2
+
3
+ var _computed = _interopRequireDefault(require("../computed"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
+
7
+ describe('computed', function () {
8
+ var exampleCfg = {
9
+ sum: function sum(_ref) {
10
+ var x = _ref.x,
11
+ y = _ref.y,
12
+ z = _ref.z;
13
+ return x + y + z;
14
+ },
15
+ product: function product(_ref2) {
16
+ var x = _ref2.x,
17
+ y = _ref2.y,
18
+ z = _ref2.z;
19
+ return x * y * z;
20
+ }
21
+ };
22
+ var exampleProps = {
23
+ x: 2,
24
+ y: 3,
25
+ z: 4
26
+ };
27
+ test('should add new props to updated object', function () {
28
+ var props = {
29
+ value: true
30
+ };
31
+ var cfg = {
32
+ count: function count() {
33
+ return 1;
34
+ }
35
+ };
36
+ var updated = (0, _computed["default"])(cfg, props);
37
+ var expected = 1;
38
+ var actual = updated.count;
39
+ expect(actual).toBe(expected);
40
+ });
41
+ test('should overwrite properties with computed values', function () {
42
+ var props = {
43
+ value: true,
44
+ count: 2
45
+ };
46
+ var cfg = {
47
+ count: function count() {
48
+ return 1;
49
+ }
50
+ };
51
+ var updated = (0, _computed["default"])(cfg, props);
52
+ var expected = 1;
53
+ var actual = updated.count;
54
+ expect(actual).toBe(expected);
55
+ });
56
+ test('should not leak updated prop values into other computed props', function () {
57
+ var props = {
58
+ count: 1
59
+ };
60
+ var cfg = {
61
+ value: function value(_ref3) {
62
+ var count = _ref3.count;
63
+ return count + 5;
64
+ },
65
+ count: function count(_ref4) {
66
+ var _count = _ref4.count;
67
+ return _count + 1;
68
+ }
69
+ };
70
+ var updated = (0, _computed["default"])(cfg, props);
71
+ var expected = 6;
72
+ var actual = updated.value;
73
+ expect(actual).toBe(expected);
74
+ });
75
+ test('should work with its documented example - sum', function () {
76
+ var updated = (0, _computed["default"])(exampleCfg, exampleProps);
77
+ var expected = 9;
78
+ var actual = updated.sum;
79
+ expect(actual).toBe(expected);
80
+ });
81
+ test('should work with its documented example - product', function () {
82
+ var updated = (0, _computed["default"])(exampleCfg, exampleProps);
83
+ var expected = 24;
84
+ var actual = updated.product;
85
+ expect(actual).toBe(expected);
86
+ });
87
+ });