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
const createMigration = (opts, data) => { | |
return new Promise((resolve, reject) => { | |
const key = `${opts.key}-version`; | |
localforage.getItem(key, (err, version) => { | |
if (version !== opts.version) { | |
data = opts.migrate(data); | |
localforage.setItem(opts.key, rehydrate(data), (err) => { | |
if (err) return reject(err); | |
localforage.setItem(key, opts.version, (err) => { | |
if (err) return reject(err); |
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
const config = { | |
key: '@session', | |
transform: { | |
in: ({ name }) => ({ name }), | |
out: ({ name }) => ({ name, avatarUrl: '' }) | |
} | |
} | |
const useStorage = (state, setState) => { | |
const [rehydrated, setRehydrated] = useState(false); |
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
const merge = (initialValue, hydratedValue) => { | |
if (!isObjectLike(initialValue)) { | |
return initialValue; | |
} | |
return {...hydratedValue, ...initialValue}; | |
}; | |
const useStorage = (state, setState, initialValue) => { | |
const [rehydrated, setRehydrated] = useState(false); | |
const [error, setError] = useState(null); |
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
const SET_INFO = 'SET_INFO'; | |
const SET_ERROR = 'SET_ERROR'; | |
const initialState = { | |
info: {}, | |
error: null | |
}; | |
const reducer = (state, action) => { | |
switch (action.type) { |
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
import localforage from 'localforage'; | |
const useStorage = (state, setState) => { | |
const [rehydrated, setRehydrated] = useState(false); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
// Async rehydration | |
localforage.getItem(config.key, (err, value) => { | |
if (err) { |
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
import { useEffect, useState, useReducer } from 'react'; | |
import { isEmpty, isNil } from 'ramda'; | |
const isObjectLiked = (value) => | |
value.constructor.name == "Array" || | |
value.constructor.name == "Object"; | |
const rehydrate = (value, defaultValue) => { | |
if (!value) return defaultValue; | |
if (value === 'false') str = false; |
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
const SET_INFO = 'SET_INFO'; | |
const SET_ERROR = 'SET_ERROR'; | |
const initialState = { | |
info: {}, | |
error: null | |
}; | |
const reducer = (state, action) => { | |
switch (action.type) { |
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
nsqlookupd: | |
image: nsqio/nsq | |
command: /nsqlookupd | |
ports: | |
- "4160" | |
- "4161" | |
nsqd: | |
image: nsqio/nsq | |
links: | |
- nsqlookupd |
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
var keystone = require('keystone'); | |
var Types = keystone.Field.Types; | |
/** | |
* Job Model | |
* ========== | |
*/ | |
var Job = new keystone.List('Job'); | |
Job.add({ |
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
package api | |
import ( | |
"log" | |
"encoding/json" | |
"net/http" | |
"app/repo" | |
"app/worker" | |
"app/model" |
NewerOlder