-
Notifications
You must be signed in to change notification settings - Fork 46.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Vaughn
committed
Dec 11, 2021
1 parent
555e871
commit 5f767f6
Showing
18 changed files
with
406 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!doctype html> | ||
<html> | ||
<body> | ||
<script src="dist/multi-left.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!doctype html> | ||
<html> | ||
<body> | ||
<script src="dist/multi-right.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf8"> | ||
<title>React DevTools</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> | ||
* { | ||
box-sizing: border-box; | ||
} | ||
body { | ||
display: flex; | ||
flex-direction: row; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, | ||
sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol; | ||
font-size: 12px; | ||
line-height: 1.5; | ||
} | ||
.column { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1 1 50%; | ||
} | ||
.column:first-of-type { | ||
border-right: 1px solid #3d424a; | ||
} | ||
.iframe { | ||
height: 50%; | ||
flex: 0 0 50%; | ||
border: none; | ||
} | ||
.devtools { | ||
height: 50%; | ||
flex: 0 0 50%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="column left-column"> | ||
<iframe src="multi-left.html" id="iframe-left" class="iframe"></iframe> | ||
<div id="devtools-left" class="devtools"></div> | ||
</div> | ||
<div class="column"> | ||
<iframe src="multi-right.html" id="iframe-right" class="iframe"></iframe> | ||
<div id="devtools-right" class="devtools"></div> | ||
</div> | ||
|
||
<script src="dist/multi-devtools.js"></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as React from 'react'; | ||
import {Component} from 'react'; | ||
import {createRoot} from 'react-dom'; | ||
import { | ||
activate as activateBackend, | ||
createBridge as createBackendBridge, | ||
initialize as initializeBackend, | ||
} from 'react-devtools-inline/backend'; | ||
import { | ||
createBridge as createFrontendBridge, | ||
createStore, | ||
initialize as createDevTools, | ||
} from 'react-devtools-inline/frontend'; | ||
|
||
function init(appIframe, devtoolsContainer) { | ||
const contentWindow = appIframe.contentWindow; | ||
|
||
// Wire each DevTools instance directly to its app. | ||
// By default, DevTools dispatches "message" events on the window, | ||
// but this means that only one instance of DevTools can live on a page. | ||
const wall = { | ||
_listeners: [], | ||
emit() {}, | ||
listen(listener) { | ||
wall._listeners.push(listener); | ||
}, | ||
send(event, payload) { | ||
wall._listeners.forEach(listener => listener({event, payload})); | ||
}, | ||
}; | ||
|
||
const backendBridge = createBackendBridge(contentWindow, wall); | ||
|
||
// TODO (sandpack) There is a race condition here. | ||
// We don't want to initialize the backend too soon because the Store might miss tree operations. | ||
// But we can't wait so late to initialize it without risking missing the "getBridgeProtocol" message. | ||
// The best backwards-compatible fix would be to change the timing of when we ask for the bridge protocol? | ||
|
||
initializeBackend(contentWindow); | ||
|
||
// Call this only once the frontend has been initialized. | ||
class InitializeBackendOnMount extends Component { | ||
componentDidMount() { | ||
activateBackend(contentWindow, {bridge: backendBridge}); | ||
} | ||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
const frontendBridge = createFrontendBridge(contentWindow, wall); | ||
const store = createStore(frontendBridge); | ||
const DevTools = createDevTools(contentWindow, { | ||
bridge: frontendBridge, | ||
store, | ||
}); | ||
|
||
createRoot(devtoolsContainer).render( | ||
<InitializeBackendOnMount> | ||
<DevTools /> | ||
</InitializeBackendOnMount>, | ||
); | ||
} | ||
|
||
const appIframeLeft = document.getElementById('iframe-left'); | ||
const appIframeRight = document.getElementById('iframe-right'); | ||
const devtoolsContainerLeft = document.getElementById('devtools-left'); | ||
const devtoolsContainerRight = document.getElementById('devtools-right'); | ||
|
||
init(appIframeLeft, devtoolsContainerLeft); | ||
init(appIframeRight, devtoolsContainerRight); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as React from 'react'; | ||
import {useState} from 'react'; | ||
import {createRoot} from 'react-dom'; | ||
|
||
function createContainer() { | ||
const container = document.createElement('div'); | ||
|
||
((document.body: any): HTMLBodyElement).appendChild(container); | ||
|
||
return container; | ||
} | ||
|
||
function StatefulCounter() { | ||
const [count, setCount] = useState(0); | ||
const handleClick = () => setCount(count + 1); | ||
return <button onClick={handleClick}>Count {count}</button>; | ||
} | ||
|
||
createRoot(createContainer()).render(<StatefulCounter />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import {useLayoutEffect, useRef, useState} from 'react'; | ||
import {render} from 'react-dom'; | ||
|
||
function createContainer() { | ||
const container = document.createElement('div'); | ||
|
||
((document.body: any): HTMLBodyElement).appendChild(container); | ||
|
||
return container; | ||
} | ||
|
||
function EffectWithState() { | ||
const [didMount, setDidMount] = useState(0); | ||
|
||
const renderCountRef = useRef(0); | ||
renderCountRef.current++; | ||
|
||
useLayoutEffect(() => { | ||
if (!didMount) { | ||
setDidMount(true); | ||
} | ||
}, [didMount]); | ||
|
||
return ( | ||
<ul> | ||
<li>Rendered {renderCountRef.current} times</li> | ||
{didMount && <li>Mounted!</li>} | ||
</ul> | ||
); | ||
} | ||
|
||
render(<EffectWithState />, createContainer()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const baseConfig = require('./webpack.config-base.js'); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
entry: { | ||
app: './src/app/index.js', | ||
'app-devtools': './src/app/devtools.js', | ||
'multi-left': './src/multi/left.js', | ||
'multi-devtools': './src/multi/devtools.js', | ||
'multi-right': './src/multi/right.js', | ||
}, | ||
devServer: { | ||
hot: true, | ||
port: 8080, | ||
clientLogLevel: 'warning', | ||
publicPath: '/dist/', | ||
stats: 'errors-only', | ||
}, | ||
}; |
Oops, something went wrong.