Skip to content

Commit

Permalink
first inline SubApp PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Dec 19, 2019
1 parent 20b59a4 commit cf53810
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 78 deletions.
27 changes: 19 additions & 8 deletions packages/subapp-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
136 changes: 68 additions & 68 deletions samples/poc-subapp/fyn-lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
_:
Expand Down
Loading

0 comments on commit cf53810

Please sign in to comment.