@dr.pogodin/react-utils 1.23.7 → 1.23.8
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/build/development/client/index.js +1 -2
- package/build/development/client/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +0 -2
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +0 -2
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/package.json +20 -20
|
@@ -17,8 +17,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
17
17
|
* Prepares and launches the app at client side.
|
|
18
18
|
* @param {object} Application Root application component
|
|
19
19
|
* @param {object} [options={}] Optional. Additional settings.
|
|
20
|
-
*/
|
|
21
|
-
function Launch(Application) {
|
|
20
|
+
*/function Launch(Application) {
|
|
22
21
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
22
|
const container = document.getElementById('react-view');
|
|
24
23
|
const scene = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_reactGlobalState","require","_client","_reactRouterDom","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","arguments","length","undefined","container","document","getElementById","scene","jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","dontHydrate","root","createRoot","render","hydrateRoot"],"sources":["../../../src/client/index.jsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router-dom';\n\nimport getInj from './getInj';\n\n/**\n * Prepares and launches the app at client side.\n * @param {object} Application Root application component\n * @param {object} [options={}] Optional. Additional settings.\n */\nexport default function Launch(Application, options = {}) {\n const container = document.getElementById('react-view');\n const scene = (\n <GlobalStateProvider initialState={getInj().ISTATE}>\n <BrowserRouter>\n <Application />\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8B,IAAAK,WAAA,GAAAL,OAAA;AAR9B;AACA;;AASA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"file":"index.js","names":["_reactGlobalState","require","_client","_reactRouterDom","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","arguments","length","undefined","container","document","getElementById","scene","jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","dontHydrate","root","createRoot","render","hydrateRoot"],"sources":["../../../src/client/index.jsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router-dom';\n\nimport getInj from './getInj';\n\n/**\n * Prepares and launches the app at client side.\n * @param {object} Application Root application component\n * @param {object} [options={}] Optional. Additional settings.\n */\nexport default function Launch(Application, options = {}) {\n const container = document.getElementById('react-view');\n const scene = (\n <GlobalStateProvider initialState={getInj().ISTATE}>\n <BrowserRouter>\n <Application />\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8B,IAAAK,WAAA,GAAAL,OAAA;AAR9B;AACA;;AASA;AACA;AACA;AACA;AACA,GACe,SAASM,MAAMA,CAACC,WAAW,EAAgB;EAAA,IAAdC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACtD,MAAMG,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,MAAMC,KAAK,gBACT,IAAAV,WAAA,CAAAW,GAAA,EAACjB,iBAAA,CAAAkB,mBAAmB;IAACC,YAAY,EAAE,IAAAC,eAAM,GAAE,CAACC,MAAO;IAAAC,QAAA,eACjD,IAAAhB,WAAA,CAAAW,GAAA,EAACd,eAAA,CAAAoB,aAAa;MAAAD,QAAA,eACZ,IAAAhB,WAAA,CAAAW,GAAA,EAACT,WAAW;IAAG;EACD,EAEnB;EAED,IAAIC,OAAO,CAACe,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAG,IAAAC,kBAAU,EAACb,SAAS,CAAC;IAClCY,IAAI,CAACE,MAAM,CAACX,KAAK,CAAC;EACpB,CAAC,MAAM,IAAAY,mBAAW,EAACf,SAAS,EAAEG,KAAK,CAAC;AACtC"}
|
|
@@ -32,9 +32,7 @@ var _webpack = _interopRequireDefault(require("webpack"));
|
|
|
32
32
|
// As this environment is a part of the Jest testing utils,
|
|
33
33
|
// we assume development dependencies are available when it is used.
|
|
34
34
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
35
|
-
|
|
36
35
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
37
|
-
|
|
38
36
|
class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
39
37
|
/**
|
|
40
38
|
* Loads Webpack config, and exposes it to the environment via global
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_renderer","_lodash","_register","_jestEnvironmentJsdom","_memfs","_webpack","E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports","default"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n {\n cookie: noop,\n send: done,\n set: noop,\n status: (value) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n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AAO,CAACzE,OAAO,CAAC0E,QAAQ,CAAC;IAChD,IAAI,CAACC,OAAO,GAAG,CAAC/E,OAAO,CAAC,QAAQ,CAAC;IACjC,IAAI,CAACyD,UAAU,GAAGa,OAAO;IACzB,IAAI,CAACtE,OAAO,GAAGA,OAAO;EACxB;EAEA,MAAMgF,KAAKA,CAAA,EAAG;IACZ,MAAM,KAAK,CAACA,KAAK,EAAE;IACnB,MAAM,IAAI,CAAC/D,UAAU,EAAE;IACvB,IAAI,IAAI,CAAC8D,OAAO,EAAE,MAAM,IAAI,CAAC7C,MAAM,EAAE;IACrC,IAAI,CAAC3B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAG;IACf,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC/F,OAAO,CAACgG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOlG,OAAO,CAACgG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,iBAAQ,CAAC2C,MAAM,EAAE;IACjB,KAAK,CAACN,QAAQ,EAAE;EAClB;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA9F,SAAA"}
|
|
1
|
+
{"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_renderer","_lodash","_register","_jestEnvironmentJsdom","_memfs","_webpack","E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports","default"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n {\n cookie: noop,\n send: done,\n set: noop,\n status: (value) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAKA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,qBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAP,sBAAA,CAAAC,O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,OAAO,EAAE,MAAM,IAAI,CAAC7C,MAAM,EAAE;IACrC,IAAI,CAAC3B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAG;IACf,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC/F,OAAO,CAACgG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOlG,OAAO,CAACgG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,iBAAQ,CAAC2C,MAAM,EAAE;IACjB,KAAK,CAACN,QAAQ,EAAE;EAClB;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA9F,SAAA"}
|
|
@@ -33,13 +33,11 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
33
33
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
34
34
|
|
|
35
35
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
36
|
-
|
|
37
36
|
/**
|
|
38
37
|
* An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
|
|
39
38
|
* from `react-dom/test-utils`.
|
|
40
39
|
* @param {function} action
|
|
41
40
|
*/
|
|
42
|
-
|
|
43
41
|
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
44
42
|
const originalProcessVersions = process.versions;
|
|
45
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate","exports"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AAGA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AAA0D,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAT1D;AACA;;AAMA;;AAGA
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate","exports"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AAGA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AAA0D,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAA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U,MAAMA,CAACC,SAAS,EAAE;EAChC,OAAOC,0BAAQ,CAACC,MAAM,CAACF,SAAS,CAAC,CAACG,MAAM,EAAE;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACJ,SAAS,EAAE;EACvC,MAAMK,QAAQ,GAAG,IAAIC,gBAAe,EAAE;EACtCD,QAAQ,CAACN,MAAM,CAACC,SAAS,CAAC;EAC1B,OAAOK,QAAQ,CAACE,eAAe,EAAE;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACR,SAAS,EAAE;EACzC,MAAMX,GAAG,GAAGe,aAAa,CAACJ,SAAS,CAAC;EACpCS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,EAAE;EAC7B,OAAOrB,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASsB,QAAQA,CAACX,SAAS,EAAE;EAClC,MAAMX,GAAG,GAAGU,MAAM,CAACC,SAAS,CAAC;EAC7BS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,EAAE;EAC7B,OAAOrB,GAAG;AACZ;AAEO,MAAMuB,QAAQ,GAAGC,kBAAE,CAACC,QAAQ;AAACC,OAAA,CAAAH,QAAA,GAAAA,QAAA"}
|
|
@@ -268,7 +268,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
268
268
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
269
269
|
|
|
270
270
|
"use strict";
|
|
271
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": function() { return /* binding */ Semaphore; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldGet */ \"@babel/runtime/helpers/classPrivateFieldGet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldSet */ \"@babel/runtime/helpers/classPrivateFieldSet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\nfunction _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }\nfunction _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }\nfunction _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); } }\nfunction _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError(\"attempted to get private field on non-instance\"); } return fn; }\n\n\n/**\n * Implements a simple semaphore for async code logic.\n */\nvar _drainQueue = /*#__PURE__*/new WeakSet();\nvar _draining = /*#__PURE__*/new WeakMap();\nvar _drainLock = /*#__PURE__*/new WeakMap();\nvar _queue = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Semaphore {\n constructor(ready) {\n _classPrivateMethodInitSpec(this, _drainQueue);\n _classPrivateFieldInitSpec(this, _draining, {\n writable: true,\n value: false\n });\n _classPrivateFieldInitSpec(this, _drainLock, {\n writable: true,\n value: null\n });\n _classPrivateFieldInitSpec(this, _queue, {\n writable: true,\n value: []\n });\n _classPrivateFieldInitSpec(this, _ready, {\n writable: true,\n value: void 0\n });\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, !!ready);\n }\n get ready() {\n return _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready);\n }\n setReady(ready) {\n const bool = !!ready;\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready) !== bool) {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, bool);\n if (bool && !_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _draining) && _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).length) _classPrivateMethodGet(this, _drainQueue, _drainQueue2).call(this);\n }\n }\n\n /**\n * Waits until the semaphore is ready, and marks it as non-ready (seizes it).\n * @return {Promise}\n */\n async seize() {\n return this.waitReady(true);\n }\n async waitReady() {\n let seize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n if (!_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready) || _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).length) {\n const barrier = new _Barrier__WEBPACK_IMPORTED_MODULE_2__.Barrier();\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).push(barrier);\n await barrier;\n if (seize) _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, false);\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _drainLock).resolve();\n } else if (seize) _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, false);\n }\n
|
|
271
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": function() { return /* binding */ Semaphore; }\n/* harmony export */ });\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldGet */ \"@babel/runtime/helpers/classPrivateFieldGet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classPrivateFieldSet */ \"@babel/runtime/helpers/classPrivateFieldSet\");\n/* harmony import */ var _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _Barrier__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Barrier */ \"./src/shared/utils/Barrier.js\");\n\n\nfunction _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }\nfunction _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }\nfunction _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); } }\nfunction _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError(\"attempted to get private field on non-instance\"); } return fn; }\n\n\n/**\n * Implements a simple semaphore for async code logic.\n */\nvar _drainQueue = /*#__PURE__*/new WeakSet();\nvar _draining = /*#__PURE__*/new WeakMap();\nvar _drainLock = /*#__PURE__*/new WeakMap();\nvar _queue = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Semaphore {\n constructor(ready) {\n // Private members below this point.\n /**\n * If semaphore is ready, it releases the next barrier in the queue, if any,\n * and reschedules itself for a call in the next event loop iteration.\n * Otherwise, it breaks the queue draining loop, which will be restarted\n * the next time the semaphore is set ready.\n */\n _classPrivateMethodInitSpec(this, _drainQueue);\n // \"true\" when the drain queue process is running (and thus no need to start\n // a new one).\n _classPrivateFieldInitSpec(this, _draining, {\n writable: true,\n value: false\n });\n // Each time a Promise from drain queue is resolved this drainLock is set\n // to block further queue draining until the promise resolution handler\n // (.seize() or .waitReady()) unlocks it, thus confirming it is fine\n // to continue the draining. This is specifically important for .seize(),\n // which should have a chance to switch semaphore state to non-ready prior\n // to next Promise in the queue being unlocked.\n _classPrivateFieldInitSpec(this, _drainLock, {\n writable: true,\n value: null\n });\n // The array of barriers set for each async code flow awaiting for\n // the Semaphore to become ready.\n _classPrivateFieldInitSpec(this, _queue, {\n writable: true,\n value: []\n });\n _classPrivateFieldInitSpec(this, _ready, {\n writable: true,\n value: void 0\n });\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, !!ready);\n }\n get ready() {\n return _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready);\n }\n setReady(ready) {\n const bool = !!ready;\n if (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready) !== bool) {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, bool);\n if (bool && !_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _draining) && _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).length) _classPrivateMethodGet(this, _drainQueue, _drainQueue2).call(this);\n }\n }\n\n /**\n * Waits until the semaphore is ready, and marks it as non-ready (seizes it).\n * @return {Promise}\n */\n async seize() {\n return this.waitReady(true);\n }\n async waitReady() {\n let seize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n if (!_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready) || _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).length) {\n const barrier = new _Barrier__WEBPACK_IMPORTED_MODULE_2__.Barrier();\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).push(barrier);\n await barrier;\n if (seize) _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, false);\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _drainLock).resolve();\n } else if (seize) _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _ready, false);\n }\n}\nasync function _drainQueue2() {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _draining, true);\n while (_babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _ready) && _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).length) {\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _drainLock, new _Barrier__WEBPACK_IMPORTED_MODULE_2__.Barrier());\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue)[0].resolve();\n await _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _drainLock); // eslint-disable-line no-await-in-loop\n _babel_runtime_helpers_classPrivateFieldGet__WEBPACK_IMPORTED_MODULE_0___default()(this, _queue).shift();\n }\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _draining, false);\n _babel_runtime_helpers_classPrivateFieldSet__WEBPACK_IMPORTED_MODULE_1___default()(this, _drainLock, null);\n}\n\n//# sourceURL=webpack://@dr.pogodin/react-utils/./src/shared/utils/Semaphore.js?");
|
|
272
272
|
|
|
273
273
|
/***/ }),
|
|
274
274
|
|