@@ -5,9 +5,117 @@ import * as ActionTypes from '../../../constants';
55import type { PreferencesState } from '../reducers/preferences' ;
66import type { RootState } from '../../../reducers' ;
77
8- // Action definitions:
8+ // Value Definitions:
9+ export type SetPreferencesTabValue = PreferencesState [ 'tabIndex' ] ;
10+ export type SetFontSizeValue = PreferencesState [ 'fontSize' ] ;
11+ export type SetLineNumbersValue = PreferencesState [ 'lineNumbers' ] ;
12+ export type SetAutocloseBracketsQuotesValue = PreferencesState [ 'autocloseBracketsQuotes' ] ;
13+ export type SetAutocompleteHinterValue = PreferencesState [ 'autocompleteHinter' ] ;
14+ export type SetAutosaveValue = PreferencesState [ 'autosave' ] ;
15+ export type SetLinewrapValue = PreferencesState [ 'linewrap' ] ;
16+ export type SetLintWarningValue = PreferencesState [ 'lintWarning' ] ;
17+ export type SetTextOutputValue = PreferencesState [ 'textOutput' ] ;
18+ export type SetGridOutputValue = PreferencesState [ 'gridOutput' ] ;
19+ export type SetThemeValue = PreferencesState [ 'theme' ] ;
20+ export type SetAutorefreshValue = PreferencesState [ 'autorefresh' ] ;
21+ export type SetLanguageValue = PreferencesState [ 'language' ] ;
22+ export type SetAllAccessibleOutputValue =
23+ | SetTextOutputValue
24+ | SetGridOutputValue ;
25+
26+ // Action Definitions:
27+ export type OpenPreferencesAction = {
28+ type : typeof ActionTypes . OPEN_PREFERENCES ;
29+ } ;
30+ export type SetPreferencesAction = {
31+ type : typeof ActionTypes . SET_PREFERENCES ;
32+ preferences : PreferencesState ;
33+ } ;
34+ export type SetErrorAction = {
35+ type : typeof ActionTypes . ERROR ;
36+ error : unknown ;
37+ } ;
38+
39+ export type SetPreferencesTabAction = {
40+ type : typeof ActionTypes . SET_PREFERENCES_TAB ;
41+ value : SetPreferencesTabValue ;
42+ } ;
43+ export type SetFontSizeAction = {
44+ type : typeof ActionTypes . SET_FONT_SIZE ;
45+ value : SetFontSizeValue ;
46+ } ;
47+ export type SetLineNumbersAction = {
48+ type : typeof ActionTypes . SET_LINE_NUMBERS ;
49+ value : SetLineNumbersValue ;
50+ } ;
51+ export type SetAutocloseBracketsQuotesAction = {
52+ type : typeof ActionTypes . SET_AUTOCLOSE_BRACKETS_QUOTES ;
53+ value : SetAutocloseBracketsQuotesValue ;
54+ } ;
55+ export type SetAutocompleteHinterAction = {
56+ type : typeof ActionTypes . SET_AUTOCOMPLETE_HINTER ;
57+ value : SetAutocompleteHinterValue ;
58+ } ;
59+ export type SetAutosaveAction = {
60+ type : typeof ActionTypes . SET_AUTOSAVE ;
61+ value : SetAutosaveValue ;
62+ } ;
63+ export type SetLinewrapAction = {
64+ type : typeof ActionTypes . SET_LINEWRAP ;
65+ value : SetLinewrapValue ;
66+ } ;
67+ export type SetLintWarningAction = {
68+ type : typeof ActionTypes . SET_LINT_WARNING ;
69+ value : SetLintWarningValue ;
70+ } ;
71+ export type SetTextOutputAction = {
72+ type : typeof ActionTypes . SET_TEXT_OUTPUT ;
73+ value : SetTextOutputValue ;
74+ } ;
75+ export type SetGridOutputAction = {
76+ type : typeof ActionTypes . SET_GRID_OUTPUT ;
77+ value : SetGridOutputValue ;
78+ } ;
79+ export type SetThemeAction = {
80+ type : typeof ActionTypes . SET_THEME ;
81+ value : SetThemeValue ;
82+ } ;
83+ export type SetAutorefreshAction = {
84+ type : typeof ActionTypes . SET_AUTOREFRESH ;
85+ value : SetAutorefreshValue ;
86+ } ;
87+ export type SetLanguageAction = {
88+ type : typeof ActionTypes . SET_LANGUAGE ;
89+ language : SetLanguageValue ;
90+ } ;
91+
92+ export type PreferencesAction =
93+ | OpenPreferencesAction
94+ | SetPreferencesAction
95+ | SetErrorAction
96+ | SetPreferencesTabAction
97+ | SetFontSizeAction
98+ | SetLineNumbersAction
99+ | SetAutocloseBracketsQuotesAction
100+ | SetAutocompleteHinterAction
101+ | SetAutosaveAction
102+ | SetLinewrapAction
103+ | SetLintWarningAction
104+ | SetTextOutputAction
105+ | SetGridOutputAction
106+ | SetThemeAction
107+ | SetAutorefreshAction
108+ | SetLanguageAction ;
109+
110+ export type UpdatePreferencesDispatch = (
111+ action : PreferencesAction | PreferencesThunk
112+ ) => void ;
113+
114+ export type PreferencesThunk = (
115+ dispatch : UpdatePreferencesDispatch ,
116+ getState : GetRootState
117+ ) => void ;
9118
10- export type UpdatePreferencesDispatch = ( action : unknown ) => void ;
11119export type GetRootState = ( ) => RootState ;
12120
13121function updatePreferences (
@@ -25,23 +133,13 @@ function updatePreferences(
25133 } ) ;
26134}
27135
28- export type SetPreferencesTabValue = PreferencesState [ 'tabIndex' ] ;
29- export type SetPreferencesTabAction = {
30- type : typeof ActionTypes . SET_PREFERENCES_TAB ;
31- value : SetPreferencesTabValue ;
32- } ;
33136export function setPreferencesTab ( value : SetPreferencesTabValue ) {
34137 return {
35138 type : ActionTypes . SET_PREFERENCES_TAB ,
36139 value
37140 } ;
38141}
39142
40- export type SetFontSizeValue = PreferencesState [ 'fontSize' ] ;
41- export type SetFontSizeAction = {
42- type : typeof ActionTypes . SET_FONT_SIZE ;
43- value : SetFontSizeAction ;
44- } ;
45143export function setFontSize ( value : SetFontSizeValue ) {
46144 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
47145 // eslint-disable-line
@@ -61,11 +159,6 @@ export function setFontSize(value: SetFontSizeValue) {
61159 } ;
62160}
63161
64- export type SetLineNumbersValue = PreferencesState [ 'lineNumbers' ] ;
65- export type SetLineNumbersAction = {
66- type : typeof ActionTypes . SET_LINE_NUMBERS ;
67- value : SetLineNumbersValue ;
68- } ;
69162export function setLineNumbers ( value : SetLineNumbersValue ) {
70163 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
71164 dispatch ( {
@@ -84,11 +177,6 @@ export function setLineNumbers(value: SetLineNumbersValue) {
84177 } ;
85178}
86179
87- export type SetAutocloseBracketsQuotesValue = PreferencesState [ 'autocloseBracketsQuotes' ] ;
88- export type SetAutocloseBracketsQuotesAction = {
89- type : typeof ActionTypes . SET_AUTOCLOSE_BRACKETS_QUOTES ;
90- value : SetAutocloseBracketsQuotesValue ;
91- } ;
92180export function setAutocloseBracketsQuotes (
93181 value : SetAutocloseBracketsQuotesValue
94182) {
@@ -109,11 +197,6 @@ export function setAutocloseBracketsQuotes(
109197 } ;
110198}
111199
112- export type SetAutocompleteHinterValue = PreferencesState [ 'autocompleteHinter' ] ;
113- export type SetAutocompleteHinterValueAction = {
114- type : typeof ActionTypes . SET_AUTOCLOSE_BRACKETS_QUOTES ;
115- value : SetAutocompleteHinterValue ;
116- } ;
117200export function setAutocompleteHinter ( value : SetAutocompleteHinterValue ) {
118201 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
119202 dispatch ( {
@@ -132,11 +215,6 @@ export function setAutocompleteHinter(value: SetAutocompleteHinterValue) {
132215 } ;
133216}
134217
135- export type SetAutosaveValue = PreferencesState [ 'autosave' ] ;
136- export type SetAutosaveAction = {
137- type : typeof ActionTypes . SET_AUTOSAVE ;
138- value : SetAutosaveValue ;
139- } ;
140218export function setAutosave ( value : SetAutosaveValue ) {
141219 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
142220 dispatch ( {
@@ -155,11 +233,6 @@ export function setAutosave(value: SetAutosaveValue) {
155233 } ;
156234}
157235
158- export type SetLinewrapValue = PreferencesState [ 'linewrap' ] ;
159- export type SetLinewrapAction = {
160- type : typeof ActionTypes . SET_LINEWRAP ;
161- value : SetLinewrapValue ;
162- } ;
163236export function setLinewrap ( value : SetLinewrapValue ) {
164237 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
165238 dispatch ( {
@@ -178,11 +251,6 @@ export function setLinewrap(value: SetLinewrapValue) {
178251 } ;
179252}
180253
181- export type SetLintWarningValue = PreferencesState [ 'lintWarning' ] ;
182- export type SetLintWarningAction = {
183- type : typeof ActionTypes . SET_LINT_WARNING ;
184- value : SetLintWarningValue ;
185- } ;
186254export function setLintWarning ( value : SetLintWarningValue ) {
187255 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
188256 dispatch ( {
@@ -201,11 +269,6 @@ export function setLintWarning(value: SetLintWarningValue) {
201269 } ;
202270}
203271
204- export type SetTextOutputValue = PreferencesState [ 'textOutput' ] ;
205- export type SetTextOutputAction = {
206- type : typeof ActionTypes . SET_TEXT_OUTPUT ;
207- value : SetTextOutputValue ;
208- } ;
209272export function setTextOutput ( value : SetTextOutputValue ) {
210273 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
211274 dispatch ( {
@@ -224,11 +287,6 @@ export function setTextOutput(value: SetTextOutputValue) {
224287 } ;
225288}
226289
227- export type SetGridOutputValue = PreferencesState [ 'gridOutput' ] ;
228- export type SetGridOutputAction = {
229- type : typeof ActionTypes . SET_GRID_OUTPUT ;
230- value : SetGridOutputValue ;
231- } ;
232290export function setGridOutput ( value : SetGridOutputValue ) {
233291 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
234292 dispatch ( {
@@ -247,11 +305,6 @@ export function setGridOutput(value: SetGridOutputValue) {
247305 } ;
248306}
249307
250- export type SetThemeValue = PreferencesState [ 'theme' ] ;
251- export type SetThemeAction = {
252- type : typeof ActionTypes . SET_THEME ;
253- preferences : SetThemeValue ;
254- } ;
255308export function setTheme ( value : SetThemeValue ) {
256309 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
257310 dispatch ( {
@@ -270,11 +323,6 @@ export function setTheme(value: SetThemeValue) {
270323 } ;
271324}
272325
273- export type SetAutorefreshValue = PreferencesState [ 'autorefresh' ] ;
274- export type SetAutorefreshAction = {
275- type : typeof ActionTypes . SET_AUTOREFRESH ;
276- value : SetAutorefreshValue ;
277- } ;
278326export function setAutorefresh ( value : SetAutorefreshValue ) {
279327 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
280328 dispatch ( {
@@ -293,21 +341,13 @@ export function setAutorefresh(value: SetAutorefreshValue) {
293341 } ;
294342}
295343
296- export type SetAllAccessibleOutputValue =
297- | SetTextOutputValue
298- | SetGridOutputValue ;
299344export function setAllAccessibleOutput ( value : SetAllAccessibleOutputValue ) {
300345 return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
301346 dispatch ( setTextOutput ( value ) ) ;
302347 dispatch ( setGridOutput ( value ) ) ;
303348 } ;
304349}
305350
306- export type SetLanguageValue = PreferencesState [ 'language' ] ;
307- export type SetLanguageAction = {
308- type : typeof ActionTypes . SET_AUTOREFRESH ;
309- value : SetLanguageValue ;
310- } ;
311351export function setLanguage (
312352 value : SetLanguageValue ,
313353 { persistPreference = true } = { }
0 commit comments