Last active
May 5, 2017 12:13
-
-
Save nirazul/7d08bc07755ada9849b737f3b55f0ddf to your computer and use it in GitHub Desktop.
blog.dreipol.ch - Snippet 8
This file contains 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
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