{"version":3,"file":"wait_object_by_path_promise-BXT1Dqdf.js","sources":["../../../node_modules/lodash/propertyOf.js","../../../app/assets/javascripts/app/object-finder.ts","../../../app/assets/javascripts/app/wait_object_by_path_promise.ts"],"sourcesContent":["var baseGet = require('./_baseGet');\n\n/**\n * The opposite of `_.property`; this method creates a function that returns\n * the value at a given path of `object`.\n *\n * @static\n * @memberOf _\n * @since 3.0.0\n * @category Util\n * @param {Object} object The object to query.\n * @returns {Function} Returns the new accessor function.\n * @example\n *\n * var array = [0, 1, 2],\n * object = { 'a': array, 'b': array, 'c': array };\n *\n * _.map(['a[2]', 'c[0]'], _.propertyOf(object));\n * // => [2, 0]\n *\n * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));\n * // => [2, 0]\n */\nfunction propertyOf(object) {\n return function(path) {\n return object == null ? undefined : baseGet(object, path);\n };\n}\n\nmodule.exports = propertyOf;\n","\nimport _propertyOf from \"lodash/propertyOf\"\n\nconst ObjectFinder = {\n findObjectByPath(path: string, scope_object = null) {\n // If any falsy thing passed in, replace with `window`\n const cur_scope = scope_object || window\n\n // We should strip \"window.\" since we cannot find `window` in `window`\n path.replace(/^window\\./, \"\")\n .replace(/\\[(\\w+)]/g, \".$1\")// convert indexes to properties\n .replace(/^\\./, \"\") // strip a leading dot\n\n const ar = path.split(\".\")\n\n return ar.reduce((scope, key) => _propertyOf(scope)(key), cur_scope)\n },\n}\n\nexport default ObjectFinder\n","\nimport Promise from \"plugins/bluebird/index\"\nimport log from \"plugins/loglevel/index\"\nimport ObjectFinder from \"app/object-finder\"\n\n\n/* eslint-disable no-unused-vars */\nenum RejectionReasons {\n TIMEOUT = \"TIMEOUT\",\n}\n/* eslint-enable no-unused-vars */\ninterface RejectionResult {\n rejection_reason: RejectionReasons,\n rejection_message: string,\n}\n\ninterface TimeState {\n total_wait_time_ms: number,\n wait_interval_ms: number,\n}\n\ninterface Options {\n wait_interval_ms: number,\n wait_interval_increase_ms: number,\n max_wait_interval_ms: number,\n max_wait_time_ms: number,\n should_log_timeout: boolean,\n}\n\ninterface InputOptions {\n wait_interval_ms?: number,\n wait_interval_increase_ms?: number,\n max_wait_interval_ms?: number,\n max_wait_time_ms?: number,\n should_log_timeout?: boolean,\n}\n\n// ============== main ==================\nconst DEFAULT_OPTION = {\n wait_interval_ms: 50,\n wait_interval_increase_ms: 50,\n max_wait_interval_ms: 500,\n max_wait_time_ms: 30 * 1000,\n should_log_timeout: true,\n}\n\nconst dummyLoop = (condition: (() => boolean), onExit: (() => void), onTimeout: ((n: number) => void), option: Options, state: TimeState) => {\n const {max_wait_interval_ms, wait_interval_increase_ms, max_wait_time_ms} = option\n let {total_wait_time_ms, wait_interval_ms} = state\n\n const partialDummyLoop = (state_in_partial: TimeState) => {\n dummyLoop(condition, onExit, onTimeout, option, state_in_partial)\n }\n\n setTimeout(() => {\n if (condition()) {\n onExit()\n }\n else {\n // increment time wait for the last iteration\n total_wait_time_ms += wait_interval_ms\n // break part\n if (total_wait_time_ms >= max_wait_time_ms) {\n onTimeout(total_wait_time_ms)\n return\n }\n\n // linear increase on timeout for next iteration\n if (wait_interval_ms < max_wait_interval_ms) {\n wait_interval_ms += wait_interval_increase_ms\n }\n\n partialDummyLoop({total_wait_time_ms, wait_interval_ms})\n }\n }, wait_interval_ms)\n}\n\nconst WaitObjectByPathPromise = (objectNameToWait: string, options: InputOptions = {}): Promise => {\n return new Promise((resolve, reject) => {\n const total_wait_time_ms = 0\n const opts = Object.assign({}, DEFAULT_OPTION, options)\n const {wait_interval_ms, should_log_timeout} = opts\n const init_state = { total_wait_time_ms, wait_interval_ms }\n\n const stopCondition = () => ObjectFinder.findObjectByPath(objectNameToWait) != null\n const local_resolve = () => resolve(ObjectFinder.findObjectByPath(objectNameToWait))\n const onTimeout = (total_time: number) => {\n if (should_log_timeout) {\n log.debug(`WaitObjectByPathPromise waited ${objectNameToWait} for ${total_time / 1000}s, it failed to be defined/loaded`)\n }\n reject(({\n rejection_reason: RejectionReasons.TIMEOUT,\n rejection_message: `WaitObjectByPathPromise waited ${objectNameToWait} for ${total_time / 1000}s, it failed to be defined/loaded`,\n } as RejectionResult))\n }\n\n if (stopCondition()) {\n local_resolve()\n }\n else {\n dummyLoop(stopCondition, local_resolve, onTimeout, opts, init_state)\n }\n })\n}\n\n\nexport default WaitObjectByPathPromise\n\nexport {\n WaitObjectByPathPromise,\n RejectionReasons,\n}\n"],"names":["baseGet","require$$0","propertyOf","object","path","propertyOf_1","ObjectFinder","scope_object","cur_scope","scope","key","_propertyOf","RejectionReasons","DEFAULT_OPTION","dummyLoop","condition","onExit","onTimeout","option","state","max_wait_interval_ms","wait_interval_increase_ms","max_wait_time_ms","total_wait_time_ms","wait_interval_ms","partialDummyLoop","state_in_partial","WaitObjectByPathPromise","objectNameToWait","options","Promise","resolve","reject","opts","should_log_timeout","init_state","stopCondition","local_resolve","total_time","log"],"mappings":"yKAAA,IAAIA,EAAUC,EAAqB,EAuBnC,SAASC,EAAWC,EAAQ,CAC1B,OAAO,SAASC,EAAM,CACpB,OAAOD,GAAU,KAAO,OAAYH,EAAQG,EAAQC,CAAI,CACzD,CACH,CAEA,OAAAC,EAAiBH,2BC1BXI,EAAe,CACnB,iBAAiBF,EAAcG,EAAe,KAAM,CAElD,MAAMC,EAAYD,GAAgB,OAG7B,OAAAH,EAAA,QAAQ,YAAa,EAAE,EAC3B,QAAQ,YAAa,KAAK,EAC1B,QAAQ,MAAO,EAAE,EAEPA,EAAK,MAAM,GAAG,EAEf,OAAO,CAACK,EAAOC,IAAQC,EAAYF,CAAK,EAAEC,CAAG,EAAGF,CAAS,CAAA,CAEvE,ECVK,IAAAI,GAAAA,IACHA,EAAA,QAAU,UADPA,IAAAA,GAAA,CAAA,CAAA,EA+BL,MAAMC,EAAiB,CACrB,iBAA4B,GAC5B,0BAA4B,GAC5B,qBAA4B,IAC5B,iBAA4B,GAAK,IACjC,mBAA4B,EAC9B,EAEMC,EAAY,CAACC,EAA4BC,EAAsBC,EAAkCC,EAAiBC,IAAqB,CAC3I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