forked from decentraland/kernel-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
31 changed files
with
1,020 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
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,28 @@ | ||
import { useStore2 } from '../../jslibs/hooks/useStore2' | ||
import React, { useCallback } from 'react' | ||
import { commsStore } from './comms/store' | ||
import { GlobalChrome } from '../types/chrome' | ||
import { LineChart } from './comms/chart' | ||
|
||
declare var chrome: GlobalChrome | ||
|
||
export function Render(props: { panelWindow: Window }) { | ||
const test = useCallback(() => { | ||
chrome.devtools.inspectedWindow.eval(`window.postMessage( | ||
{ | ||
name: '[dcl-debugger:panel] Pong!', | ||
source: 'dcl-debugger', | ||
}, | ||
'*' | ||
)`) | ||
}, []) | ||
const [state] = useStore2(commsStore) | ||
return ( | ||
<div> | ||
<div style={{ color: 'white' }}>Render 5</div> | ||
<pre>{JSON.stringify(state, null, 2)}</pre> | ||
<button onClick={test}>Send Test `Ping`</button> | ||
<LineChart {...props} /> | ||
</div> | ||
) | ||
} |
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,24 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "comms", | ||
srcs = glob( | ||
include = [ | ||
"*.ts", | ||
"*.tsx", | ||
], | ||
), | ||
module_name = "@dcl/debugger/devtool/comms", | ||
deps = [ | ||
"//debugger/devtool/jslibs", | ||
"//debugger/types", | ||
"//jslibs/hooks", | ||
"@npm//redux", | ||
"@npm//react", | ||
"@npm//@types/react", | ||
"@npm//chart.js", | ||
"@npm//@types/chart.js", | ||
], | ||
) |
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,119 @@ | ||
import Chart from 'chart.js' | ||
import React, { useEffect, useLayoutEffect, useState } from 'react' | ||
import { useStore2 } from '../../../jslibs/hooks/useStore2' | ||
import { getCommsStore } from './store' | ||
|
||
function getContextFromCanvas(panelWindow: Window) { | ||
const document = panelWindow.document | ||
if (!document) { | ||
return | ||
} | ||
const canvas = panelWindow.document.getElementById('canvas') as HTMLCanvasElement | ||
if (canvas) { | ||
return canvas.getContext('2d') | ||
} | ||
} | ||
|
||
export function LineChart(props: { panelWindow: Window }) { | ||
const [state] = useStore2(getCommsStore()) | ||
const [context, setContext] = useState(null as CanvasRenderingContext2D | null) | ||
useEffect(() => { | ||
if (!context) { | ||
const tryContext = getContextFromCanvas(props.panelWindow) | ||
if (tryContext) { | ||
setContext(tryContext) | ||
} | ||
} | ||
}) | ||
const [myLine, setMyLine] = useState(null as Chart | null) | ||
useEffect(() => { | ||
if (context && !myLine) { | ||
setMyLine(new Chart(context, initialConfig)) | ||
} | ||
}, [context, myLine, setMyLine]) | ||
const [configChangeRequests, setChangeRequests] = useState([]) | ||
useLayoutEffect(() => { | ||
if (myLine && configChangeRequests.length) { | ||
for (let change of configChangeRequests) { | ||
change(initialConfig) | ||
} | ||
setChangeRequests([]) | ||
myLine.update() | ||
} | ||
}, [configChangeRequests, myLine, setChangeRequests]) | ||
return ( | ||
<ul> | ||
{state && | ||
state.history && | ||
state.history.map((_: any, index: number | string) => { | ||
return <li key={index}>{_.totalBytes}</li> | ||
})} | ||
</ul> | ||
) | ||
} | ||
|
||
export var MONTHS = [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
] | ||
var initialConfig = { | ||
type: 'line', | ||
data: { | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | ||
datasets: [ | ||
{ | ||
label: 'My First dataset', | ||
labels: MONTHS, | ||
backgroundColor: '#ffffff', | ||
borderColor: '#ff0000', | ||
data: [0.1, 0.2, 0.3, 0.25, 0.35, 0.5, 0.7], | ||
fill: false, | ||
}, | ||
{ | ||
label: 'My Second dataset', | ||
labels: MONTHS, | ||
fill: false, | ||
backgroundColor: '#0000ff', | ||
borderColor: '#0000ff', | ||
data: [0.15, 0.12, 0.26, 0.37, 0.29, 0.4, 0.65], | ||
}, | ||
], | ||
}, | ||
options: { | ||
responsive: true, | ||
title: { | ||
display: true, | ||
text: 'Chart.js Line Chart', | ||
}, | ||
scales: { | ||
xAxes: [ | ||
{ | ||
display: true, | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Month', | ||
}, | ||
}, | ||
], | ||
yAxes: [ | ||
{ | ||
display: true, | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Value', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} |
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,30 @@ | ||
import { | ||
CommsState, | ||
COMMS_REPORT, | ||
COMMS_DISCONNECTED, | ||
ReportAction, | ||
INITAL_COMMS_STATE, | ||
DisconnectedAction, | ||
} from './types' | ||
|
||
export function CommsReducer(state: CommsState, action: ReportAction | DisconnectedAction) { | ||
if (!action) { | ||
if (!state) { | ||
return INITAL_COMMS_STATE | ||
} | ||
return state | ||
} | ||
if (!state) { | ||
return CommsReducer(INITAL_COMMS_STATE, action) | ||
} | ||
switch (action.type) { | ||
case COMMS_DISCONNECTED: | ||
return {} | ||
case COMMS_REPORT: | ||
return { | ||
...action.payload, | ||
history: [action.payload, ...(state.history || [])].filter((_, index) => index < 10), | ||
} | ||
} | ||
return state | ||
} |
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
Oops, something went wrong.