clean unused useState hooks from PCA component

This commit is contained in:
Sorrel Bri 2020-02-21 16:14:20 -08:00
parent eb551a3fce
commit 745fd3b899
3 changed files with 12 additions and 33 deletions

View file

@ -1,16 +1,14 @@
import React, { useState, useReducer } from 'react'; import React, { useState, useReducer } from 'react';
import './PhonoChangeApplier.scss'; import './PhonoChangeApplier.scss';
// import ls from 'local-storage';
import ProtoLang from './components/ProtoLang'; import ProtoLang from './components/ProtoLang';
import Features from './components/Features'; import Features from './components/Features';
import Epochs from './components/Epochs'; import Epochs from './components/Epochs';
import Options from './components/Options'; import Options from './components/Options';
import Output from './components/Output'; import Output from './components/Output';
import {stateReducer} from './reducers/reducer'; import { stateReducer } from './reducers/reducer';
import {initState} from './reducers/reducer.init'; import { initState } from './reducers/reducer.init';
const PhonoChangeApplier = () => { const PhonoChangeApplier = () => {
const [ state, dispatch ] = useReducer( const [ state, dispatch ] = useReducer(
@ -18,26 +16,8 @@ const PhonoChangeApplier = () => {
{}, {},
initState initState
) )
// ! DONE const { lexicon, phones, phonemes, epochs, options, features, results } = state;
const [ lexicon, setLexicon ] = useState(['mun', 'tʰu', 'tɯm', 'utʰ']);
const [ phonemes, setPhonemes ] = useState(
{
n: [ 'occlusive', 'sonorant', 'obstruent', 'nasal', 'alveolar' ],
m: [ 'occlusive', 'sonorant', 'obstruent', 'nasal', 'bilabial' ],
u: [ 'continuant', 'sonorant', 'syllabic', 'high', 'back', 'rounded' ],
ɯ: [ 'continuant', 'sonorant', 'syllabic', 'high', 'back', 'unrounded' ],
t: [ 'occlusive', 'plosive', 'obstruent', 'alveolar' ],
: [ 'occlusive', 'plosive', 'obstruent', 'alveolar', 'aspirated' ],
}
);
const [ epochs, setEpochs ] = useState([{name: 'epoch 1', changes:['[+ rounded]>[- rounded + unrounded]/_#']}]);
const [ options, setOptions ] = useState({output: 'default', save: false})
const [ features, setFeatures ] = useState(
['occlusive', 'sonorant', 'obstruent', 'nasal', 'alveolar','bilabial',
'continuant','syllabic','high','back','rounded','unrounded', 'plosive','aspirated'])
// ! UNDONE // ! UNDONE
const [ results, setResults ] = useState([])
const [ errors, setErrors ] = useState({}) const [ errors, setErrors ] = useState({})
const runChanges = e => { const runChanges = e => {
@ -82,11 +62,8 @@ const PhonoChangeApplier = () => {
} }
startingIndex = index; startingIndex = index;
}) })
// lexemeBundle.unshift(['#'])
// lexemeBundle.push(['#'])
lexicalFeatureBundles.push(lexemeBundle); lexicalFeatureBundles.push(lexemeBundle);
}) })
console.log(lexicalFeatureBundles)
// decompose rules // decompose rules
let allEpochs = epochs.map(epoch => { let allEpochs = epochs.map(epoch => {
@ -101,7 +78,6 @@ const PhonoChangeApplier = () => {
return {epoch: epoch.name, rules: ruleBundle} return {epoch: epoch.name, rules: ruleBundle}
}) })
console.log(allEpochs)
// apply sound changes // apply sound changes
allEpochs.reduce((diachronicLexicon, epoch) => { allEpochs.reduce((diachronicLexicon, epoch) => {
let startingLexicon = diachronicLexicon.length let startingLexicon = diachronicLexicon.length
@ -122,11 +98,11 @@ const PhonoChangeApplier = () => {
return ( return (
<div className="PhonoChangeApplier" data-testid="PhonoChangeApplier"> <div className="PhonoChangeApplier" data-testid="PhonoChangeApplier">
<ProtoLang lexicon={state.lexicon} dispatch={dispatch}/> <ProtoLang lexicon={lexicon} dispatch={dispatch}/>
<Features phones={state.phones} features={state.features} dispatch={dispatch}/> <Features phones={phones} features={features} dispatch={dispatch}/>
<Epochs epochs={state.epochs} dispatch={dispatch} /> <Epochs epochs={epochs} dispatch={dispatch} />
<Options options={state.options} dispatch={dispatch}/> <Options options={options} dispatch={dispatch}/>
<Output results={state.results} dispatch={dispatch}/> <Output results={results} dispatch={dispatch}/>
</div> </div>
); );
} }

View file

@ -16,7 +16,7 @@ export const initState = (changesArgument: number): stateType => {
'[+ sonorant - low rounded high back]>0/._.', '[+ sonorant - low rounded high back]>0/._.',
'[+ obstruent]>[+ obstruent aspirated ]/#_.', '[+ obstruent]>[+ obstruent aspirated ]/#_.',
'[+ sonorant - rounded]>[+ sonorant + rounded]/._#', '[+ sonorant - rounded]>[+ sonorant + rounded]/._#',
'at>ta/._#' // 'at>ta/._#'
] ]
} }
], ],

View file

@ -259,6 +259,7 @@ export const run = (state: stateType, action: resultsAction): stateType => {
// TODO iterate through each epoch // TODO iterate through each epoch
try { try {
console.log('running results')
const passResults = state.epochs.reduce((results, epoch, _) => { const passResults = state.epochs.reduce((results, epoch, _) => {
const { phones, features, lexicon } = state; const { phones, features, lexicon } = state;
let lexiconBundle; let lexiconBundle;
@ -276,8 +277,10 @@ export const run = (state: stateType, action: resultsAction): stateType => {
}, []); }, []);
const results = passResults.map(stringifyResults); const results = passResults.map(stringifyResults);
console.log(results)
return {...state, results } return {...state, results }
} catch (err) { } catch (err) {
console.log(err)
return {...state, errors: err }; return {...state, errors: err };
} }
} }