@dr.pogodin/react-utils 1.15.7 → 1.16.2

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 (41) hide show
  1. package/build/development/client/index.js +11 -5
  2. package/build/development/client/index.js.map +1 -1
  3. package/build/development/server/renderer.js +78 -36
  4. package/build/development/server/renderer.js.map +1 -1
  5. package/build/development/shared/components/CodeSplit/index.js +108 -9
  6. package/build/development/shared/components/CodeSplit/index.js.map +1 -1
  7. package/build/development/shared/components/Modal/index.js +2 -3
  8. package/build/development/shared/components/Modal/index.js.map +1 -1
  9. package/build/development/shared/utils/jest.js +14 -77
  10. package/build/development/shared/utils/jest.js.map +1 -1
  11. package/build/development/shared/utils/splitComponent.js +12 -13
  12. package/build/development/shared/utils/splitComponent.js.map +1 -1
  13. package/build/development/shared/utils/time.js +11 -22
  14. package/build/development/shared/utils/time.js.map +1 -1
  15. package/build/development/web.bundle.js +21 -41
  16. package/build/production/client/index.js +3 -2
  17. package/build/production/client/index.js.map +1 -1
  18. package/build/production/server/renderer.js +26 -13
  19. package/build/production/server/renderer.js.map +1 -1
  20. package/build/production/shared/components/CodeSplit/index.js +8 -5
  21. package/build/production/shared/components/CodeSplit/index.js.map +1 -1
  22. package/build/production/shared/components/Modal/index.js +2 -3
  23. package/build/production/shared/components/Modal/index.js.map +1 -1
  24. package/build/production/shared/utils/jest.js +6 -28
  25. package/build/production/shared/utils/jest.js.map +1 -1
  26. package/build/production/shared/utils/splitComponent.js +6 -7
  27. package/build/production/shared/utils/splitComponent.js.map +1 -1
  28. package/build/production/shared/utils/time.js +6 -20
  29. package/build/production/shared/utils/time.js.map +1 -1
  30. package/build/production/web.bundle.js +1 -1
  31. package/build/production/web.bundle.js.LICENSE.txt +2 -7
  32. package/build/production/web.bundle.js.map +1 -1
  33. package/package.json +25 -25
  34. package/build/development/shared/components/CodeSplit/ClientSide.js +0 -155
  35. package/build/development/shared/components/CodeSplit/ClientSide.js.map +0 -1
  36. package/build/development/shared/components/CodeSplit/ServerSide.js +0 -111
  37. package/build/development/shared/components/CodeSplit/ServerSide.js.map +0 -1
  38. package/build/production/shared/components/CodeSplit/ClientSide.js +0 -21
  39. package/build/production/shared/components/CodeSplit/ClientSide.js.map +0 -1
  40. package/build/production/shared/components/CodeSplit/ServerSide.js +0 -18
  41. package/build/production/shared/components/CodeSplit/ServerSide.js.map +0 -1
@@ -11,28 +11,20 @@ Object.defineProperty(exports, "act", {
11
11
  return _testUtils.act;
12
12
  }
13
13
  });
14
- exports.findInDomByClass = findInDomByClass;
15
- exports.findInDomManyByClass = findInDomManyByClass;
16
14
  exports.getMockUuid = getMockUuid;
17
15
  exports.mockClientSide = mockClientSide;
18
16
  exports.mockTimer = mockTimer;
19
17
  exports.mount = mount;
20
18
  exports.render = render;
21
- exports.renderDom = renderDom;
22
19
  exports.shallowRender = shallowRender;
23
20
  exports.shallowSnapshot = shallowSnapshot;
24
21
  exports.simulate = void 0;
25
22
  exports.snapshot = snapshot;
26
23
  exports.unmockClientSide = unmockClientSide;
27
- exports.unmount = unmount;
28
-
29
- var _react = require("react");
30
24
 
31
25
  var _mockdate = _interopRequireDefault(require("mockdate"));
32
26
 
33
- var _propTypes = _interopRequireDefault(require("prop-types"));
34
-
35
- var _reactDom = require("react-dom");
27
+ var _client = require("react-dom/client");
36
28
 
37
29
  var _testUtils = _interopRequireWildcard(require("react-dom/test-utils"));
38
30
 
@@ -40,8 +32,6 @@ var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
40
32
 
41
33
  var _shallow = _interopRequireDefault(require("react-test-renderer/shallow"));
42
34
 
43
- var _jsxRuntime = require("react/jsx-runtime");
44
-
45
35
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
46
36
 
47
37
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -59,6 +49,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
59
49
  * from `react-dom/test-utils`.
60
50
  * @param {function} action
61
51
  */
52
+ global.IS_REACT_ACT_ENVIRONMENT = true;
62
53
  const originalProcessVersions = process.versions;
63
54
  /**
64
55
  * Tricks **react-utils** into thinking the test is running within client-side
@@ -109,52 +100,29 @@ async function mockTimer(time) {
109
100
  /**
110
101
  * Mounts `scene` to the DOM, and returns the root scene element.
111
102
  * @param {React.ReactNode} scene
112
- * @return {HTMLElement}
103
+ * @return {HTMLElement} Created container DOM element with destroy() function
104
+ * attached.
113
105
  */
114
106
 
115
107
 
116
108
  function mount(scene) {
109
+ let root;
117
110
  const res = document.createElement('div');
118
111
  document.body.appendChild(res);
119
- (0, _reactDom.render)(scene, res);
120
- return res;
121
- }
122
- /**
123
- * Unmounts `scene` from the DOM.
124
- * @param {HTMLElement} scene
125
- */
126
112
 
113
+ res.destroy = () => {
114
+ (0, _testUtils.act)(() => root.unmount());
115
+ res.remove();
116
+ };
127
117
 
128
- function unmount(scene) {
129
- (0, _reactDom.unmountComponentAtNode)(scene);
130
- scene.remove();
118
+ (0, _testUtils.act)(() => {
119
+ root = (0, _client.createRoot)(res);
120
+ root.render(scene);
121
+ });
122
+ return res;
131
123
  }
132
124
  /* OLD STUFF BELOW THIS MARK */
133
125
 
134
- /**
135
- * Just an alias for
136
- * [findRenderedDOMComponentWithClass(..)](https://reactjs.org/docs/test-utils.html#findrendereddomcomponentwithclass).
137
- * @param {object} dom
138
- * @param {string} className
139
- * @return {object}
140
- */
141
-
142
-
143
- function findInDomByClass(dom, className) {
144
- return _testUtils.default.findRenderedDOMComponentWithClass(dom, className);
145
- }
146
- /**
147
- * Just an alias for
148
- * [scryRenderedDOMComponentsWithClass(..)](https://reactjs.org/docs/test-utils.html#scryrendereddomcomponentswithclass).
149
- * @param {object} dom
150
- * @param {stirng} className
151
- * @return {array}
152
- */
153
-
154
-
155
- function findInDomManyByClass(dom, className) {
156
- return _testUtils.default.scryRenderedDOMComponentsWithClass(dom, className);
157
- }
158
126
  /**
159
127
  * Renders provided ReactJS component into JSON representation of the component
160
128
  * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).
@@ -168,37 +136,6 @@ function findInDomManyByClass(dom, className) {
168
136
 
169
137
  function render(component) {
170
138
  return _reactTestRenderer.default.create(component).toJSON();
171
- } // The Wrapper is necessary for the "renderDom(..)" function, because
172
- // the "renderIntoDocument(..)" function from "react-dom/test-utils" works
173
- // only with state components, so we have to wrap our ReactJS components into
174
- // such Wrapper.
175
-
176
-
177
- class Wrapper extends _react.Component {
178
- componentDidMount() {}
179
-
180
- render() {
181
- const {
182
- children
183
- } = this.props;
184
- return children;
185
- }
186
-
187
- }
188
-
189
- Wrapper.propTypes = {
190
- children: _propTypes.default.node.isRequired
191
- };
192
- /**
193
- * Renders given ReactJS component into DOM, using `react-dom/test-utils`.
194
- * @param {object} component ReactJS component to render.
195
- * @return {object} Rendered DOM.
196
- */
197
-
198
- function renderDom(component) {
199
- return _testUtils.default.renderIntoDocument( /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapper, {
200
- children: component
201
- }));
202
139
  }
203
140
  /**
204
141
  * Generates a shallow render of given ReactJS component, using
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"names":["originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","set","Date","now","jest","advanceTimersByTime","mount","scene","res","document","createElement","body","appendChild","unmount","remove","findInDomByClass","dom","className","TU","findRenderedDOMComponentWithClass","findInDomManyByClass","scryRenderedDOMComponentsWithClass","render","component","Renderer","create","toJSON","Wrapper","Component","componentDidMount","children","props","propTypes","PT","node","isRequired","renderDom","renderIntoDocument","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","Simulate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;AAZA;;AACA;;AASA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AAGA,MAAMA,uBAAuB,GAAGC,OAAO,CAACC,QAAxC;AAEA;AACA;AACA;AACA;;AACO,SAASC,cAAT,GAA0B;AAC/BC,EAAAA,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,EAA+B,UAA/B,EAA2C;AAAEK,IAAAA,KAAK,EAAE;AAAT,GAA3C;AACD;AAED;AACA;AACA;;;AACO,SAASC,gBAAT,GAA4B;AACjCH,EAAAA,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,EAA+B,UAA/B,EAA2C;AACzCK,IAAAA,KAAK,EAAEN,uBADkC;AAEzCQ,IAAAA,QAAQ,EAAE;AAF+B,GAA3C;AAID;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAqBC,IAAI,GAAG,CAA5B,EAA+B;AACpC,QAAMC,CAAC,GAAGD,IAAI,CAACE,QAAL,CAAc,EAAd,EAAkBC,QAAlB,CAA2B,EAA3B,EAA+B,GAA/B,CAAV;AACA,SAAQ,GAAEF,CAAC,CAACG,KAAF,CAAQ,CAAR,EAAW,CAAX,CAAc,IAAGH,C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slint-disable import/no-extraneous-dependencies */\n\nimport { Component } from 'react';\n\nimport mockdate from 'mockdate';\nimport PT from 'prop-types';\nimport { render as newRender, unmountComponentAtNode } from 'react-dom';\nimport TU from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act } from 'react-dom/test-utils';\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement}\n */\nexport function mount(scene) {\n const res = document.createElement('div');\n document.body.appendChild(res);\n newRender(scene, res);\n return res;\n}\n\n/**\n * Unmounts `scene` from the DOM.\n * @param {HTMLElement} scene\n */\nexport function unmount(scene) {\n unmountComponentAtNode(scene);\n scene.remove();\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Just an alias for\n * [findRenderedDOMComponentWithClass(..)](https://reactjs.org/docs/test-utils.html#findrendereddomcomponentwithclass).\n * @param {object} dom\n * @param {string} className\n * @return {object}\n */\nexport function findInDomByClass(dom, className) {\n return TU.findRenderedDOMComponentWithClass(dom, className);\n}\n\n/**\n * Just an alias for\n * [scryRenderedDOMComponentsWithClass(..)](https://reactjs.org/docs/test-utils.html#scryrendereddomcomponentswithclass).\n * @param {object} dom\n * @param {stirng} className\n * @return {array}\n */\nexport function findInDomManyByClass(dom, className) {\n return TU.scryRenderedDOMComponentsWithClass(dom, className);\n}\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n// The Wrapper is necessary for the \"renderDom(..)\" function, because\n// the \"renderIntoDocument(..)\" function from \"react-dom/test-utils\" works\n// only with state components, so we have to wrap our ReactJS components into\n// such Wrapper.\nclass Wrapper extends Component {\n componentDidMount() {}\n\n render() {\n const { children } = this.props;\n return children;\n }\n}\n\nWrapper.propTypes = {\n children: PT.node.isRequired,\n};\n\n/**\n * Renders given ReactJS component into DOM, using `react-dom/test-utils`.\n * @param {object} component ReactJS component to render.\n * @return {object} Rendered DOM.\n */\nexport function renderDom(component) {\n return TU.renderIntoDocument((\n <Wrapper>\n {component}\n </Wrapper>\n ));\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"file":"jest.js"}
1
+ {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"names":["global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","set","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","unmount","remove","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AAGA;;AACA;;;;;;AATA;;AACA;;AAMA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AAGAA,MAAM,CAACC,wBAAP,GAAkC,IAAlC;AAEA,MAAMC,uBAAuB,GAAGC,OAAO,CAACC,QAAxC;AAEA;AACA;AACA;AACA;;AACO,SAASC,cAAT,GAA0B;AAC/BC,EAAAA,MAAM,CAACC,cAAP,CAAsBJ,OAAtB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AAI,CAACO,OAAL,EAAV;AACAN,IAAAA,GAAG,CAACO,MAAJ;AACD,GAHD;;AAIA,sBAAI,MAAM;AACRR,IAAAA,IAAI,GAAG,wBAAWC,GAAX,CAAP;AACAD,IAAAA,IAAI,CAACS,MAAL,CAAYV,KAAZ;AACD,GAHD;AAIA,SAAOE,GAAP;AACD;AAED;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASQ,MAAT,CAAgBC,SAAhB,EAA2B;AAChC,SAAOC,2BAASC,MAAT,CAAgBF,SAAhB,EAA2BG,MAA3B,EAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,aAAT,CAAuBJ,SAAvB,EAAkC;AACvC,QAAMK,QAAQ,GAAG,IAAIC,gBAAJ,EAAjB;AACAD,EAAAA,QAAQ,CAACN,MAAT,CAAgBC,SAAhB;AACA,SAAOK,QAAQ,CAACE,eAAT,EAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,eAAT,CAAyBR,SAAzB,EAAoC;AACzC,QAAMT,GAAG,GAAGa,aAAa,CAACJ,SAAD,CAAzB;AACAS,EAAAA,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ;AACA,SAAOnB,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASoB,QAAT,CAAkBX,SAAlB,EAA6B;AAClC,QAAMT,GAAG,GAAGQ,MAAM,CAACC,SAAD,CAAlB;AACAS,EAAAA,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ;AACA,SAAOnB,GAAP;AACD;;AAEM,MAAMqB,QAAQ,GAAGC,mBAAGC,QAApB","sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"file":"jest.js"}
@@ -11,6 +11,8 @@ var _react = require("react");
11
11
 
12
12
  var _CodeSplit = _interopRequireDefault(require("../components/CodeSplit"));
13
13
 
14
+ /* eslint-disable react/jsx-props-no-spreading */
15
+
14
16
  /**
15
17
  * Wraps a regular React component into a "code splitting" component,
16
18
  * i.e. all code used exclusively by that component and its sub-tree
@@ -18,26 +20,23 @@ var _CodeSplit = _interopRequireDefault(require("../components/CodeSplit"));
18
20
  * the client-side.
19
21
  * @param {object} options
20
22
  * @param {string} options.chunkName
21
- * @param {function} options.getClientSide
22
- * @param {React.ElementType} [options.placeholder]
23
- * @param {React.ElementType} [options.serverSide]
24
- * @returns {React.ElementType}
23
+ * @param {function} options.getComponent
24
+ * @param {React.Element} [options.placeholder]
25
+ * @return {React.ElementType}
25
26
  */
26
27
  function splitComponent({
27
28
  chunkName,
28
- getClientSide,
29
- placeholder,
30
- serverSide
29
+ getComponent,
30
+ placeholder
31
31
  }) {
32
32
  // eslint-disable-next-line react/prop-types
33
33
  return ({
34
- children = [],
34
+ children,
35
35
  ...props
36
- } = {}) => /*#__PURE__*/(0, _react.createElement)(_CodeSplit.default, { ...props,
36
+ }) => /*#__PURE__*/(0, _react.createElement)(_CodeSplit.default, { ...props,
37
37
  chunkName,
38
- getClientSide,
39
- placeholder,
40
- serverSide
41
- }, ...children);
38
+ getComponent,
39
+ placeholder
40
+ }, children);
42
41
  }
43
42
  //# sourceMappingURL=splitComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/splitComponent.js"],"names":["splitComponent","chunkName","getClientSide","placeholder","serverSide","children","props","CodeSplit"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwB;AACrCC,EAAAA,SADqC;AAErCC,EAAAA,aAFqC;AAGrCC,EAAAA,WAHqC;AAIrCC,EAAAA;AAJqC,CAAxB,EAKZ;AACD;AACA,SAAO,CAAC;AAAEC,IAAAA,QAAQ,GAAG,EAAb;AAAiB,OAAGC;AAApB,MAA8B,EAA/B,kBAAsC,0BAC3CC,kBAD2C,EAE3C,EACE,GAAGD,KADL;AAEEL,IAAAA,SAFF;AAGEC,IAAAA,aAHF;AAIEC,IAAAA,WAJF;AAKEC,IAAAA;AALF,GAF2C,EAS3C,GAAGC,QATwC,CAA7C;AAWD","sourcesContent":["import { createElement } from 'react';\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getClientSide\n * @param {React.ElementType} [options.placeholder]\n * @param {React.ElementType} [options.serverSide]\n * @returns {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getClientSide,\n placeholder,\n serverSide,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children = [], ...props } = {}) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getClientSide,\n placeholder,\n serverSide,\n },\n ...children,\n );\n}\n"],"file":"splitComponent.js"}
1
+ {"version":3,"sources":["../../../../src/shared/utils/splitComponent.js"],"names":["splitComponent","chunkName","getComponent","placeholder","children","props","CodeSplit"],"mappings":";;;;;;;;;AAEA;;AAEA;;AAJA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwB;AACrCC,EAAAA,SADqC;AAErCC,EAAAA,YAFqC;AAGrCC,EAAAA;AAHqC,CAAxB,EAIZ;AACD;AACA,SAAO,CAAC;AAAEC,IAAAA,QAAF;AAAY,OAAGC;AAAf,GAAD,kBAA4B,0BACjCC,kBADiC,EAEjC,EACE,GAAGD,KADL;AAEEJ,IAAAA,SAFF;AAGEC,IAAAA,YAHF;AAIEC,IAAAA;AAJF,GAFiC,EAQjCC,QARiC,CAAnC;AAUD","sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n\nimport { createElement } from 'react';\n\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getComponent,\n placeholder,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children, ...props }) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getComponent,\n placeholder,\n },\n children,\n );\n}\n"],"file":"splitComponent.js"}
@@ -9,18 +9,7 @@ exports.default = void 0;
9
9
 
10
10
  var _dayjs = _interopRequireDefault(require("dayjs"));
11
11
 
12
- /**
13
- * @category Utilities
14
- * @module time
15
- * @desc
16
- * ```js
17
- * import { time } from '@dr.pogodin/react-utils';
18
- * ```
19
- * Date & time utilities. The `time` export is a convenient alias for
20
- * [dayjs](https://day.js.org/en/) library, _i.e._ you can use `time`
21
- * in all ways you would use `dayjs`. It is further extended with
22
- * the following additional members.
23
- */
12
+ var _Barrier = require("./Barrier");
24
13
 
25
14
  /**
26
15
  * @static
@@ -84,20 +73,20 @@ _dayjs.default.YEAR_MS = 365 * _dayjs.default.DAY_MS;
84
73
 
85
74
  _dayjs.default.now = Date.now;
86
75
  /**
87
- * @static
88
- * @func timer
89
- * @desc Creates a Promise, which resolves after the given timeout.
76
+ * Creates a Promise, which resolves after the given timeout.
90
77
  * @param {number} timeout Timeout [ms].
91
- * @return {Promise} Resolves after the timeout.
92
- * @example
93
- * import { time } from '@dr.pogodin/react-utils';
94
- * time.timer(5000).then(() => console.log('5 seconds have passed'))
78
+ * @return {Barrier} Resolves after the timeout. It has additional
79
+ * .abort() method attached, which cancels the pending timer resolution
80
+ * (without resolving or rejecting the barrier).
95
81
  */
96
82
 
97
83
  _dayjs.default.timer = async function timer(timeout) {
98
- return new Promise(resolve => {
99
- setTimeout(resolve, timeout);
100
- });
84
+ const res = new _Barrier.Barrier();
85
+ const id = setTimeout(res.resolve.bind(res), timeout);
86
+
87
+ res.abort = () => clearTimeout(id);
88
+
89
+ return res;
101
90
  };
102
91
 
103
92
  var _default = _dayjs.default;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/time.js"],"names":["dayjs","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","now","Date","timer","timeout","Promise","resolve","setTimeout"],"mappings":";;;;;;;;;AAaA;;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAA,eAAMC,MAAN,GAAe,IAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,eAAME,MAAN,GAAe,KAAKF,eAAMC,MAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,eAAMG,OAAN,GAAgB,KAAKH,eAAME,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAF,eAAMI,MAAN,GAAe,KAAKJ,eAAMG,OAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAH,eAAMK,OAAN,GAAgB,MAAML,eAAMI,MAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAJ,eAAMM,GAAN,GAAYC,IAAI,CAACD,GAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAN,eAAMQ,KAAN,GAAc,eAAeA,KAAf,CAAqBC,OAArB,EAA8B;AAC1C,SAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC9BC,IAAAA,UAAU,CAACD,OAAD,EAAUF,OAAV,CAAV;AACD,GAFM,CAAP;AAGD,CAJD;;eAMeT,c","sourcesContent":["/**\n * @category Utilities\n * @module time\n * @desc\n * ```js\n * import { time } from '@dr.pogodin/react-utils';\n * ```\n * Date & time utilities. The `time` export is a convenient alias for\n * [dayjs](https://day.js.org/en/) library, _i.e._ you can use `time`\n * in all ways you would use `dayjs`. It is further extended with\n * the following additional members.\n */\n\nimport dayjs from 'dayjs';\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\ndayjs.SEC_MS = 1000;\n\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 &times; `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\ndayjs.MIN_MS = 60 * dayjs.SEC_MS;\n\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 &times; `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\ndayjs.HOUR_MS = 60 * dayjs.MIN_MS;\n\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 &times; `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\ndayjs.DAY_MS = 24 * dayjs.HOUR_MS;\n\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 &times; `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\ndayjs.YEAR_MS = 365 * dayjs.DAY_MS;\n\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\ndayjs.now = Date.now;\n\n/**\n * @static\n * @func timer\n * @desc Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Promise} Resolves after the timeout.\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * time.timer(5000).then(() => console.log('5 seconds have passed'))\n */\ndayjs.timer = async function timer(timeout) {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout);\n });\n};\n\nexport default dayjs;\n"],"file":"time.js"}
1
+ {"version":3,"sources":["../../../../src/shared/utils/time.js"],"names":["dayjs","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","now","Date","timer","timeout","res","Barrier","id","setTimeout","resolve","bind","abort","clearTimeout"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAA,eAAMC,MAAN,GAAe,IAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,eAAME,MAAN,GAAe,KAAKF,eAAMC,MAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAD,eAAMG,OAAN,GAAgB,KAAKH,eAAME,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAF,eAAMI,MAAN,GAAe,KAAKJ,eAAMG,OAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAH,eAAMK,OAAN,GAAgB,MAAML,eAAMI,MAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAJ,eAAMM,GAAN,GAAYC,IAAI,CAACD,GAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAN,eAAMQ,KAAN,GAAc,eAAeA,KAAf,CAAqBC,OAArB,EAA8B;AAC1C,QAAMC,GAAG,GAAG,IAAIC,gBAAJ,EAAZ;AACA,QAAMC,EAAE,GAAGC,UAAU,CAACH,GAAG,CAACI,OAAJ,CAAYC,IAAZ,CAAiBL,GAAjB,CAAD,EAAwBD,OAAxB,CAArB;;AACAC,EAAAA,GAAG,CAACM,KAAJ,GAAY,MAAMC,YAAY,CAACL,EAAD,CAA9B;;AACA,SAAOF,GAAP;AACD,CALD;;eAOeV,c","sourcesContent":["import dayjs from 'dayjs';\nimport { Barrier } from './Barrier';\n\n/**\n * @static\n * @const SEC_MS\n * @desc One second, expressed in milliseconds (equals 1000 ms).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.SEC_MS); // Prints: 1000\n */\ndayjs.SEC_MS = 1000;\n\n/**\n * @static\n * @const MIN_MS\n * @desc One minute, expressed in milliseconds (equals 60 &times; `SEC_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.MIN_MS); // Prints: 60000\n */\ndayjs.MIN_MS = 60 * dayjs.SEC_MS;\n\n/**\n * @static\n * @const HOUR_MS\n * @desc One hour, expressed in milliseconds (equals 60 &times; `MIN_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.HOUR_MS); // Prints: 3600000\n */\ndayjs.HOUR_MS = 60 * dayjs.MIN_MS;\n\n/**\n * @static\n * @const DAY_MS\n * @desc One day, expressed in milliseconds (equals 24 &times; `HOUR_MS`).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.DAY_MS); // Prints: 86400000\n */\ndayjs.DAY_MS = 24 * dayjs.HOUR_MS;\n\n/**\n * @static\n * @const YEAR_MS\n * @desc One year, expressed in milliseconds (equals 365 &times; `DAY_MS`,\n * thus a normal, non-leap year).\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.YEAR_MS); // Prints: 31536000000\n */\ndayjs.YEAR_MS = 365 * dayjs.DAY_MS;\n\n/**\n * @static\n * @func now\n * @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).\n * @return {number}\n * @example\n * import { time } from '@dr.pogodin/react-utils';\n * console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.\n */\ndayjs.now = Date.now;\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\ndayjs.timer = async function timer(timeout) {\n const res = new Barrier();\n const id = setTimeout(res.resolve.bind(res), timeout);\n res.abort = () => clearTimeout(id);\n return res;\n};\n\nexport default dayjs;\n"],"file":"time.js"}