refactor into using config reducer

This commit is contained in:
okbel
2018-03-20 12:09:32 -03:00
parent d6fba2d515
commit 030deb1b81
7 changed files with 44 additions and 17 deletions
@@ -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,
};
+6 -2
View File
@@ -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) {
+8 -4
View File
@@ -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();
}
}
+13 -1
View File
@@ -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') ||
+10 -2
View File
@@ -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
View File
@@ -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());
});
}