react-native-twopane-navigation
Version:
React Native package for dual screen devices navigation support (Surface Duo)
52 lines (48 loc) • 1.48 kB
text/typescript
import {
IHeaderState, IHeaderAction
} from './header.interface';
import { PUSH_HEADER, REPLACE_HEADER, REMOVE_KEY_HEADER } from './header.types';
const initialState: IHeaderState = {
headers: {}
};
const headerReducer = (
state: IHeaderState = initialState,
action: IHeaderAction
): IHeaderState => {
switch (action.type) {
case PUSH_HEADER: {
return {
...state,
headers: {
...state.headers,
[action.payload.key as string]: action.payload.header
}
};
}
case REPLACE_HEADER: {
const hasKey = action.payload.key in state.headers;
if (!hasKey) {
return { ...state };
}
return {
...state,
headers: {
...state.headers,
[action.payload.key as string]: action.payload.header
}
};
}
case REMOVE_KEY_HEADER: {
// using delete over lodash.omit to reduce dependencies on external libraries
const newData = state;
if(newData.headers[action.payload.key])
{
delete newData.headers[action.payload.key];
}
return { ...newData }
}
default:
return state;
}
};
export default headerReducer;