Skip to content

Instantly share code, notes, and snippets.

@ipatate
Last active March 16, 2017 18:08
Show Gist options
  • Save ipatate/00b6162314c3f75bda42279973342f4c to your computer and use it in GitHub Desktop.
Save ipatate/00b6162314c3f75bda42279973342f4c to your computer and use it in GitHub Desktop.
// 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