Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxBing0066 committed Sep 30, 2020
1 parent a54b9c1 commit 2a20dd8
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/history/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[
"@babel/plugin-transform-runtime",
{
"corejs": 2,
"corejs": 3,
"helpers": true,
"regenerator": true,
"useESModules": false
Expand Down
2 changes: 1 addition & 1 deletion examples/history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getConfig = () => config;
}[historyType];

const app = new RAPIOP({
config: getConfig,
getConfig,
history,
mountDOM
});
Expand Down
1 change: 1 addition & 0 deletions examples/history/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "ZxBing0066",
"license": "MIT",
"dependencies": {
"@rapiop/mod": "^0.0.8",
"@rapiop/rapiop": "latest",
"axios": "^0.19.0",
"core-js": "^3.6.5",
Expand Down
1 change: 1 addition & 0 deletions examples/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "ZxBing0066",
"license": "MIT",
"dependencies": {
"@rapiop/mod": "^0.0.8",
"@rapiop/rapiop": "latest",
"axios": "^0.19.0",
"history": "^4.9.0"
Expand Down
36 changes: 21 additions & 15 deletions examples/plugins/dist/error-demo.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
window.app.loadDependences(['error-dependence']).then(() => {
window.app.register(
'error-demo',
mountDOM => {
const content = document.createElement('div');
content.innerText = 'this is my error demo';
mountDOM.appendChild(content);
console.log('error demo mounted');
},
mountDOM => {
mountDOM.innerHTML = null;
console.log('error demo unmounted');
}
);
});
window.mod
.import(['error-dependence'])
.then(() => {
window.app.register(
'error-demo',
mountDOM => {
const content = document.createElement('div');
content.innerText = 'this is my error demo';
mountDOM.appendChild(content);
console.log('error demo mounted');
},
mountDOM => {
mountDOM.innerHTML = null;
console.log('error demo unmounted');
}
);
})
.catch(e => {
console.log(e);
alert('error');
});
3 changes: 2 additions & 1 deletion examples/plugins/dist/frame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.app.loadDependences(['lodash'], () => {
window.mod.import(['lodash']).then(() => {
console.log(123);
const app = window.app;
const _ = window._;
app.registerFrame(() => {
Expand Down
4 changes: 1 addition & 3 deletions examples/plugins/dist/iframe-demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
window.app.loadDependences(['React', 'ReactDOM'], () => {
const React = window.React;
const ReactDOM = window.ReactDOM;
window.mod.import(['react', 'react-dom']).then(([React, ReactDOM]) => {
window.app.register(
'iframe-demo',
mountDOM => {
Expand Down
4 changes: 1 addition & 3 deletions examples/plugins/dist/react-demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
window.app.loadDependences(['React', 'ReactDOM'], () => {
const React = window.React;
const ReactDOM = window.ReactDOM;
window.mod.import(['react', 'react-dom']).then(([React, ReactDOM]) => {
window.app.register(
'react-demo',
mountDOM => {
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/dist/test-demo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.app.loadDependences(['test'], () => {
window.mod.import(['test.js']).then(() => {
window.app.register(
'test-demo',
mountDOM => {
Expand Down
31 changes: 14 additions & 17 deletions examples/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import _ from 'lodash';
import { createBrowserHistory } from 'history';
import RAPIOP from '@rapiop/rapiop';
import FramePlugin from '@rapiop/rapiop/lib/plugins/frame';
import DependencePlugin from '@rapiop/rapiop/lib/plugins/dependence';
import IframePlugin from '@rapiop/rapiop/lib/plugins/iframe';
import mod from '@rapiop/mod';
import '@rapiop/mod/lib/resolver/amd';

const config = {
demo: {
Expand Down Expand Up @@ -43,32 +44,27 @@ const config = {
}
};
const dependenceMap = {
React: { files: ['https://unpkg.com/[email protected]/umd/react.production.min.js'] },
ReactDOM: { files: ['https://unpkg.com/[email protected]/umd/react-dom.production.min.js'], dependences: ['React'] },
lodash: { files: ['https://unpkg.com/[email protected]/lodash.min.js'] },
test: { files: ['/test.js'], dependences: ['React', 'ReactDOM'] },
'error-dependence': { files: ['https://error.js'] }
react: { js: ['https://unpkg.com/[email protected]/umd/react.production.min.js'], type: 'amd' },
'react-dom': {
js: ['https://unpkg.com/[email protected]/umd/react-dom.production.min.js'],
dep: ['react'],
type: 'amd'
},
lodash: { js: ['https://unpkg.com/[email protected]/lodash.min.js'], type: 'amd' },
'error-dependence': { js: ['https://error.js'] }
};

function getConfig() {
return config;
}
mod.config({ modules: dependenceMap });
const isIframe = window.top != window;

const history = createBrowserHistory();
const app = new RAPIOP({
config: getConfig,
history,
plugins: [
new IframePlugin(),
new FramePlugin(),
new DependencePlugin({
getDependenceMap: () => Promise.resolve(dependenceMap),
onError: (e: Error) => {
alert(`load dependence error`);
console.error(e);
}
})
],
plugins: [...(isIframe ? [new IframePlugin()] : []), new FramePlugin()],
onError: (e: Error) => {
console.error(e);
alert(`error`);
Expand Down Expand Up @@ -121,3 +117,4 @@ app.getConfig = () => config;
app.history = history;

(window as any).app = app;
(window as any).mod = mod;
1 change: 1 addition & 0 deletions examples/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "ZxBing0066",
"license": "MIT",
"dependencies": {
"@rapiop/mod": "^0.0.8",
"@rapiop/rapiop": "latest",
"axios": "^0.19.0",
"history": "^4.9.0"
Expand Down
1 change: 1 addition & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "ZxBing0066",
"license": "MIT",
"dependencies": {
"@rapiop/mod": "^0.0.8",
"@rapiop/rapiop": "latest",
"axios": "^0.19.0",
"history": "^4.9.0"
Expand Down

0 comments on commit 2a20dd8

Please sign in to comment.