Skip to content

Instantly share code, notes, and snippets.

View NoriSte's full-sized avatar

Stefano Magni NoriSte

View GitHub Profile
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchOrder2 = () => {
if (Math.random() > 0.5) {
return Promise.resolve({ status: 'done', pods: [1, 2, 3] })
} else {
return Promise.reject({ errorMessage: 'foo' })
}
}
@NoriSte
NoriSte / machine.js
Created April 30, 2021 14:53
Generated by XState Viz: https://xstate.js.org/viz
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchOrder2 = () => {
if (Math.random() > 0.5) {
return Promise.resolve({ status: 'done', pods: [1, 2, 3] })
} else {
return Promise.reject({ errorMessage: 'foo' })
}
}
@NoriSte
NoriSte / migrate-to-vite.sh
Created April 30, 2021 06:49
Webpack to Vite Codemods
# AUTOMATIC MIGRATION FROM WEBPACK TO VITE
# chmod +x migrate-to-vite.sh to make this file executable
# installing codemods
# https://docs.python-guide.org/starting/install3/osx/
# https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf
# https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
# NO NEED; ALREADY ON MASTER - (manual action)
@NoriSte
NoriSte / machine.js
Last active April 30, 2021 14:27
Generated by XState Viz: https://xstate.js.org/viz
// services
const fetchConfig = () => Promise.resolve({ hereId: 'foo', hereCode: 'bar' })
const fetchOrder = () => Promise.resolve({ status: 'done', pods: [1, 2, 3] })
const fetchIntl = () => Promise.resolve({ messages: { foo: 'bar' } })
const fetchMachine = Machine(
{
id: 'tracking-app',
initial: 'loading',
context: {
@NoriSte
NoriSte / machine.js
Last active April 29, 2021 15:31
RM V2' tracking app
const setOnline = assign({
offline: (context, event) => (context.offline = false),
})
const setOffline = assign({
offline: (context, event) => (context.offline = true),
})
const setLastUpdate = assign({
lastUpdate: (context, event) => (context.lastUpdate = Date.now()),
})
const setStatusOk = assign({
@NoriSte
NoriSte / RecoilRoot.tsx
Created October 20, 2020 05:56
Re-implementing Recoil APIs / article gists
// @see https://github.com/NoriSte/recoil-apis
import { FC } from "react";
import * as React from "react";
import { createContext } from "react";
import { generateRecoilId } from "./core";
export const RecoilContext = createContext("");
export const RecoilRoot: FC = (props) => {
@NoriSte
NoriSte / api.ts
Created October 20, 2020 05:52
Re-implementing Recoil APIs / article gists
// @see https://github.com/NoriSte/recoil-apis
type Callback = () => void;
/**
* Subscribe/unsubscribe to all the updates of the involved Recoil Values
*/
const useSubscribeToRecoilValues = <T>(
recoilValue: RecoilValue<T>,
callback: Callback
) => {
@NoriSte
NoriSte / api.ts
Last active October 19, 2020 06:51
Re-implementing Recoil APIs / article gists
// @see https://github.com/NoriSte/recoil-apis
/**
* Recoil-like atom creation.
*/
export const atom = <T>(atom: Atom<T>) => {
// ...
return atom;
};
@NoriSte
NoriSte / core.ts
Created October 19, 2020 06:21
Re-implementing Recoil APIs / article gists
// @see https://github.com/NoriSte/recoil-apis
/**
* Register a new Recoil Value idempotently.
* @private
*/
export const registerRecoilValue = <T>(
recoilId: string,
recoilValue: RecoilValue<T>
) => {