Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Async JavaScript Lazy Loading#899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6fbaa15d4b56ab937bc3081408b93c1620dd36409042f658093cfc2451b4ddfa70f3c272fe8c23077b80917f536231765ea387525df362a18ee541a10bde0396cf8f5659496f4e787b6cd1d1dc9429047cd69f6bba0389535ba28a953f65b610ff28b4e105a9d24848f32edbd91771d158034cd5478f839d956152f303afee608a0ab5801fbe2eb1dc5a16360a18d3c24712eb37e4c9e4daa8eb2c87000deec3d642b62f4766dad29b0678999e437c2650fa92ea2d481ce97923c3c81caf35006247bb643e13e82884c74aa598dae8d6c1370a6e4c68b864cb92a5699558bf6c13e274e1a7a4707c3edaa7852312063185eaa79b2fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
| Copyright (c) 2019 Plotly | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "@plotly/dash-component-plugins", | ||
| "version": "1.0.1", | ||
| "description": "Plugins for Dash Components", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git@github.com:plotly/dash.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/plotly/dash/issues" | ||
| }, | ||
| "homepage": "https://github.com/plotly/dash", | ||
| "main": "src/index.js", | ||
| "author": "Marc-André Rivet", | ||
| "license": "MIT" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { lazy } from 'react'; | ||
| export const asyncDecorator = (target, promise) => { | ||
| let resolve; | ||
| const isReady = new Promise(r => { | ||
| resolve = r; | ||
| }); | ||
| const state = { | ||
| isReady, | ||
| get: lazy(() => { | ||
| return Promise.resolve(promise()).then(res => { | ||
| setTimeout(async () => { | ||
| await resolve(true); | ||
| state.isReady = true; | ||
| }, 0); | ||
| return res; | ||
| }); | ||
| }), | ||
| }; | ||
| Object.defineProperty(target, '_dashprivate_isLazyComponentReady', { | ||
| get: () => state.isReady, | ||
| }); | ||
| return state.get; | ||
| }; | ||
| export const isReady = target => target && | ||
| target._dashprivate_isLazyComponentReady; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { asyncDecorator, isReady } from './dynamicImport'; | ||
| export { asyncDecorator, isReady }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
| Copyright (c) 2019 Plotly | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "@plotly/webpack-dash-dynamic-import", | ||
| "version": "1.0.0", | ||
| "description": "Webpack Plugin for Dynamic Import in Dash", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git@github.com:plotly/dash.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/plotly/dash/issues" | ||
| }, | ||
| "homepage": "https://github.com/plotly/dash", | ||
| "main": "src/index.js", | ||
| "author": "Marc-André Rivet", | ||
| "license": "MIT" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| const resolveImportSource = `\ | ||
| Object.defineProperty(__webpack_require__, 'p', { | ||
| get: (function () { | ||
| let script = document.currentScript; | ||
| if (!script) { | ||
| /* Shim for IE11 and below */ | ||
| /* Do not take into account async scripts and inline scripts */ | ||
| const scripts = Array.from(document.getElementsByTagName('script')).filter(function(s) { return !s.async && !s.text && !s.textContent; }); | ||
| script = scripts.slice(-1)[0]; | ||
| } | ||
| var url = script.src.split('/').slice(0, -1).join('/') + '/'; | ||
| return function() { | ||
| return url; | ||
| }; | ||
| })() | ||
| });` | ||
| class WebpackDashDynamicImport { | ||
| apply(compiler) { | ||
| compiler.hooks.compilation.tap('WebpackDashDynamicImport', compilation => { | ||
| compilation.mainTemplate.hooks.requireExtensions.tap('WebpackDashDynamicImport > RequireExtensions', (source, chunk, hash) => { | ||
| return [ | ||
| source, | ||
| resolveImportSource | ||
| ] | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| module.exports = WebpackDashDynamicImport; |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| module.exports = { | ||
| presets: [['@babel/preset-env', { | ||
| useBuiltIns: 'usage', | ||
| corejs: 3 | ||
| }], '@babel/preset-react'], | ||
| env: { | ||
| test: { | ||
| plugins: [ | ||
| '@babel/plugin-transform-modules-commonjs' | ||
| ] | ||
| } | ||
| } | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -33,17 +33,20 @@ import cookie from 'cookie'; | ||
| import {uid, urlBase, isMultiOutputProp, parseMultipleOutputs} from '../utils'; | ||
| import {STATUS} from '../constants/constants'; | ||
| import {applyPersistence, prunePersistence} from '../persistence'; | ||
| import setAppIsReady from './setAppReadyState'; | ||
| export const updateProps = createAction(getAction('ON_PROP_CHANGE')); | ||
| export const setRequestQueue = createAction(getAction('SET_REQUEST_QUEUE')); | ||
| export const computeGraphs = createAction(getAction('COMPUTE_GRAPHS')); | ||
| export const computePaths = createAction(getAction('COMPUTE_PATHS')); | ||
| export const setLayout = createAction(getAction('SET_LAYOUT')); | ||
| export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE')); | ||
| export const setConfig = createAction(getAction('SET_CONFIG')); | ||
| export const setHooks = createAction(getAction('SET_HOOKS')); | ||
| export const setLayout = createAction(getAction('SET_LAYOUT')); | ||
| export const onError = createAction(getAction('ON_ERROR')); | ||
| export {setAppIsReady}; | ||
| export function hydrateInitialOutputs() { | ||
| return function(dispatch, getState) { | ||
| triggerDefaultState(dispatch, getState); | ||
| @@ -175,7 +178,7 @@ function reduceInputIds(nodeIds, InputGraph) { | ||
| /* | ||
| * Create input-output(s) pairs, | ||
| * sort by number of outputs, | ||
| * and remove redudant inputs (inputs that update the same output) | ||
Marc-Andre-Rivet marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * and remove redundant inputs (inputs that update the same output) | ||
| */ | ||
| const inputOutputPairs = nodeIds.map(nodeId => ({ | ||
| input: nodeId, | ||
| @@ -194,7 +197,7 @@ function reduceInputIds(nodeIds, InputGraph) { | ||
| * trigger components to update multiple times. | ||
| * | ||
| * For example, [A, B] => C and [A, D] => E | ||
| * The unique inputs might be [A, B, D] but that is redudant. | ||
| * The unique inputs might be [A, B, D] but that is redundant. | ||
| * We only need to update B and D or just A. | ||
| * | ||
| * In these cases, we'll supply an additional list of outputs | ||
| @@ -215,10 +218,15 @@ function reduceInputIds(nodeIds, InputGraph) { | ||
| } | ||
| export function notifyObservers(payload) { | ||
| return function(dispatch, getState) { | ||
| return async function(dispatch, getState) { | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notifyObservers may now have to wait defensively before sending callbacks | ||
| const {id, props, excludedOutputs} = payload; | ||
| const {graphs, requestQueue} = getState(); | ||
| const {graphs, isAppReady, requestQueue} = getState(); | ||
| if (isAppReady !== true) { | ||
| await isAppReady; | ||
| } | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a known component is not ready, wait for it | ||
| const {InputGraph} = graphs; | ||
| /* | ||
| * Figure out all of the output id's that depend on this input. | ||
| @@ -942,6 +950,8 @@ function updateOutput( | ||
| ); | ||
| }); | ||
| } | ||
| dispatch(setAppIsReady()); | ||
alexcjohnson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| }; | ||
| if (multi) { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.