From 3f2b4e66189d706726d4de941febed174c413a95 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Fri, 21 Feb 2020 20:55:17 -0800 Subject: [PATCH] refactor components to remove unused useState hooks --- src/PhonoChangeApplier.js | 78 --------------------------------- src/components/Options.js | 18 ++++---- src/components/Output.js | 2 +- src/components/Output.test.js | 8 ++-- src/reducers/reducer.results.js | 3 -- 5 files changed, 15 insertions(+), 94 deletions(-) diff --git a/src/PhonoChangeApplier.js b/src/PhonoChangeApplier.js index 08db24e..6db5c4b 100644 --- a/src/PhonoChangeApplier.js +++ b/src/PhonoChangeApplier.js @@ -17,84 +17,6 @@ const PhonoChangeApplier = () => { initState ) const { lexicon, phones, phonemes, epochs, options, features, results } = state; - // ! UNDONE - const [ errors, setErrors ] = useState({}) - - const runChanges = e => { - e.preventDefault(); - - let ruleError = epochs.reduce((errorObject, epoch) => { - epoch.changes.map((change, index) => { - if (!change.match(/>.*\/.*_/)) { - errorObject[epoch.name] - ? errorObject[epoch.name].push(index) - : errorObject[epoch.name] = [index] - errorObject[epoch.name].ruleSyntaxError = true; - } - - // TODO validate phoneme syntax - let decomposedChange = change.split('>'); - decomposedChange = [decomposedChange[0], ...decomposedChange[1].split('/')] - decomposedChange = [decomposedChange[0], decomposedChange[1], ...decomposedChange[2].split('_')]; - - }) - return errorObject; - }, {}) - - - if (Object.entries(ruleError).length) return setErrors(ruleError) - setErrors({}); - - // decompose Lexical Items - // moving window on phonemes of each lexical item - let lexicalFeatureBundles = [] - lexicon.forEach(lexeme => { - let lexemeBundle = []; - let startingIndex = 0; - let lastIndex = lexeme.length - 1; - [...lexeme].forEach((_, index) => { - if (phonemes[lexeme.slice(startingIndex, index + 1)] && index !== lastIndex) return; - if (phonemes[lexeme.slice(startingIndex, index + 1)]) return lexemeBundle.push(phonemes[lexeme.slice(startingIndex)]) - if (index !== 0 && index !== lastIndex) lexemeBundle.push(phonemes[lexeme.slice(startingIndex, index)]) - if (index === lastIndex) { - lexemeBundle.push(phonemes[lexeme.slice(startingIndex, index)]) - lexemeBundle.push(phonemes[lexeme.slice(index)]) - } - startingIndex = index; - }) - lexicalFeatureBundles.push(lexemeBundle); - }) - - // decompose rules - let allEpochs = epochs.map(epoch => { - let ruleBundle = epoch.changes.map(rule => { - return { - input: rule.split('>')[0].replace(/\[|\]|\+/g, '').trim(), - result: rule.split('>')[1].split('/')[0], - preInput: rule.split('/')[1].split('_')[0].replace(/\[|\]|\+/g, '').trim(), - postInput: rule.split('/')[1].split('_')[1].replace(/\[|\]|\+/g, '').trim(), - } - }) - return {epoch: epoch.name, rules: ruleBundle} - }) - - // apply sound changes - allEpochs.reduce((diachronicLexicon, epoch) => { - let startingLexicon = diachronicLexicon.length - ? diachronicLexicon[diachronicLexicon.length - 1] - : lexicalFeatureBundles; - let currentRules = epoch.rules; - let resultingLexicon = startingLexicon.forEach(lexeme => { - currentRules.forEach(rule => { - let ruleEnvironment = [[rule.preInput], [rule.input], [rule.postInput]]; - console.log(ruleEnvironment) - }) - }) - diachronicLexicon.push(resultingLexicon) - },[]) - - // handle output - } return (
diff --git a/src/components/Options.js b/src/components/Options.js index dac6ca9..30997ef 100644 --- a/src/components/Options.js +++ b/src/components/Options.js @@ -2,13 +2,13 @@ import React, { useState } from 'react'; import './Options.scss'; import ls from 'local-storage'; -const Options = props => { +const Options = ({ options, dispatch }) => { const [ load, setLoad ] = useState(''); const handleRadioChange = e => { const option = e.target.name; const setValue = e.target.id; - props.dispatch({ + dispatch({ type: 'SET_OPTIONS', value: { option, @@ -20,7 +20,7 @@ const Options = props => { const handleCheckChange = e => { const option = e.target.name; const setValue = e.target.checked ? 'true' : 'false'; - props.dispatch({ + dispatch({ type: 'SET_OPTIONS', value: { option, @@ -31,7 +31,7 @@ const Options = props => { const handleFormSubmit = (e, options) => { e.preventDefault(); - props.dispatch({ + dispatch({ type: 'RUN', value: options }); @@ -41,13 +41,13 @@ const Options = props => {

Modeling Options

-
handleFormSubmit(e, props.options)} data-testid="Options-form"> + handleFormSubmit(e, options)} data-testid="Options-form"> {/*
Output
*/} handleRadioChange(e)} />