add state flow type to state reducer
This commit is contained in:
parent
d7f75bb018
commit
02426fb383
2 changed files with 42 additions and 14 deletions
|
@ -1,4 +1,8 @@
|
||||||
[ignore]
|
[ignore]
|
||||||
|
.*/node_modules/.*
|
||||||
|
.*/src/serviceWorker\.js
|
||||||
|
.*/src/index\.js
|
||||||
|
.*\.test
|
||||||
|
|
||||||
[include]
|
[include]
|
||||||
|
|
||||||
|
@ -7,5 +11,6 @@
|
||||||
[lints]
|
[lints]
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
|
; all=true
|
||||||
|
|
||||||
[strict]
|
[strict]
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
const addPhones = (phones, phone) => {
|
// @flow
|
||||||
|
type stateType = {
|
||||||
|
lexicon: Array<?string>,
|
||||||
|
epochs: Array<?{name: string, changes: Array<string>}>,
|
||||||
|
phones: {[key: string]: phoneType},
|
||||||
|
options: {},
|
||||||
|
results: {},
|
||||||
|
errors: {},
|
||||||
|
features: featureType
|
||||||
|
}
|
||||||
|
|
||||||
|
type phoneType = {
|
||||||
|
grapheme: string,
|
||||||
|
features: {[key: string]: boolean}
|
||||||
|
}
|
||||||
|
|
||||||
|
type featureType = {
|
||||||
|
[key: string]: {[key: string]: Array<phoneType>}
|
||||||
|
}
|
||||||
|
|
||||||
|
const addPhones = (phones: {}, phone: string): {} => {
|
||||||
let node = {};
|
let node = {};
|
||||||
phone.split('').forEach((graph, index) => {
|
phone.split('').forEach((graph, index) => {
|
||||||
if (index) node[graph] = {}
|
if (index) node[graph] = {}
|
||||||
|
@ -9,15 +29,18 @@ const addPhones = (phones, phone) => {
|
||||||
return phones;
|
return phones;
|
||||||
}
|
}
|
||||||
|
|
||||||
const findPhone = (phones, phone) => {
|
const findPhone = (phones: {}, phone: string): {} => {
|
||||||
let node;
|
let node = {};
|
||||||
phone.split('').forEach((graph, index) => {
|
phone.split('').forEach((graph, index) => {
|
||||||
node = index === 0 ? phones[graph] : node[graph];
|
node = index === 0 ? phones[graph] : node[graph];
|
||||||
});
|
});
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
const addFeatureToPhone = (phones, phone, featureKey, featureValue) => {
|
const addFeatureToPhone = (
|
||||||
|
phones: {}, phone: string, featureKey: string, featureValue: boolean
|
||||||
|
): {} =>
|
||||||
|
{
|
||||||
let node = {}
|
let node = {}
|
||||||
phone.split('').forEach((graph, index) => {
|
phone.split('').forEach((graph, index) => {
|
||||||
node = index === 0 ? phones[graph] : node[graph];
|
node = index === 0 ? phones[graph] : node[graph];
|
||||||
|
@ -26,7 +49,7 @@ const addFeatureToPhone = (phones, phone, featureKey, featureValue) => {
|
||||||
return phones;
|
return phones;
|
||||||
}
|
}
|
||||||
|
|
||||||
const findFeatures = (phones, lexeme) => {
|
const findFeatures = (phones: {}, lexeme:string): [] => {
|
||||||
let featureBundle = []
|
let featureBundle = []
|
||||||
let lastIndex = lexeme.length - 1;
|
let lastIndex = lexeme.length - 1;
|
||||||
let node = {};
|
let node = {};
|
||||||
|
@ -45,14 +68,14 @@ const findFeatures = (phones, lexeme) => {
|
||||||
return featureBundle;
|
return featureBundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const decomposeRule = rule => {
|
const decomposeRule = (rule: string): string[] => {
|
||||||
let decomposedChange = rule.split('>');
|
let decomposedChange = rule.split('>');
|
||||||
decomposedChange = [decomposedChange[0], ...decomposedChange[1].split('/')]
|
decomposedChange = [decomposedChange[0], ...decomposedChange[1].split('/')]
|
||||||
decomposedChange = [decomposedChange[0], decomposedChange[1], ...decomposedChange[2].split('_')];
|
decomposedChange = [decomposedChange[0], decomposedChange[1], ...decomposedChange[2].split('_')];
|
||||||
return [...decomposedChange];
|
return [...decomposedChange];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const stateReducer = (state, action) => {
|
export const stateReducer = (state: stateType, action: {type: string, value: {}}) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'INIT': {
|
case 'INIT': {
|
||||||
return initState();
|
return initState();
|
||||||
|
@ -154,7 +177,7 @@ export const stateReducer = (state, action) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initState = changesArgument => {
|
export const initState = (changesArgument: number = -1): stateType => {
|
||||||
const state = {
|
const state = {
|
||||||
lexicon: [
|
lexicon: [
|
||||||
'anta', 'anat', 'anət', 'anna', 'tan', 'ənta'
|
'anta', 'anat', 'anət', 'anna', 'tan', 'ənta'
|
||||||
|
|
Loading…
Reference in a new issue