Skip to content

Instantly share code, notes, and snippets.

@srph
Created October 20, 2015 16:20
Show Gist options
  • Save srph/2ad5aa47b55e275252c7 to your computer and use it in GitHub Desktop.
Save srph/2ad5aa47b55e275252c7 to your computer and use it in GitHub Desktop.
resolve wrapper for redux + react resolver
import { resolve } from 'react-resolver';
import store from 'app-store';
/**
* A wrapper to fill in the first argument with a dummy string.
* This helps because we usually don't set it to a prop, but
* to a Reducer.
*
* Also gives us the `dispatch` of the Store (yepee)
*
* Without this util:
* import store from 'app-store/';
* const dispatch = store.get().dispatch;
* @resolve('@_RESOLVED_DATA_@', (props) => dispatch(SomeAction()));
*
* With this util:
* import 'app-utils/resolver/resolver';
* @resolve(dispatch => props => dispatch(someAction(props.location.query.id)))
*
* @see
* react-resolver resolve
*/
export default function(promise) {
const dispatch = store.get().dispatch;
return resolve('@_RESOLVED_DATA_@', promise(dispatch));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment