Skip to content

Commit

Permalink
add dev field
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed May 14, 2024
1 parent 74596b4 commit 455ccb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/myreact-dom/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
enableEventSystem,
enableEventTrack,
enableHighlight,
injectDevField,
} from "../shared";

import { render, hydrate, hydrateRoot, createRoot } from "./mount";
Expand All @@ -34,6 +35,8 @@ initGlobalRenderPlatform();
// not need for new refresh runtime package
// initGlobalHMR();

injectDevField();

checkReconcilerVersion();

checkMyReactVersion();
Expand Down
9 changes: 9 additions & 0 deletions packages/myreact-dom/src/shared/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type DevToolRuntime = (dispatch: CustomRenderDispatch, platform: CustomRe
export const setDevTools = (devToolRuntime: DevToolRuntime, dispatch: CustomRenderDispatch, platform: CustomRenderPlatform) => {
try {
devToolRuntime(dispatch, platform, initHMR);
delete globalThis[DEV_INJECT_FIELD];
} catch (e) {
if (__DEV__) {
console.error("devToolRuntime failed:", e);
Expand All @@ -19,8 +20,16 @@ export const DEV_TOOL_RUNTIME_FIELD = "__MY_REACT_DEVTOOL_RUNTIME__";

export const DISPATCH_FIELD = "__@my-react/dispatch__";

const DEV_INJECT_FIELD = "__@my-react/react-inject__";

const DEV_REFRESH_FIELD = "__@my-react/react-refresh__";

export const injectDevField = () => {
if (__DEV__ && typeof globalThis !== "undefined") {
globalThis[DEV_INJECT_FIELD] = setDevTools;
}
};

export const autoSetDevTools = (dispatch: CustomRenderDispatch, platform: CustomRenderPlatform) => {
const runtime = globalThis[DEV_TOOL_RUNTIME_FIELD];

Expand Down

0 comments on commit 455ccb2

Please sign in to comment.