mirror of
https://github.com/wassname/talk.git
synced 2026-07-05 04:32:04 +08:00
refactor into using config reducer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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`;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user