Skip to content

Instantly share code, notes, and snippets.

View nirazul's full-sized avatar

Rouven Bühlmann nirazul

View GitHub Profile
@nirazul
nirazul / index.html
Last active May 5, 2017 12:00
blog.dreipol.ch - Snippet 1
<html data-cfg='{ "routeData": { "routes": [] } }'></html>
@nirazul
nirazul / index.js
Last active May 5, 2017 12:03
blog.dreipol.ch - Snippet 3
const routes = [
{
"name": "cms-page-2",
"path": "/work",
"component": function VueComponent() {},
"meta": {
"api": {
"fetch": function(params, query) {},
"params": {},
"query": {
@nirazul
nirazul / index.json
Created May 5, 2017 12:05
blog.dreipol.ch - Snippet 4
{
"fetched": {
"containers": {
"home": {
"plugins": [],
"type": "cmp-home"
},
"main": {
"plugins": [],
"type": "cmp-main"
@nirazul
nirazul / index.json
Created May 5, 2017 12:08
block.dreipol.ch - Snippet 5
"plugins": [
{
"content": {
"src": "static/assets/img/alpaca.img",
"alt": "Alpaca grazing"
},
"type": "cmp-image"
}
]
@nirazul
nirazul / index.json
Created May 5, 2017 12:09
blog.dreipol.ch - Snippet 6
{
"fetched": {
"partials": {
"menu": {
"content": {},
}
}
}
}
@nirazul
nirazul / index.js
Last active May 5, 2017 12:12
blog.dreipol.ch - Snippet 7
export default {
beforeRouteEnter(to, from, next) {
const Fetched = to.meta.api.fetch(to.params, to.query);
next(vm => Fetched.then((vm) => {
vm.$set(vm, 'routeData', fetched);
});
},
beforeRouteUpdate(to, from, next) {
const Fetched = to.meta.api.fetch(to.params, to.query);
Fetched.then(() => {
@nirazul
nirazul / index.js
Last active May 5, 2017 12:13
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
@nirazul
nirazul / index.js
Created May 5, 2017 12:15
blog.dreipol.ch - Snippet 9
function getRouteData({ commit, state, dispatch }, { url }) {
let FetchPromise = state.routes[url];
if (FetchPromise) {
return FetchPromise;
}
return new Promise((resolve, reject) => {
Axios.request({ url }).then(
(request) => {
@nirazul
nirazul / index.json
Last active May 6, 2017 09:29
blog.dreipol.ch - Snippet 2
{
"routes": [
{
"name": "cms-page-2",
"path": "/work",
"component": "work",
"api": {
"fetch": {
"url": "/api/en/pages/work",
"params": {},
@nirazul
nirazul / map-filters.js
Created June 4, 2017 11:28
Map global filters to local methods to use them in components as well as templates
/**
* Map global filters for being used from within `methods`. This makes them usable in js as well as templates
* @param {Array} filters - A list of registered filter names
* @return {Object) An object containing filters and their functions
*/
export function mapFilters(filters) {
return filters.reduce((result, filter) => {
result[filter] = function(...args) {
return this.$options.filters[filter](...args);
};