Skip to content

Instantly share code, notes, and snippets.

@nirazul
Last active May 5, 2017 12:13
Show Gist options
  • Save nirazul/7d08bc07755ada9849b737f3b55f0ddf to your computer and use it in GitHub Desktop.
Save nirazul/7d08bc07755ada9849b737f3b55f0ddf to your computer and use it in GitHub Desktop.
blog.dreipol.ch - Snippet 8
function setEndpoint(store, presets) {
return function fetch(route) {
// 1. Merge params and query with route presets
const params = Object.assign({}, presets.params, route.params);
const query = Object.assign({}, presets.query, route.query);
// 2. Create compiled endpoint url
const url = compileUrl(presets.url, params, query);
// 3. Push available data into the store's endpoint address
if (route.response) {
return store.setRouteData({
key: url,
value: route.response
});
}
// 4. Fetch data from compiled url
return store.getRouteData({ key: url });
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment