Skip to content

Instantly share code, notes, and snippets.

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);
const config = {
key: '@session',
transform: {
in: ({ name }) => ({ name }),
out: ({ name }) => ({ name, avatarUrl: '' })
}
}
const useStorage = (state, setState) => {
const [rehydrated, setRehydrated] = useState(false);
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);
const SET_INFO = 'SET_INFO';
const SET_ERROR = 'SET_ERROR';
const initialState = {
info: {},
error: null
};
const reducer = (state, action) => {
switch (action.type) {
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) {
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;
const SET_INFO = 'SET_INFO';
const SET_ERROR = 'SET_ERROR';
const initialState = {
info: {},
error: null
};
const reducer = (state, action) => {
switch (action.type) {
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160"
- "4161"
nsqd:
image: nsqio/nsq
links:
- nsqlookupd
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Job Model
* ==========
*/
var Job = new keystone.List('Job');
Job.add({
package api
import (
"log"
"encoding/json"
"net/http"
"app/repo"
"app/worker"
"app/model"