-
Notifications
You must be signed in to change notification settings - Fork 30
Initial commit of component render classes. #8
Changes from 1 commit
0638019
e5d96a8
8500f7e
dad1c8b
3c4c4fe
2a0e894
6bc9a3e
db0fa11
939dbf7
f5d12f7
9ff18a0
2840c31
9bde50b
be4a5d8
bef5a8e
5d548ad
f791971
95e2423
fffa746
e1ea4fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,8 @@ | |
import "./overlay/styles.less"; | ||
import * as React from "react"; | ||
import * as ReactDOM from "react-dom"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately React does not have a default export specified, and therefore your suggestion won't work in typescript. I'm importing as per Typescript documentation on working with React here: https://www.typescriptlang.org/docs/handbook/react-&-webpack.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know! I've always used Babel, which converts CommonJS modules to use default exports automatically. |
||
import { Constants as CONST, CSS } from "../lib/Constants"; | ||
import { KeyCode, KeyEvent, CSS } from "../lib/Constants"; | ||
import { Messaging } from "../lib/Messaging"; | ||
import { Options } from "./overlay/Options"; | ||
import { Overlay } from "./overlay/Overlay"; | ||
import { Variable } from "../core/variables/Variable"; | ||
import { remixer } from "../core/Remixer"; | ||
|
@@ -28,69 +27,35 @@ import { remixer } from "../core/Remixer"; | |
* Interface for the properties assigned to the DOMController component. | ||
* @interface | ||
*/ | ||
interface ControllerProps { | ||
wrapperElement: HTMLElement; | ||
} | ||
interface ControllerProps { wrapperElement: HTMLElement; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modifying a parent in a child is an antipattern in React; are you going to fix this in #12? It would be pretty simple to change |
||
|
||
/** | ||
* Interface for the state of the DOMController component. | ||
* @interface | ||
*/ | ||
interface ControllerState { | ||
/** | ||
* The DOMController will render a control component for each of the variables | ||
* of this array. | ||
* @type {Array<Variable>} | ||
*/ | ||
variables?: Array<Variable>; | ||
|
||
/** | ||
* The current route to render. | ||
* @type {Route} | ||
*/ | ||
route?: Route; | ||
} | ||
|
||
/** | ||
* Available routes to render. | ||
*/ | ||
enum Route { | ||
Variables, | ||
Options | ||
} | ||
interface ControllerState { variables?: Array<Variable>; } | ||
|
||
/** | ||
* A React component class that renders an MDL-styled card containing child | ||
* components determined by its current Route. | ||
* | ||
* Depending on the Route, the card content can be either: | ||
* 1) The overlay with configurable control components per assigned Variables. | ||
* 2) An options page used to configure Remixer session properties. | ||
* | ||
* Renders an MDL card-styled overlay containing a child control for each | ||
* variable. | ||
* @class | ||
* @extends React.Component | ||
*/ | ||
export class DOMController extends React.Component<ControllerProps, ControllerState> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component it trying to do too many things. See my advice in #12. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! After we land this I will do some refactoring per #12. |
||
|
||
state = { | ||
variables: remixer.attachedInstance.variablesArray, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be in |
||
route: Route.Variables | ||
}; | ||
|
||
/** | ||
* The component will mount. Lets register for messaging and key events. | ||
* @override | ||
*/ | ||
/** @override */ | ||
componentDidMount() { | ||
// Register for messaging and key events. | ||
Messaging.register(this.onMessageReceived.bind(this)); | ||
this.addKeyListener(); | ||
} | ||
|
||
/** | ||
* The component will unmount. Lets unregister. | ||
* @override | ||
*/ | ||
/** @override */ | ||
componentWillUnmount() { | ||
// Unregister for messaging and key events. | ||
Messaging.unregister(); | ||
this.removeKeyListener(); | ||
} | ||
|
@@ -107,56 +72,31 @@ export class DOMController extends React.Component<ControllerProps, ControllerSt | |
|
||
/** Adds a key listener. */ | ||
addKeyListener(): void { | ||
document.addEventListener(CONST.KEY_EVENT_DOWN, (e: KeyboardEvent) => { | ||
if (e.keyCode === CONST.KEY_CODE_ESC) { | ||
document.addEventListener(KeyEvent.DOWN, (e: KeyboardEvent) => { | ||
if (e.keyCode === KeyCode.ESC) { | ||
this.toggleVisibility(); | ||
} | ||
}); | ||
} | ||
|
||
/** Removes a key listener. */ | ||
removeKeyListener(): void { | ||
document.removeEventListener(CONST.KEY_EVENT_DOWN); | ||
document.removeEventListener(KeyEvent.DOWN); | ||
} | ||
|
||
/** Toggles the Remixer overlay visibility. */ | ||
toggleVisibility() { | ||
this.props.wrapperElement.classList.toggle(CSS.VISIBLE); | ||
this.props.wrapperElement.classList.toggle(CSS.RMX_VISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I've asked this in every review and haven't seen any comments/changes. Maybe the comments got lost in the GitHub UI? Why are you mutating the DOM of an element this component doesn't control? Couldn't this just be: toggleVisibility() {
this.setState({
isVisible: !this.props.isVisible,
}})
}
render() {
const {
isVisible,
variables,
updateVariable,
} = this.props;
if (this.props.isVisible) {
return (
// your DOM tree
)
} else {
return <div />;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we chatted about this. Its part of #12. Just never made that change. |
||
} | ||
|
||
/** | ||
* Updates the state to new route. | ||
* @param {Event} event The route to update to. | ||
*/ | ||
updateRoute(event: Event) { | ||
const currentRoute = this.state.route; | ||
this.setState({ | ||
route: currentRoute === Route.Variables | ||
? Route.Options | ||
: Route.Variables | ||
}); | ||
} | ||
|
||
/** | ||
* Renders the component via React. | ||
* @override | ||
*/ | ||
/** @override */ | ||
render() { | ||
const CurrentRoute = this.state.route === Route.Options ? Options : Overlay; | ||
return ( | ||
<div className="rmx-card-wide mdl-card mdl-shadow--6dp"> | ||
<div className="mdl-card mdl-shadow--6dp"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you use string literals in some places and groups of |
||
<div className="mdl-card__title" ref="myInput"> | ||
<h2 className="mdl-card__title-text">Remixer</h2> | ||
|
||
</div> | ||
<div className="mdl-card__menu"> | ||
<button className="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect" | ||
onClick={this.updateRoute.bind(this)}> | ||
<i className="material-icons">menu</i> | ||
</button> | ||
</div> | ||
<div className="mdl-card__supporting-text mdl-card__actions mdl-card--border"> | ||
{/*}<CurrentRoute variables={this.state.variables} />*/} | ||
<Overlay variables={this.state.variables} /> | ||
</div> | ||
</div> | ||
|
@@ -167,5 +107,5 @@ export class DOMController extends React.Component<ControllerProps, ControllerSt | |
/** | ||
* Renders the DOMController component to the overlay wrapper element. | ||
*/ | ||
let element = document.getElementById(CONST.ID_OVERLAY_WRAPPER); | ||
let element = document.getElementById(CSS.RMX_OVERLAY_WRAPPER); | ||
ReactDOM.render(<div><DOMController wrapperElement={element} /></div>, element); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a bit easier to read if you named it something camel-cased, like
StyleClassName
orCSSClassName
.