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 './PhonoChangeApplier.scss';
// import ls from 'local-storage';
import ProtoLang from './components/ProtoLang';
import Features from './components/Features';
import Epochs from './components/Epochs';
import Options from './components/Options';
import Output from './components/Output';
import {stateReducer} from './reducers/reducer';
import {initState} from './reducers/reducer.init';
import { stateReducer } from './reducers/reducer';
import { initState } from './reducers/reducer.init';
const PhonoChangeApplier = () => {
const [ state, dispatch ] = useReducer(
@ -18,26 +16,8 @@ const PhonoChangeApplier = () => {
{},
initState
)
// ! DONE
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'])
const { lexicon, phones, phonemes, epochs, options, features, results } = state;
// ! UNDONE
const [ results, setResults ] = useState([])
const [ errors, setErrors ] = useState({})
const runChanges = e => {
@ -82,11 +62,8 @@ const PhonoChangeApplier = () => {
}
startingIndex = index;
})
// lexemeBundle.unshift(['#'])
// lexemeBundle.push(['#'])
lexicalFeatureBundles.push(lexemeBundle);
})
console.log(lexicalFeatureBundles)
// decompose rules
let allEpochs = epochs.map(epoch => {
@ -101,7 +78,6 @@ const PhonoChangeApplier = () => {
return {epoch: epoch.name, rules: ruleBundle}
})
console.log(allEpochs)
// apply sound changes
allEpochs.reduce((diachronicLexicon, epoch) => {
let startingLexicon = diachronicLexicon.length
@ -122,11 +98,11 @@ const PhonoChangeApplier = () => {
return (
<div className="PhonoChangeApplier" data-testid="PhonoChangeApplier">
<ProtoLang lexicon={state.lexicon} dispatch={dispatch}/>
<Features phones={state.phones} features={state.features} dispatch={dispatch}/>
<Epochs epochs={state.epochs} dispatch={dispatch} />
<Options options={state.options} dispatch={dispatch}/>
<Output results={state.results} dispatch={dispatch}/>
<ProtoLang lexicon={lexicon} dispatch={dispatch}/>
<Features phones={phones} features={features} dispatch={dispatch}/>
<Epochs epochs={epochs} dispatch={dispatch} />
<Options options={options} dispatch={dispatch}/>
<Output results={results} dispatch={dispatch}/>
</div>
);
}

View file

@ -16,7 +16,7 @@ export const initState = (changesArgument: number): stateType => {
'[+ sonorant - low rounded high back]>0/._.',
'[+ obstruent]>[+ obstruent aspirated ]/#_.',
'[+ 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
try {
console.log('running results')
const passResults = state.epochs.reduce((results, epoch, _) => {
const { phones, features, lexicon } = state;
let lexiconBundle;
@ -276,8 +277,10 @@ export const run = (state: stateType, action: resultsAction): stateType => {
}, []);
const results = passResults.map(stringifyResults);
console.log(results)
return {...state, results }
} catch (err) {
console.log(err)
return {...state, errors: err };
}
}