Skip to content

Instantly share code, notes, and snippets.

View danReynolds's full-sized avatar
💭
Grinding

Dan Reynolds danReynolds

💭
Grinding
View GitHub Profile
@danReynolds
danReynolds / machine.js
Last active May 13, 2020 16:47
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
Let's examine how the Apollo cache layers optimistic data, primarily from the performTransaction API:
https://github.com/apollographql/apollo-client/blob/master/src/cache/inmemory/inMemoryCache.ts#L255
When executing a transaction like writing an optimistic mutation result, it will first call `addLayer` on its optimisticData.
This will create a new layer which as it is instantiated, calls the `perform` function that was passed to it. It stores a reference to the layer that instantiated it as its parent.
Perform is called with the newly instantiated layer. It sets both the data reference and optimisticData reference equal to the new layer instance, so that any changes to data or optimisticData that occur during the transaction are set onto the new layer and not its parent and not the root entity store.
@danReynolds
danReynolds / .dart
Created January 29, 2024 16:36
Brighten extension
extension ColorExtensions on Color {
String toHex() =>
'#${(value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}';
bool get isDark {
return ThemeData.estimateBrightnessForColor(this) == Brightness.dark;
}
Color darken([int percent = 10]) {
assert(1 <= percent && percent <= 100);
import { ZodTypeAny, z } from "zod";
import {
DeploymentOptions,
FunctionBuilder,
https,
} from "firebase-functions/v1";
import { assert, validate } from "./validate.js";
import Logger from "./logger.js";
const logger = new Logger("Precheck");