Color link, apply to todo example, and generalize store access

This commit is contained in:
Riley Eynon-Lynch 2015-10-27 15:50:53 -05:00
parent 06f713baab
commit ce49aafc4d
4 changed files with 27 additions and 13 deletions

View File

@ -1,14 +1,19 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import TodoApp from './TodoApp'; import TodoApp from './TodoApp';
import { createStore, combineReducers, compose } from 'redux'; import { createStore, combineReducers, compose } from 'redux';
import { devTools, persistState } from 'redux-devtools'; import { devTools, persistState, urlState } from 'redux-devtools';
import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react'; import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import * as reducers from '../reducers'; import * as reducers from '../reducers';
const devStateJsonMatches = window.location.href.match(/[?&]dev_state=([^&]+)\b/);
const devStateJson = devStateJsonMatches ? devStateJsonMatches[1] : null;
const finalCreateStore = compose( const finalCreateStore = compose(
devTools(), devTools(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)) persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
urlState(devStateJson)
)(createStore); )(createStore);
const reducer = combineReducers(reducers); const reducer = combineReducers(reducers);

View File

@ -1,16 +1,21 @@
import React, { PropTypes, Component } from 'react'; import React, { PropTypes, Component } from 'react';
import { getUrlForState } from '../urlState';
export default class LogMonitor extends Component { const styles = {
link: {
color: '#6FB3D2'
}
};
export default class LinkToState extends Component {
static propTypes = { static propTypes = {
computedState: PropTypes.object.isRequired fullAppState: PropTypes.object.isRequired
}; };
render() { render() {
const stateUriComponent = encodeURIComponent(JSON.stringify(this.props.computedState)); const urlForState = getUrlForState(this.props.fullAppState);
return <a style={{...styles.link}} href={urlForState}>
// TODO: don't blow away other params Current State
const urlForThisState = `?reduxDevState=${stateUriComponent}`; </a>;
return <a href={urlForThisState}>Current State</a>;
} }
} }

View File

@ -178,8 +178,6 @@ export default class LogMonitor extends Component {
); );
} }
const currentState = computedStates[computedStates.length - 1];
return ( return (
<div style={{...styles.container, backgroundColor: theme.base00}}> <div style={{...styles.container, backgroundColor: theme.base00}}>
<div style={{...styles.buttonBar, borderColor: theme.base02}}> <div style={{...styles.buttonBar, borderColor: theme.base02}}>
@ -189,7 +187,7 @@ export default class LogMonitor extends Component {
<LogMonitorButton theme={theme} onClick={::this.handleCommit} enabled={computedStates.length > 1}>Commit</LogMonitorButton> <LogMonitorButton theme={theme} onClick={::this.handleCommit} enabled={computedStates.length > 1}>Commit</LogMonitorButton>
</div> </div>
<div> <div>
<LinkToState computedState={{ monitorState, skippedActions, stagedActions, computedStates, select }} /> <LinkToState fullAppState={ this.props.store.getState() } />
</div> </div>
<div style={styles.elements} ref="elements"> <div style={styles.elements} ref="elements">
{elements} {elements}

View File

@ -13,6 +13,12 @@ function deserializeState(json) {
} }
} }
export function getUrlForState(state) {
const stateUriComponent = serializeState(state);
// TODO: don't blow away other params
return `?dev_state=${stateUriComponent}`;
}
export default function urlEncodedStateReducer(stateUriComponent) { export default function urlEncodedStateReducer(stateUriComponent) {
return next => (reducer, initialState) => { return next => (reducer, initialState) => {