Last active
March 16, 2017 18:08
-
-
Save ipatate/00b6162314c3f75bda42279973342f4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/gaearon/redux-thunk | |
export function updateTitleMeta(value) { | |
return (dispatch, getState) => { | |
const state = getState(); | |
const head = state.header; | |
head.title = value; | |
return dispatch(addToHeader(head)); | |
}; | |
} | |
// set the default header after query | |
export function getDefaultHeader() { | |
return (dispatch, getState) => { | |
const state = getState(); | |
return fetch(`${state.config.host}/getDefaultHeader`, { | |
method: 'get', | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
}) | |
// verif if not error server | |
.then(checkStatus) | |
.then((res) => { | |
return res.json(); | |
}) | |
// success !! | |
.then((json) => { | |
dispatch(setDefaultHeader(json)); | |
}) | |
// oh bad !! | |
.catch(() => { | |
dispatch(setDefaultHeader({})); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment