Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ES2015 classes for subcomponents instead of imported render functions #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/components/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

import Render from './AppRender';
import AppRender from './AppRender';

import { Component } from 'react';

export default class App extends Component {
render () {
return Render.call(this, this.props, this.state);
return <AppRender />;
}
}
29 changes: 16 additions & 13 deletions src/common/components/AppRender.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ import Formulae from './Formulae';
import Keyboard from './Keyboard';

import React, {
Component,
StyleSheet,
View
} from 'react-native';

export default function () {
return (
<View style={styles.container}>
<View style={styles.screen} >
<Screen />
export default class AppRender extends Component {
Render () {
return (
<View style={styles.container}>
<View style={styles.screen} >
<Screen />
</View>
<View style={styles.formulae}>
<Formulae />
</View>
<View style={styles.keyboard}>
<Keyboard />
</View>
</View>
<View style={styles.formulae}>
<Formulae />
</View>
<View style={styles.keyboard}>
<Keyboard />
</View>
</View>
);
);
}
}

var styles = StyleSheet.create({
Expand Down
20 changes: 11 additions & 9 deletions src/common/components/AppRender.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';

import React from 'react';
import React, { Component } from 'react';
import Screen from './Screen';
import Formulae from './Formulae';
import Keyboard from './Keyboard';

export default function () {
return (
<div className='main'>
<Screen />
<Formulae />
<Keyboard />
</div>
);
export default class AppRender extends Component () {
Render () {
return (
<div className='main'>
<Screen />
<Formulae />
<Keyboard />
</div>
);
}
}
8 changes: 2 additions & 6 deletions src/common/components/Formulae.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
'use strict';

import Base from './FormulaeBase';
import Render from './FormulaeRender';
import FormulaeRender from './FormulaeRender';

export default class Formulae extends Base {
constructor (props) {
super(props);
}

render () {
return Render.call(this, this.props, this.state);
return <FormulaeRender />;
}
}
23 changes: 13 additions & 10 deletions src/common/components/FormulaeRender.ios.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
'use strict';

import React, {
Component,
StyleSheet,
Text,
View,
TouchableHighlight
} from 'react-native';

export default function (props, state) {
return (
<View style={styles.formulae}>
{this.state.displayFormulae.map(function(formula) {
return <TouchableHighlight style={getFormulaStyles(formula.operator)} onPress={this.handleClick.bind(this, formula)} underlayColor='#cdcdcd'>
<Text style={styles.text}>{formula.literal}</Text>
</TouchableHighlight>
}, this)}
</View>
);
export default class FormulaeRender extends Component {
Render () {
return (
<View style={styles.formulae}>
{this.state.displayFormulae.map(function(formula) {
return <TouchableHighlight style={getFormulaStyles(formula.operator)} onPress={this.handleClick.bind(this, formula)} underlayColor='#cdcdcd'>
<Text style={styles.text}>{formula.literal}</Text>
</TouchableHighlight>
}, this)}
</View>
);
}
}

var getFormulaStyles = function(operator) {
Expand Down
18 changes: 10 additions & 8 deletions src/common/components/FormulaeRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import React from 'react';

export default function (props, state) {
return (
<div className='formulae'>
{state.displayFormulae.map(function(formula) {
return <span key={formula.id} onClick={this.handleClick.bind(this, formula)} className={this.dynamicClass(formula.operator)}>{formula.literal}</span>
}, this)}
</div>
);
export default class FormulaeRender extends Component {
Render () {
return (
<div className='formulae'>
{state.displayFormulae.map(function(formula) {
return <span key={formula.id} onClick={this.handleClick.bind(this, formula)} className={this.dynamicClass(formula.operator)}>{formula.literal}</span>
}, this)}
</div>
);
}
}
8 changes: 2 additions & 6 deletions src/common/components/Key.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
'use strict';

import Base from './KeyBase';
import Render from './KeyRender';
import KeyRender from './KeyRender';

export default class Key extends Base {
constructor (props) {
super(props);
}

render () {
return Render.call(this, this.props, this.state);
return <KeyRender />;
}
}
65 changes: 34 additions & 31 deletions src/common/components/KeyRender.ios.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
'use strict';

import React, {
Component,
StyleSheet,
Text,
View,
TouchableHighlight
} from 'react-native';

export default function () {
if(this.props.keyType === 'number') {
return (
<View style={styles.keyNumber}>
<TouchableHighlight style={styles.button} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={styles.textButton}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
} else if(this.props.keyType === 'operator') {
return (
<View style={styles.keyOperator}>
<TouchableHighlight style={getOperatorStyles(this.props.keyValue)} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={styles.textButtonOperator}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
} else if(this.props.keyType === 'action') {
return (
<View style={styles.keyAction}>
<TouchableHighlight style={getActionStyles(this.props.keyValue)} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={getActionButtonStyles(this.props.keyValue)}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
export default class KeyRender extends Component {
Render () {
if(this.props.keyType === 'number') {
return (
<View style={styles.keyNumber}>
<TouchableHighlight style={styles.button} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={styles.textButton}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
} else if(this.props.keyType === 'operator') {
return (
<View style={styles.keyOperator}>
<TouchableHighlight style={getOperatorStyles(this.props.keyValue)} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={styles.textButtonOperator}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
} else if(this.props.keyType === 'action') {
return (
<View style={styles.keyAction}>
<TouchableHighlight style={getActionStyles(this.props.keyValue)} onPress={this.handleClick} underlayColor='#cdcdcd'>
<Text style={getActionButtonStyles(this.props.keyValue)}>
{this.props.keySymbol}
</Text>
</TouchableHighlight>
</View>
);
}
}
}

Expand Down
64 changes: 33 additions & 31 deletions src/common/components/KeyRender.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
'use strict';

import React from 'react';
import React, { Component } from 'react';

export default function (props, state) {
var classString = 'key key-' + props.keyType;
if(state.isHighlighted) {
classString += ' highlight';
}
var classOperation = '';
if(props.keyType === 'operator') {
classOperation = 'operator ' + props.keyValue;
}
if(props.keyType === 'action') {
classOperation = 'action ' + props.keyValue;
}
if(props.keyType === 'number') {
return (
<div className={classString}
onClick={this.handleClick}
onMouseDown={this.onMouseDown}
onMouseUp={this.onMouseUp}>
<div className={classOperation}>{props.keySymbol}</div>
</div>
);
} else {
return (
<div className={classString}>
<div className={classOperation}
onClick={this.handleClick}
onMouseDown={this.onMouseDown}
onMouseUp={this.onMouseUp}>{props.keySymbol}</div>
</div>
);
export default class KeyRender extends Component {
Render () {
var classString = 'key key-' + props.keyType;
if(state.isHighlighted) {
classString += ' highlight';
}
var classOperation = '';
if(props.keyType === 'operator') {
classOperation = 'operator ' + props.keyValue;
}
if(props.keyType === 'action') {
classOperation = 'action ' + props.keyValue;
}
if(props.keyType === 'number') {
return (
<div className={classString}
onClick={this.handleClick}
onMouseDown={this.onMouseDown}
onMouseUp={this.onMouseUp}>
<div className={classOperation}>{props.keySymbol}</div>
</div>
);
} else {
return (
<div className={classString}>
<div className={classOperation}
onClick={this.handleClick}
onMouseDown={this.onMouseDown}
onMouseUp={this.onMouseUp}>{props.keySymbol}</div>
</div>
);
}
}
}
4 changes: 2 additions & 2 deletions src/common/components/Keyboard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

import Render from './KeyboardRender';
import KeyboardRender from './KeyboardRender';

import { Component } from 'react';

export default class Keyboard extends Component {
render () {
return Render.call(this, this.props, this.state);
return <KeyboardRender />;
}
}
Loading