Abstract CharacterString for resuability

This commit is contained in:
Jordan Eldredge 2016-07-12 09:14:58 -07:00
parent 06482e6795
commit 389f5cb27d
3 changed files with 20 additions and 6 deletions

View file

@ -6,3 +6,4 @@ module.exports = (props) => {
return <div {...props} className={className}>{props.children}</div>;
};
// TODO: Require that props.children be a string

14
js/CharacterString.jsx Normal file
View file

@ -0,0 +1,14 @@
import React from 'react';
import Character from './Character.jsx';
module.exports = (props) => {
const text = '' + props.children;
const chars = text.split('');
return <div {...props}>
{chars.map(character => {
return <Character>{character}</Character>;
})};
</div>;
};
// TODO: Require that props.children be a string

View file

@ -2,7 +2,7 @@
import React from 'react';
import {connect} from 'react-redux';
import Character from './Character.jsx';
import CharacterString from './CharacterString.jsx';
class Marquee extends React.Component {
@ -45,11 +45,10 @@ class Marquee extends React.Component {
// TODO: Use the spread operator
chars = start.concat(end).slice(0, 30);
}
return <div onMouseDown={this.handleMouseDown}>
{chars.map(character => {
return <Character>{character}</Character>;
})};
</div>;
const text = chars.join('');
return <CharacterString onMouseDown={this.handleMouseDown}>
{text}
</CharacterString>;
}
}