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
Machine( | |
{ | |
context: { | |
networkQuality: "good", | |
}, | |
on: { | |
REPORT_NETWORK_QUALITY: { | |
actions: [ | |
assign({ | |
networkQuality: (_, ev) => ev.networkQuality, |
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 | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
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
// source | |
524288; // {"basics":["Object"],"composites":["StructuredType","StructuredOrInstantiable","ObjectFlagsType","Narrowable","NotPrimitiveUnion","IncludesMask"]} | |
// target | |
8388608; // {"basics":["IndexedAccess"],"composites":["TypeVariable","InstantiableNonPrimitive","Instantiable","StructuredOrInstantiable","Simplifiable","Narrowable","NotPrimitiveUnion","IncludesWildcard"]} | |
var flags = { | |
Any: 1 << 0, | |
Unknown: 1 << 1, | |
String: 1 << 2, | |
Number: 1 << 3, |
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 createSingleState = () => ({ | |
initial: "fetch", | |
states: { | |
fetch: { | |
invoke: { | |
src: "fetchSmth", | |
onDone: { | |
target: "done", | |
actions: "notifySingleSuccess" | |
} |
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
function createLongLastingContext<T>(factory: () => T) { | |
const defaultValue = typeof document !== "undefined" ? factory() : null; | |
const ctx = React.createContext<T | null>(defaultValue); | |
return { | |
useContext: () => { | |
const value = React.useContext(ctx); | |
if (!value) { | |
throw new Error("Context not initialized."); | |
} | |
return value; |
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
mapped types syntax and intro | |
https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gRgKygXigbwFBW1AZge3wC4oBnYAJwEsA7AcwBosc4BDCkmgVwFs4IKGAL4YMoSFACSAEwg1gVUAB4AKgD4U6ZtgDaAaSi0oAawgh8uKCoC6JFfuvDR46AGVWPaKhlyFy+AhqGAD0wTgAegD8omLg0AAKFPg8VKRUuCCqGqiYOFD6hjQmZhZWtlAAFACUKBqJyakQqg5BIrES9SlpuFQQ0pqdqemZAUGhEdEYsgDGADbs0NP4NORQFGDTJIPdvdKiSyvAeFzAXBReaxsAdGwU1SFheU-PUFGiuCdnEFfAABZyFQqADdWLMasgNLkcCDZtooOM3kIqkA | |
a tweet that prompted the idea for the talk | |
https://twitter.com/kentcdodds/status/1608187990215655424 | |
but since this isn't possible with satisfies (it doesn't participate in inference, in an example like that it only provides contextual types) the answer was to use a function with a reverse mapped 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
async function microtask() { | |
return Promise.resolve().then(() => {}); | |
} | |
async function test() { | |
queueMicrotask(() => { | |
console.log("1"); | |
queueMicrotask(() => { | |
console.log("2"); | |
}); | |
}); |
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 microtask = () => {} | |
async function test() { | |
queueMicrotask(() => { | |
console.log("1"); | |
queueMicrotask(() => { | |
console.log("2"); | |
}); | |
}); | |
await microtask(); |
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
// identity mapped type | |
https://www.typescriptlang.org/play?#code/PTAEEsDsAcFcBcBQ8Ce0CmoDyAjAVqALygDeioFoAZgPY0BcoAzvAE5QDmANOZTgIatGkWAFsc6VogC+iRCGqxIAY3jgakZGkwBJACbpIa1AB4AKgD4ipXhQDaAaQiRQAa3QoaVUGYC6jM0dfGTkFZX4AGwitDFAAZX5RTGJ9Q2MUE1w8CyA | |
// promisify mapped type | |
https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gRgKygXigbygMwPbYFxQDOwATgJYB2A5gDRRwCGJBFArgLZwQlQC+AUP1CQoABRLZ2ZQmUwgAPABUAfCnT8omqAG0A0lEpQA1hBDZMURQF0CACgCUKVeMnSISvVeX8BQ8NBcpGUwyCAATNUDpWQV4BG9+MIgAYwAbJmhk7ApiKBIwZIIo4NCwwSyc4CxWYFYSaFR85IA6RhIHQUwauohm4AALCApbWwA3BlTHZFU0DS1x1J97IA | |
// SatisfyName, get access to ur own key in the callback | |
https://www.typescriptlang.org/play?#code/PTAEDMFcDsGMBcCWB7aAoeBPADgU1AMoCGSAzuJgHJEC2uAPACoB8oAvKAN5qigDaAaVCJooANa5MycKEYBdAFygAFNFq4lAgJTtWAN2SIAJgG40AXzNojuWABsiAJ3xQ4SVKFIlE5TAHkAIwArW3hqOiZmZWRgpWIyCnCGFi0lA2MrLwT-YNCk5U5QEFBkSHhsMp5QIiVVdR02Vm4q3jU6M15zABoqgNq23AamltARgY7QbostEyA | |
// provideValue, just pairs of data and callbacks that get *their* data as an argument | |
https://www.typescript |
OlderNewer