Use new store
parent
653627033a
commit
16cdc1acf7
@ -0,0 +1,9 @@
|
||||
export const $count = state => {
|
||||
return state.counter
|
||||
}
|
||||
export const lala = 'lalal'
|
||||
|
||||
export default {
|
||||
$count,
|
||||
lala
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
import { createStore } from 'potent-reducer'
|
||||
import {
|
||||
safeSelectNextWord,
|
||||
safeSelectNextSentence,
|
||||
safeSelectPrevWord,
|
||||
safeSelectPrevSentence,
|
||||
safeSelectNextSegment,
|
||||
safeSelectPrevSegment
|
||||
} from './selectors'
|
||||
|
||||
const initialState = {
|
||||
originalText: 'Sample Text',
|
||||
curIdx: 0,
|
||||
maxLength: 10,
|
||||
isPlaying: false,
|
||||
wpm: 300,
|
||||
offset: -15,
|
||||
running: false,
|
||||
lang: 'en',
|
||||
textDisplay: {
|
||||
mode: 'pagination',
|
||||
options: {
|
||||
pagination: { pageLength: 50 },
|
||||
segments: { prev: 9, next: 40 },
|
||||
sentences: { prev: 1, next: 8 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const thunks = {
|
||||
setText: text => dispatch => dispatch({ text }),
|
||||
resetSegment: () => dispatch => dispatch(),
|
||||
incSegment: () => dispatch => dispatch(),
|
||||
decSegment: () => dispatch => dispatch(),
|
||||
incWord: () => dispatch => dispatch(),
|
||||
decWord: () => dispatch => dispatch(),
|
||||
incSentence: () => dispatch => dispatch(),
|
||||
decSentence: () => dispatch => dispatch(),
|
||||
setMaxLength: length => dispatch => dispatch({ length }),
|
||||
setWpm: wpm => dispatch => dispatch({ wpm }),
|
||||
setOffset: offset => dispatch => dispatch({ offset }),
|
||||
start: () => dispatch => dispatch(),
|
||||
stop: () => dispatch => dispatch(),
|
||||
pause: () => dispatch => dispatch(),
|
||||
setLang: lang => dispatch => dispatch({ lang })
|
||||
}
|
||||
|
||||
const reducer = {
|
||||
SET_TEXT: (state, { text }) => ({ ...state, originalText: text, curIdx: 0 }),
|
||||
RESET_SEGMENT: state => ({ ...state, curIdx: 0 }),
|
||||
INC_SEGMENT: state => ({ ...state, curIdx: safeSelectNextSegment(state) }),
|
||||
DEC_SEGMENT: state => ({ ...state, curIdx: safeSelectPrevSegment(state) }),
|
||||
INC_WORD: state => ({ ...state, curIdx: safeSelectNextWord(state) }),
|
||||
DEC_WORD: state => ({ ...state, curIdx: safeSelectPrevWord(state) }),
|
||||
INC_SENTENCE: state => ({ ...state, curIdx: safeSelectNextSentence(state) }),
|
||||
DEC_SENTENCE: state => ({ ...state, curIdx: safeSelectPrevSentence(state) }),
|
||||
SET_MAX_LENGTH: (state, { maxLength }) => ({
|
||||
...state,
|
||||
maxLength,
|
||||
running: false,
|
||||
curIdx: 0
|
||||
}),
|
||||
SET_WPM: (state, { wpm }) => ({ ...state, wpm }),
|
||||
SET_OFFSET: (state, { offset }) => ({ ...state, offset }),
|
||||
START: state => ({ ...state, running: true }),
|
||||
STOP: state => ({ ...state, running: false, curIdx: 0 }),
|
||||
PAUSE: state => ({ ...state, running: false }),
|
||||
SET_LANG: (state, { lang }) => ({ ...state, lang })
|
||||
}
|
||||
|
||||
const store = createStore({ reducer, thunks, initialState, logging: true })
|
||||
export const Provider = store.Provider
|
||||
export const useStore = store.useStore
|
||||
export const useSelector = store.useSelector
|
||||
export const useDispatch = store.useDispatch
|
Loading…
Reference in New Issue