Skip to content

Instantly share code, notes, and snippets.

View javisperez's full-sized avatar

Javis V. Pérez javisperez

View GitHub Profile
import { createStore } from 'vuex';
// The modules to import
import auth, { Store as AuthStore, State as AuthState } from './auth';
import counter, { Store as CounterStore, State as CounterState } from './counter';
// A State type with all the submodules
type State = {
auth: AuthState;
counter: CounterState;
@javisperez
javisperez / addons.js
Last active March 31, 2018 21:45
Dexie js - some useful methods
/**
* I'll update this gist as I get to define more helpful methods to extend
*/
/**
* insertReplace, looks for unique keys on the table and the data to insert
* if the current key/value pair is found (and unique) update it with the given data,
* otherwise insert it as a new record
*/
db.Table.prototype.insertReplace = function(data) {
@javisperez
javisperez / interceptors.js
Last active December 4, 2022 16:47
Axios interceptor for cache with js-cache
// Usually I use this in my app's config file, in case I need to disable all cache from the app
// Cache is from `js-cache`, something like `import Cache from 'js-cache';`
const cacheable = true,
cache = new Cache();
// On request, return the cached version, if any
axios.interceptors.request.use(request => {
// Only cache GET requests
if (request.method === 'get' && cacheable) {
@javisperez
javisperez / vue-route-data.js
Last active March 26, 2020 01:37
[UPDATED] VueRouteData plugin for vue-router@2.0 and vue@1or2
/**
* Note: this is an updated version of the original plugin:
* https://gist.github.com/fnlctrl/1cf9da63493e0fe78181a4f4e2cc6f64
*
* VueRouteData plugin for vue-router@2.0 and vue@1or2,
* implemented according to https://github.com/vuejs/vue-router/issues/296#issuecomment-235481643
*
* This plugin looks for `$options.fetchRouteData`,
* and watches `$route` using `$options.fetchRouteData` as handler.
*