This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
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
14 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
"https://stadia.google.com/*" | ||
], | ||
"js": [ | ||
"dist/index.js" | ||
"dist/main/index.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 |
---|---|---|
@@ -1,29 +1,74 @@ | ||
import Internal from '../decorators/@Internal'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Logger from '../Logger'; | ||
import Util from '../Util'; | ||
|
||
export default class AbstractComponent { | ||
export interface DefaultProps { | ||
|
||
} | ||
|
||
export interface DefaultState { | ||
renderer: HTMLElement | null | ||
} | ||
|
||
export default class AbstractComponent<A extends DefaultProps, B extends DefaultState> extends React.Component<A, B> { | ||
|
||
public __useReact = false; | ||
public name: string; | ||
public renderer: HTMLElement | null = null; | ||
|
||
constructor(name: string) { | ||
this.name = name; | ||
constructor(data: { props?: A, name: string }) { | ||
super(data.props !== undefined ? data.props : {} as A); | ||
this.name = data.name; | ||
|
||
// TODO: Not safe, find better solution | ||
this.state = { | ||
renderer: null | ||
} as B | ||
|
||
this.__start(); | ||
setInterval(() => this.__tick(), 1000); | ||
} | ||
|
||
@Internal('onStart') | ||
public async __start() { | ||
Logger.component(`Component ${this.name} has been enabled`); | ||
this.onStart(); | ||
} | ||
|
||
@Internal('onUpdate') | ||
public async __tick() {} | ||
public async __tick() { | ||
console.log("tick"); | ||
this.onUpdate(); | ||
} | ||
|
||
public async updateRenderer() { | ||
await Util.updateRenderer(); | ||
this.renderer = Util.renderer; | ||
if (this.__useReact) { | ||
this.setState(state => ({ renderer: Util.renderer })); | ||
} | ||
} | ||
|
||
/** | ||
* @deprecated React render function, only override this if you're 100% sure you know what you're doing. | ||
* @see onRender | ||
*/ | ||
render() { | ||
if (!this.__useReact) return null; | ||
|
||
if (this.state.renderer !== null) { | ||
const renderData = this.onRender(); | ||
if(renderData === null) return null; | ||
|
||
const target = this.state.renderer.querySelector(renderData.query); | ||
if (target !== null) { | ||
return ReactDOM.createPortal( | ||
renderData.node, | ||
<Element>this.state.renderer.querySelector(renderData.query), | ||
); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
async onStart(): Promise<void> {} | ||
async onUpdate(): Promise<void> {} | ||
onRender(): { query: string, node: React.ReactNode } | null { return null } | ||
} |
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,26 @@ | ||
import React from 'react'; | ||
import AbstractComponent, { DefaultProps, DefaultState } from './AbstractComponent'; | ||
import ReactComponent from '../decorators/@ReactComponent'; | ||
|
||
@ReactComponent | ||
export default class TestComponent extends AbstractComponent<DefaultProps, DefaultState> { | ||
constructor() { | ||
super({ name: "Test Component" }); | ||
} | ||
|
||
async onStart(): Promise<void> {} | ||
|
||
async onUpdate(): Promise<void> { | ||
this.updateRenderer(); | ||
console.log(this.__useReact); | ||
} | ||
|
||
onRender(): { query: string; node: React.ReactNode } { | ||
return { | ||
query: '.CVVXfc', | ||
node: <button>Test Button</button> | ||
} | ||
} | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default function ReactComponent<T extends { new (...args: any[]): {} }>(constructor: T) { | ||
return class extends constructor { | ||
__useReact = true | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import TestComponent from './components/TestComponent'; | ||
import Util from './Util'; | ||
|
||
console.log("main2"); | ||
|
||
window.addEventListener('load', async () => { | ||
await Util.updateRenderer(); | ||
|
||
const root = document.createElement('div'); | ||
document.body.appendChild(root) | ||
|
||
ReactDOM.render( | ||
<div> | ||
<TestComponent/> | ||
</div>, | ||
root | ||
) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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