Skip to content
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

feat: 新增hel微模块示例 #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/react16/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"eslint-webpack-plugin": "^3.1.1",
"file-loader": "^6.2.0",
"fs-extra": "^10.0.0",
"hel-lodash": "^2.1.7",
"hel-micro": "^4.8.11",
"hel-micro-core": "^4.8.11",
"hel-micro-react": "^4.8.10",
"hel-types": "^4.3.3",
"html-webpack-plugin": "^5.5.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.4.3",
Expand Down
11 changes: 10 additions & 1 deletion examples/react16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Location from "./Location";
import Communication from "./Communication";
import React17 from "./nest";
import Font from "./Font";
import RemoteComp from "./RemoteComp";
import RemoteFnCall from "./RemoteFnCall";
import logo from "./logo.svg";
import Tag from "antd/es/tag";
import Button from "antd/es/button";
Expand Down Expand Up @@ -49,7 +51,8 @@ export default function App() {
<nav>
<NavLink to="/home">首页</NavLink> | <NavLink to="/dialog">弹窗</NavLink> |{" "}
<NavLink to="/location">路由</NavLink> | <NavLink to="/communication">通信</NavLink> |{" "}
<NavLink to="/nest">内嵌</NavLink> | <NavLink to="/font">字体</NavLink>
<NavLink to="/nest">内嵌</NavLink> | <NavLink to="/font">字体</NavLink> |{" "}
<NavLink to="/remote-comp">远程组件</NavLink>| <NavLink to="/remote-fn">远程方法</NavLink>
</nav>

<div>
Expand All @@ -75,6 +78,12 @@ export default function App() {
<Route path="/font">
<Font />
</Route>
<Route path="/remote-comp">
<RemoteComp />
</Route>
<Route path="/remote-fn">
<RemoteFnCall />
</Route>
<Route exact path="/">
<Redirect to="/home" />
</Route>
Expand Down
17 changes: 17 additions & 0 deletions examples/react16/src/RemoteComp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { useRemoteComp } from 'hel-micro-react';

export default function RemoteComp() {
const Comp = useRemoteComp(
// see https://github.com/hel-e co/hel-tpl-remote-react-comp
"hel-tpl-remote-react-comps",
// see https://github.com/hel-eco/hel-tpl-remote-react-comp-ts
// "hel-tpl-remote-react-comps-ts",
"HelloRemoteReactComp",
{ versionId: "1.3.2" }
);
return <div>
<h1>这是一个懒加载的远程react组件</h1>
<Comp />
</div>;
}
19 changes: 19 additions & 0 deletions examples/react16/src/RemoteFnCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import m from 'hel-lodash';

export default function RemoteComp() {
const [tip, setTip] = React.useState('');
const changeTip = () => {
setTip(`${m.myUtils.myMod.sayHelloToHel()}_${Date.now()}`);
};


return <div>
<h1>这是一个预加载的远程方法调用示例:</h1>
<h2>lodash version is: {m.VERSION}</h2>
<h2>tip is: {tip}</h2>
<button onClick={changeTip} style={{ color: "red", fontSize: "28px" }}>
click me to see changed result{" "}
</button>
</div>;
}
31 changes: 6 additions & 25 deletions examples/react16/src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { BrowserRouter } from "react-router-dom";
import "./styles.css";
import { bindReactRuntime, preFetchLib } from 'hel-micro';

const basename = process.env.NODE_ENV === "production" ? "/demo-react16/" : "";
bindReactRuntime({ React, ReactDOM });

if (window.__POWERED_BY_WUJIE__) {
// eslint-disable-next-line no-undef
window.__WUJIE_MOUNT = () => {
ReactDOM.render(
<BrowserRouter basename={basename}>
<App />
</BrowserRouter>,
document.getElementById("root")
);
};
window.__WUJIE_UNMOUNT = () => {
ReactDOM.unmountComponentAtNode(document.getElementById("root"));
};
} else {
ReactDOM.render(
<BrowserRouter basename={basename}>
<App />
</BrowserRouter>,
document.getElementById("root")
);
}
(async function () {
await preFetchLib('hel-lodash','2.3.0'); // 预加载 hel-lodash,方便其他地方可以静态导入 hel-lodash
await import('./loadApp');
})().catch(console.error);
30 changes: 30 additions & 0 deletions examples/react16/src/loadApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { BrowserRouter } from "react-router-dom";
import "./styles.css";

const basename = process.env.NODE_ENV === "production" ? "/demo-react16/" : "";

if (window.__POWERED_BY_WUJIE__) {
// eslint-disable-next-line no-undef
window.__WUJIE_MOUNT = () => {
ReactDOM.render(
<BrowserRouter basename={basename}>
<App />
</BrowserRouter>,
document.getElementById("root")
);
};
window.__WUJIE_UNMOUNT = () => {
ReactDOM.unmountComponentAtNode(document.getElementById("root"));
};
window.__WUJIE.mount();
} else {
ReactDOM.render(
<BrowserRouter basename={basename}>
<App />
</BrowserRouter>,
document.getElementById("root")
);
}
120 changes: 105 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.