refactor into using config reducer

This commit is contained in:
okbel
2018-03-20 11:52:44 -03:00
parent 8a2fa2432f
commit d6fba2d515
6 changed files with 22 additions and 34 deletions
@@ -1,2 +0,0 @@
export const ENABLE_PLUGINS_DEBUG = 'ENABLE_PLUGINS_DEBUG';
export const DISABLE_PLUGINS_DEBUG = 'DISABLE_PLUGINS_DEBUG';
@@ -8,7 +8,7 @@ const initialState = {
errors: {},
};
export default function config(state = initialState, action) {
export default function configure(state = initialState, action) {
switch (action.type) {
case actions.UPDATE_PENDING: {
let next = state;
@@ -1,20 +0,0 @@
import * as actions from '../constants/debug';
const initialState = {
plugins: false,
};
export default function DEBUG(state = initialState, action) {
switch (action.type) {
case actions.ENABLE_PLUGINS_DEBUG:
return {
plugins: true,
};
case actions.DISABLE_PLUGINS_DEBUG:
return {
plugins: false,
};
default:
return state;
}
}
+6 -10
View File
@@ -69,7 +69,6 @@ class Slot extends React.Component {
defaultComponent: DefaultComponent,
queryData,
fill,
debug = {},
} = this.props;
const { plugins } = this.context;
let children = this.getChildren();
@@ -95,19 +94,18 @@ class Slot extends React.Component {
children = children.map(childFactory);
}
const debugProps =
debug.plugins || pluginsConfig.debug
? {
'data-slot-name': fill,
}
: {};
const debugProps = pluginsConfig.debug
? {
'data-slot-name': fill,
}
: {};
return (
<Component
className={cn(
{
[styles.inline]: inline,
[styles.debug]: debug.plugins || pluginsConfig.debug,
[styles.debug]: pluginsConfig.debug,
},
className,
`talk-slot-${kebabCase(fill)}`
@@ -125,7 +123,6 @@ Slot.defaultProps = {
};
Slot.propTypes = {
debug: PropTypes.object,
fill: PropTypes.string.isRequired,
inline: PropTypes.bool,
className: PropTypes.string,
@@ -161,7 +158,6 @@ Slot.propTypes = {
const mapStateToProps = state => ({
reduxState: state,
debug: state.debug,
});
export default connect(mapStateToProps, null)(Slot);
@@ -1,3 +1,5 @@
const prefix = `TALK_FRAMEWORK`;
export const MERGE_CONFIG = `${prefix}_MERGE_CONFIG`;
export const ENABLE_PLUGINS_DEBUG = `${prefix}_ENABLE_PLUGINS_DEBUG`;
export const DISABLE_PLUGINS_DEBUG = `${prefix}_DISABLE_PLUGINS_DEBUG`;
+13 -1
View File
@@ -1,10 +1,22 @@
import { MERGE_CONFIG } from '../constants/config';
import {
MERGE_CONFIG,
ENABLE_PLUGINS_DEBUG,
DISABLE_PLUGINS_DEBUG,
} from '../constants/config';
import { LOGOUT } from '../constants/auth';
const initialState = {};
export default function config(state = initialState, action) {
switch (action.type) {
case ENABLE_PLUGINS_DEBUG:
return {
plugins: true,
};
case DISABLE_PLUGINS_DEBUG:
return {
plugins: false,
};
case LOGOUT:
return {
...state,