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
//onEntry: sendParent("FAIL") | |
const failureMachine = Machine({ | |
id: 'failure', | |
initial: 'INIT', | |
// context: new Error('Hi there'), | |
states: { | |
INIT: { | |
on: { | |
"*": [ |
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 fetchMachine = Machine({ | |
id: "root", | |
context: { | |
authorizationCode: "123" | |
}, | |
initial: "INIT", | |
states: { | |
"NOT AUTHORIZED": { | |
on: { | |
LOGIN: "AUTHORIZING" |
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
// Available variables: | |
// Machine (machine factory function) | |
// assign (action) | |
// XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: "theWholeSelect", | |
initial: "init", | |
context: { | |
currentValueToShow: 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
type Tail<T extends any[]> = ((...args: T) => any) extends (( | |
_: infer First, | |
...rest: infer Rest | |
) => any) | |
? T extends any[] ? Rest : ReadonlyArray<Rest[number]> | |
: [] | |
type GrabDeepType<T extends Record<any, any>, PathType> = { | |
'deeper': PathType extends [infer HeadType, ...any[]] |
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
#!/bin/bash | |
find ./ -type f -print | xargs grep $1 || echo 'Not found' |
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
//Eslint thinks that its wrong: | |
errorOrMessage instanceof Error | |
? { | |
error: errorOrMessage, | |
meta, | |
} | |
: { | |
error: new Error(errorOrMessage), | |
meta, |
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 actionTypeEq = type => pipe(secondArg, propEq('type', type)); | |
const secondArg = (first, second) => second; | |
const assocMerge = (pathToObjectOrArray, value) => | |
assocPath(pathToObjectOrArray, merge(pathOr({}, pathToObjectOrArray), value)); | |
const reducer = cond([ | |
[ | |
actionTypeEq(LOADED), | |
(state, action) => assocMerge(['data'], action.payload)(state), | |
], | |
[T, identity], |
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
// Lets say we have some function | |
var ar = 'Some value'; | |
const f = (...args2) => console.log(ar, ...args2); | |
f(1) //Some value, 1 | |
// Now lets change the behaviour | |
// without changing the function | |
const saveToClosure = (data) => { |