mirror of
https://github.com/wassname/talk.git
synced 2026-07-04 20:09:44 +08:00
refactor into using config reducer
This commit is contained in:
@@ -3,7 +3,6 @@ import embed from './embed';
|
||||
import configure from './configure';
|
||||
import stream from './stream';
|
||||
import profile from './profile';
|
||||
import debug from './debug';
|
||||
|
||||
export default {
|
||||
login,
|
||||
@@ -11,5 +10,4 @@ export default {
|
||||
configure,
|
||||
stream,
|
||||
profile,
|
||||
debug,
|
||||
};
|
||||
|
||||
@@ -161,8 +161,12 @@ export default class Stream {
|
||||
);
|
||||
}
|
||||
|
||||
dispatch(action) {
|
||||
this.pym.sendMessage('dispatch', action);
|
||||
enableDebug() {
|
||||
this.pym.sendMessage('enableDebug');
|
||||
}
|
||||
|
||||
disableDebug() {
|
||||
this.pym.sendMessage('disableDebug');
|
||||
}
|
||||
|
||||
login(token) {
|
||||
|
||||
@@ -3,10 +3,6 @@ export default class StreamInterface {
|
||||
this._stream = stream;
|
||||
}
|
||||
|
||||
dispatch(action) {
|
||||
return this._stream.dispatch(action);
|
||||
}
|
||||
|
||||
on(eventName, callback) {
|
||||
return this._stream.emitter.on(eventName, callback);
|
||||
}
|
||||
@@ -26,4 +22,12 @@ export default class StreamInterface {
|
||||
remove() {
|
||||
return this._stream.remove();
|
||||
}
|
||||
|
||||
enableDebug() {
|
||||
return this._stream.enableDebug();
|
||||
}
|
||||
|
||||
disableDebug() {
|
||||
return this._stream.disableDebug();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
import { MERGE_CONFIG } from '../constants/config';
|
||||
import {
|
||||
MERGE_CONFIG,
|
||||
ENABLE_PLUGINS_DEBUG,
|
||||
DISABLE_PLUGINS_DEBUG,
|
||||
} from '../constants/config';
|
||||
|
||||
export const mergeConfig = config => ({
|
||||
type: MERGE_CONFIG,
|
||||
config,
|
||||
});
|
||||
|
||||
export const enablePlugins = () => ({
|
||||
type: ENABLE_PLUGINS_DEBUG,
|
||||
});
|
||||
|
||||
export const disablePlugins = () => ({
|
||||
type: DISABLE_PLUGINS_DEBUG,
|
||||
});
|
||||
|
||||
@@ -74,7 +74,6 @@ class Slot extends React.Component {
|
||||
let children = this.getChildren();
|
||||
|
||||
// @Deprecated plugin_config
|
||||
|
||||
const pluginsConfig =
|
||||
get(reduxState, 'config.plugins_config') ||
|
||||
get(reduxState, 'config.plugin_config') ||
|
||||
|
||||
@@ -11,11 +11,19 @@ export default function config(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case ENABLE_PLUGINS_DEBUG:
|
||||
return {
|
||||
plugins: true,
|
||||
...state,
|
||||
plugins_config: {
|
||||
...state.plugins_config,
|
||||
debug: true,
|
||||
},
|
||||
};
|
||||
case DISABLE_PLUGINS_DEBUG:
|
||||
return {
|
||||
plugins: false,
|
||||
...state,
|
||||
plugins_config: {
|
||||
...state.plugins_config,
|
||||
debug: false,
|
||||
},
|
||||
};
|
||||
case LOGOUT:
|
||||
return {
|
||||
|
||||
+7
-5
@@ -25,7 +25,7 @@ import { createIntrospection } from 'coral-framework/services/introspection';
|
||||
import introspectionData from 'coral-framework/graphql/introspection.json';
|
||||
import coreReducers from '../reducers';
|
||||
import { checkLogin as checkLoginAction } from '../actions/auth';
|
||||
import { mergeConfig } from '../actions/config';
|
||||
import { mergeConfig, enableDebug, disableDebug } from '../actions/config';
|
||||
import { setAuthToken, logout } from '../actions/auth';
|
||||
|
||||
/**
|
||||
@@ -216,10 +216,12 @@ export async function createContext({
|
||||
store.dispatch(logout());
|
||||
});
|
||||
|
||||
pym.onMessage('dispatch', action => {
|
||||
store.dispatch({
|
||||
type: action,
|
||||
});
|
||||
pym.onMessage('enableDebug', () => {
|
||||
store.dispatch(enableDebug());
|
||||
});
|
||||
|
||||
pym.onMessage('disableDebug', () => {
|
||||
store.dispatch(disableDebug());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user