From 389f5cb27df2c94288d289b43ef11139918dde3d Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 12 Jul 2016 09:14:58 -0700 Subject: [PATCH] Abstract CharacterString for resuability --- js/Character.jsx | 1 + js/CharacterString.jsx | 14 ++++++++++++++ js/Marquee.jsx | 11 +++++------ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 js/CharacterString.jsx diff --git a/js/Character.jsx b/js/Character.jsx index fa33c346..965d10e1 100644 --- a/js/Character.jsx +++ b/js/Character.jsx @@ -6,3 +6,4 @@ module.exports = (props) => { return
{props.children}
; }; +// TODO: Require that props.children be a string diff --git a/js/CharacterString.jsx b/js/CharacterString.jsx new file mode 100644 index 00000000..faa57133 --- /dev/null +++ b/js/CharacterString.jsx @@ -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
+ {chars.map(character => { + return {character}; + })}; +
; +}; + +// TODO: Require that props.children be a string diff --git a/js/Marquee.jsx b/js/Marquee.jsx index 080dca72..2f06277c 100644 --- a/js/Marquee.jsx +++ b/js/Marquee.jsx @@ -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
- {chars.map(character => { - return {character}; - })}; -
; + const text = chars.join(''); + return + {text} + ; } }