mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-06 19:25:17 +02:00
Rewritten some parts of redux store to use typescript interfaces
This commit is contained in:
parent
78acede8ab
commit
d3c5e2a5ec
10 changed files with 89 additions and 45 deletions
|
@ -1,29 +1,27 @@
|
|||
import {
|
||||
GET_APPS,
|
||||
GET_APPS_SUCCESS,
|
||||
GET_APPS_ERROR
|
||||
} from '../actions/actionTypes';
|
||||
|
||||
import { ActionTypes, Action } from '../actions';
|
||||
import { App } from '../../interfaces/App';
|
||||
|
||||
interface State {
|
||||
export interface State {
|
||||
loading: boolean;
|
||||
apps: App[];
|
||||
errors: '' | undefined;
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
loading: true,
|
||||
apps: []
|
||||
apps: [],
|
||||
errors: undefined
|
||||
}
|
||||
|
||||
const getApps = (state: State, action: any): State => {
|
||||
const getApps = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
loading: true,
|
||||
errors: undefined
|
||||
}
|
||||
}
|
||||
|
||||
const getAppsSuccess = (state: State, action: any): State => {
|
||||
const getAppsSuccess = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
|
@ -31,10 +29,19 @@ const getAppsSuccess = (state: State, action: any): State => {
|
|||
}
|
||||
}
|
||||
|
||||
const appReducer = (state = initialState, action: any) => {
|
||||
const getAppsError = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
errors: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
const appReducer = (state = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case GET_APPS: return getApps(state, action);
|
||||
case GET_APPS_SUCCESS: return getAppsSuccess(state, action);
|
||||
case ActionTypes.getApps: return getApps(state, action);
|
||||
case ActionTypes.getAppsSuccess: return getAppsSuccess(state, action);
|
||||
case ActionTypes.getAppsError: return getAppsError(state, action);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import { GlobalState } from '../../interfaces/GlobalState';
|
||||
|
||||
import themeReducer from './theme';
|
||||
import appReducer from './app';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
const rootReducer = combineReducers<GlobalState>({
|
||||
theme: themeReducer,
|
||||
app: appReducer
|
||||
})
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
import { SET_THEME } from '../actions/actionTypes';
|
||||
import { ActionTypes, Action } from '../actions';
|
||||
|
||||
const initialState = {
|
||||
export interface State {
|
||||
theme: string;
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
theme: 'blues'
|
||||
}
|
||||
|
||||
const themeReducer = (state = initialState, action: any) => {
|
||||
const setTheme = (state: State, action: Action): State => {
|
||||
return { theme: action.payload };
|
||||
}
|
||||
|
||||
const themeReducer = (state = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case SET_THEME:
|
||||
return {
|
||||
theme: action.payload
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
case ActionTypes.setTheme: return setTheme(state, action);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue