refactor to remove new phoneme object constructor from Features function body

This commit is contained in:
Sorrel Bri 2019-11-29 15:05:33 -08:00
parent b83a11912e
commit bae5606257

View file

@ -12,24 +12,27 @@ const parseFeaturesFromPhonemeObject = phonemeObject => {
return Object.keys(featureMap).map(feature => <li key={`feature__${feature}`}>{`[+ ${feature}] = `}{featureMap[feature].join('|')}</li>); return Object.keys(featureMap).map(feature => <li key={`feature__${feature}`}>{`[+ ${feature}] = `}{featureMap[feature].join('|')}</li>);
} }
const getPhonemesFromFeatureSubmission = (props, newPhonemes, feature) => {
let newPhonemeObject = newPhonemes.split('/').reduce((phonemeObject, newPhoneme) => {
newPhoneme = newPhoneme.trim();
phonemeObject = phonemeObject[newPhoneme]
? {...phonemeObject, [newPhoneme]: [...phonemeObject[newPhoneme], feature]}
: {...phonemeObject, [newPhoneme]: [feature]}
return phonemeObject;
}, {...props.phonemes})
return newPhonemeObject;
}
const Features = (props) => { const Features = (props) => {
const [feature, setFeature] = useState('nasal') const [feature, setFeature] = useState('nasal')
const [newPhonemes, setNewPhonemes] = useState('n / m / ŋ') const [newPhonemes, setNewPhonemes] = useState('n / m / ŋ')
const newFeaturesSubmit = e => { const newFeaturesSubmit = e => {
e.preventDefault(); e.preventDefault();
let newPhonemeObject = newPhonemes.split('/').reduce((phonemeObject, newPhoneme) => { let newPhonemeObject = getPhonemesFromFeatureSubmission(props, newPhonemes, feature);
// console.log([...phonemeObject[newPhoneme], feature])
newPhoneme = newPhoneme.trim();
phonemeObject = phonemeObject[newPhoneme]
? {...phonemeObject, [newPhoneme]: [...phonemeObject[newPhoneme], feature]}
: {...phonemeObject, [newPhoneme]: [feature]}
return phonemeObject;
}, {...props.phonemes})
props.setPhonemes(newPhonemeObject); props.setPhonemes(newPhonemeObject);
setFeature(''); setFeature('');
setNewPhonemes(''); setNewPhonemes('');
} }