diff --git a/packages/subapp-web/src/index.js b/packages/subapp-web/src/index.js index 2f5582d382..ebf8987120 100644 --- a/packages/subapp-web/src/index.js +++ b/packages/subapp-web/src/index.js @@ -105,24 +105,35 @@ export function loadSubApp(info, renderStart) { return info; } -export function dynamicLoadSubApp(options) { +export function dynamicLoadSubApp({ name, id, timeout, onLoad, onError }) { // TODO: timeout and callback const wsa = window.webSubApps; - const lname = options.name.toLowerCase(); + const lname = name.toLowerCase(); if (wsa._bundles[lname] === undefined) { window.loadSubAppBundles(lname); } + const startTime = Date.now(); const load = delay => { setTimeout(() => { - const subApp = wsa[options.name]; - const element = document.getElementById(options.id); - if (element && subApp && subApp.start) { - subApp.start({ id: options.id }); - } else { - load(50); + const subApp = wsa[name]; + if (subApp) { + if (!id) { + return onLoad(); + } else { + const element = document.getElementById(id); + if (element && subApp.start) { + return subApp.start({ id }); + } + } } + + if (timeout > 50 && Date.now() - startTime > timeout) { + return onError(new Error("dynamicLoadSubApp Timeout")); + } + + return load(50); }, delay); }; diff --git a/samples/poc-subapp/fyn-lock.yaml b/samples/poc-subapp/fyn-lock.yaml index 7965f91f7d..dda1f8fd9e 100644 --- a/samples/poc-subapp/fyn-lock.yaml +++ b/samples/poc-subapp/fyn-lock.yaml @@ -5158,19 +5158,19 @@ ejs: $: sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA== _: 'https://registry.npmjs.org/ejs/-/ejs-2.7.4.tgz' electrode-archetype-opt-critical-css: - _latest: 1.0.3-fynlocal_h + _latest: 1.0.4-fynlocal_h _: - ../electrode-archetype-opt-critical-css: 1.0.3-fynlocal_h - 1.0.3-fynlocal_h: + ../electrode-archetype-opt-critical-css: 1.0.4-fynlocal_h + 1.0.4-fynlocal_h: optFailed: 1 $: local _: ../../packages/electrode-archetype-opt-critical-css electrode-archetype-opt-eslint: _latest: 1.0.3 _: - ../electrode-archetype-opt-eslint: 1.0.3-fynlocal_h + ../electrode-archetype-opt-eslint: 1.0.4-fynlocal_h ^1.0.3: 1.0.3 - 1.0.3-fynlocal_h: + 1.0.4-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-eslint @@ -5196,9 +5196,9 @@ electrode-archetype-opt-eslint: electrode-archetype-opt-flow: _latest: 1.0.2 _: - ../electrode-archetype-opt-flow: 1.0.2-fynlocal_h + ../electrode-archetype-opt-flow: 1.0.3-fynlocal_h ^1.0.2: 1.0.2 - 1.0.2-fynlocal_h: + 1.0.3-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-flow @@ -5216,19 +5216,19 @@ electrode-archetype-opt-flow: flow-bin: ^0.74.0 flow-typed: ^2.4.0 electrode-archetype-opt-inferno: - _latest: 0.2.11-fynlocal_h + _latest: 0.2.12-fynlocal_h _: - ../electrode-archetype-opt-inferno: 0.2.11-fynlocal_h - 0.2.11-fynlocal_h: + ../electrode-archetype-opt-inferno: 0.2.12-fynlocal_h + 0.2.12-fynlocal_h: optFailed: 1 $: local _: ../../packages/electrode-archetype-opt-inferno electrode-archetype-opt-jest: _latest: 1.0.3 _: - ../electrode-archetype-opt-jest: 1.0.3-fynlocal_h + ../electrode-archetype-opt-jest: 1.0.4-fynlocal_h ^1.0.3: 1.0.3 - 1.0.3-fynlocal_h: + 1.0.4-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-jest @@ -5254,9 +5254,9 @@ electrode-archetype-opt-jest: electrode-archetype-opt-karma: _latest: 2.0.7 _: - ../electrode-archetype-opt-karma: 2.0.7-fynlocal_h + ../electrode-archetype-opt-karma: 2.0.8-fynlocal_h ^2.0.6: 2.0.7 - 2.0.7-fynlocal_h: + 2.0.8-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-karma @@ -5308,9 +5308,9 @@ electrode-archetype-opt-karma: electrode-archetype-opt-less: _latest: 1.0.2 _: - ../electrode-archetype-opt-less: 1.0.2-fynlocal_h + ../electrode-archetype-opt-less: 1.0.3-fynlocal_h ^1.0.2: 1.0.2 - 1.0.2-fynlocal_h: + 1.0.3-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-less @@ -5328,9 +5328,9 @@ electrode-archetype-opt-less: electrode-archetype-opt-mocha: _latest: 1.0.3 _: - ../electrode-archetype-opt-mocha: 1.0.3-fynlocal_h + ../electrode-archetype-opt-mocha: 1.0.4-fynlocal_h ^1.0.3: 1.0.3 - 1.0.3-fynlocal_h: + 1.0.4-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-mocha @@ -5356,19 +5356,19 @@ electrode-archetype-opt-mocha: enzyme-adapter-react-16: ^1.1.0 mocha: ^4.0.0 electrode-archetype-opt-phantomjs: - _latest: 1.0.2-fynlocal_h + _latest: 1.0.3-fynlocal_h _: - ../electrode-archetype-opt-phantomjs: 1.0.2-fynlocal_h - 1.0.2-fynlocal_h: + ../electrode-archetype-opt-phantomjs: 1.0.3-fynlocal_h + 1.0.3-fynlocal_h: optFailed: 1 $: local _: ../../packages/electrode-archetype-opt-phantomjs electrode-archetype-opt-postcss: _latest: 1.0.4 _: - ../electrode-archetype-opt-postcss: 1.0.4-fynlocal_h + ../electrode-archetype-opt-postcss: 1.0.5-fynlocal_h ^1.0.4: 1.0.4 - 1.0.4-fynlocal_h: + 1.0.5-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-postcss @@ -5396,19 +5396,19 @@ electrode-archetype-opt-postcss: postcss-scss: ^1.0.6 sugarss: ^1.0.1 electrode-archetype-opt-preact: - _latest: 1.0.0-fynlocal_h + _latest: 1.0.1-fynlocal_h _: - ../electrode-archetype-opt-preact: 1.0.0-fynlocal_h - 1.0.0-fynlocal_h: + ../electrode-archetype-opt-preact: 1.0.1-fynlocal_h + 1.0.1-fynlocal_h: optFailed: 1 $: local _: ../../packages/electrode-archetype-opt-preact electrode-archetype-opt-pwa: _latest: 1.0.6 _: - ../electrode-archetype-opt-pwa: 1.0.6-fynlocal_h + ../electrode-archetype-opt-pwa: 1.0.7-fynlocal_h ^1.0.6: 1.0.6 - 1.0.6-fynlocal_h: + 1.0.7-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-pwa @@ -5438,9 +5438,9 @@ electrode-archetype-opt-pwa: electrode-archetype-opt-react: _latest: 2.0.4 _: - ../electrode-archetype-opt-react: 2.0.4-fynlocal_h + ../electrode-archetype-opt-react: 2.0.5-fynlocal_h ^2.0.4: 2.0.4 - 2.0.4-fynlocal_h: + 2.0.5-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-react @@ -5458,9 +5458,9 @@ electrode-archetype-opt-react: electrode-archetype-opt-react-intl: _latest: 1.0.0 _: - ../electrode-archetype-opt-react-intl: 1.0.0-fynlocal_h + ../electrode-archetype-opt-react-intl: 1.0.1-fynlocal_h ^1.0.0: 1.0.0 - 1.0.0-fynlocal_h: + 1.0.1-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-react-intl @@ -5474,10 +5474,10 @@ electrode-archetype-opt-react-intl: dependencies: react-intl: ^2.1.3 electrode-archetype-opt-sass: - _latest: 1.0.9-fynlocal_h + _latest: 1.0.10-fynlocal_h _: - ../electrode-archetype-opt-sass: 1.0.9-fynlocal_h - 1.0.9-fynlocal_h: + ../electrode-archetype-opt-sass: 1.0.10-fynlocal_h + 1.0.10-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-sass @@ -5487,9 +5487,9 @@ electrode-archetype-opt-sass: electrode-archetype-opt-sinon: _latest: 1.0.3 _: - ../electrode-archetype-opt-sinon: 1.0.3-fynlocal_h + ../electrode-archetype-opt-sinon: 1.0.4-fynlocal_h ^1.0.3: 1.0.3 - 1.0.3-fynlocal_h: + 1.0.4-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-sinon @@ -5507,9 +5507,9 @@ electrode-archetype-opt-sinon: electrode-archetype-opt-stylus: _latest: 1.0.2 _: - ../electrode-archetype-opt-stylus: 1.0.2-fynlocal_h + ../electrode-archetype-opt-stylus: 1.0.3-fynlocal_h ^1.0.2: 1.0.2 - 1.0.2-fynlocal_h: + 1.0.3-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-stylus @@ -5527,9 +5527,9 @@ electrode-archetype-opt-stylus: electrode-archetype-opt-typescript: _latest: 1.0.3 _: - ../electrode-archetype-opt-typescript: 1.0.3-fynlocal_h + ../electrode-archetype-opt-typescript: 1.0.4-fynlocal_h ^1.0.3: 1.0.3 - 1.0.3-fynlocal_h: + 1.0.4-fynlocal_h: hasPI: 1 $: local _: ../../packages/electrode-archetype-opt-typescript @@ -5545,10 +5545,10 @@ electrode-archetype-opt-typescript: typescript: ^3.2.1 '@babel/preset-typescript': ^7.1.0 electrode-archetype-react-app: - _latest: 6.5.21-fynlocal_h + _latest: 7.0.0-beta7.0-fynlocal_h _: - ../../packages/electrode-archetype-react-app: 6.5.21-fynlocal_h - 6.5.21-fynlocal_h: + ../../packages/electrode-archetype-react-app: 7.0.0-beta7.0-fynlocal_h + 7.0.0-beta7.0-fynlocal_h: top: 1 $: local _: ../../packages/electrode-archetype-react-app @@ -5560,13 +5560,13 @@ electrode-archetype-react-app: optional-require: ^1.0.0 subapp-util: ^1.0.2 optionalDependencies: - electrode-archetype-opt-inferno: ^0.2.11 - electrode-archetype-opt-react: ^2.0.4 + electrode-archetype-opt-inferno: ^0.2.12 + electrode-archetype-opt-react: ^2.0.5 electrode-archetype-react-app-dev: - _latest: 6.5.21-fynlocal_h + _latest: 7.0.0-beta7.0-fynlocal_h _: - ../../packages/electrode-archetype-react-app-dev: 6.5.21-fynlocal_h - 6.5.21-fynlocal_h: + ../../packages/electrode-archetype-react-app-dev: 7.0.0-beta7.0-fynlocal_h + 7.0.0-beta7.0-fynlocal_h: top: 1 $: local _: ../../packages/electrode-archetype-react-app-dev @@ -5649,26 +5649,26 @@ electrode-archetype-react-app-dev: xenv-config: ^1.3.0 xsh: ^0.4.4 optionalDependencies: - electrode-archetype-opt-critical-css: ^1.0.3 - electrode-archetype-opt-eslint: ^1.0.3 - electrode-archetype-opt-flow: ^1.0.2 - electrode-archetype-opt-inferno: ^0.2.11 - electrode-archetype-opt-jest: ^1.0.3 - electrode-archetype-opt-karma: ^2.0.7 - electrode-archetype-opt-less: ^1.0.2 - electrode-archetype-opt-mocha: ^1.0.3 - electrode-archetype-opt-phantomjs: ^1.0.2 - electrode-archetype-opt-postcss: ^1.0.4 - electrode-archetype-opt-preact: ^1.0.0 - electrode-archetype-opt-pwa: ^1.0.6 - electrode-archetype-opt-react: ^2.0.4 - electrode-archetype-opt-react-intl: ^1.0.0 - electrode-archetype-opt-sass: ^1.0.9 - electrode-archetype-opt-stylus: ^1.0.2 - electrode-archetype-opt-sinon: ^1.0.3 - electrode-archetype-opt-typescript: ^1.0.3 + electrode-archetype-opt-critical-css: ^1.0.4 + electrode-archetype-opt-eslint: ^1.0.4 + electrode-archetype-opt-flow: ^1.0.3 + electrode-archetype-opt-inferno: ^0.2.12 + electrode-archetype-opt-jest: ^1.0.4 + electrode-archetype-opt-karma: ^2.0.8 + electrode-archetype-opt-less: ^1.0.3 + electrode-archetype-opt-mocha: ^1.0.4 + electrode-archetype-opt-phantomjs: ^1.0.3 + electrode-archetype-opt-postcss: ^1.0.5 + electrode-archetype-opt-preact: ^1.0.1 + electrode-archetype-opt-pwa: ^1.0.7 + electrode-archetype-opt-react: ^2.0.5 + electrode-archetype-opt-react-intl: ^1.0.1 + electrode-archetype-opt-sass: ^1.0.10 + electrode-archetype-opt-stylus: ^1.0.3 + electrode-archetype-opt-sinon: ^1.0.4 + electrode-archetype-opt-typescript: ^1.0.4 peerDependencies: - electrode-archetype-react-app: ^6.0.0 + electrode-archetype-react-app: 7.0.0-beta7.0 electrode-cdn-file-loader: _latest: 1.1.1 _: diff --git a/samples/poc-subapp/src/components/deals.jsx b/samples/poc-subapp/src/components/deals.jsx index c9110858d4..9f3641d962 100644 --- a/samples/poc-subapp/src/components/deals.jsx +++ b/samples/poc-subapp/src/components/deals.jsx @@ -3,6 +3,46 @@ import { dynamicLoadSubApp } from "subapp-web"; import PropTypes from "prop-types"; import { connect } from "react-redux"; +class SubApp extends React.Component { + constructor() { + super(); + this.state = { ready: false }; + } + + render() { + // is subapp loaded? + // TODO: handle SSR + if (typeof window === "undefined") { + return ""; + } + const { name } = this.props; + const wsa = window.webSubApps; + const lname = name.toLowerCase(); + + if (wsa._bundles[lname] && wsa[name]) { + const subapp = window.webSubApps[name]; + return ( +