Skip to content

Instantly share code, notes, and snippets.

View rayrayzayzay's full-sized avatar

Rachel Zack rayrayzayzay

View GitHub Profile
let mode: "idle" | "dragging" = "idle"
const dragHandler: InteractionHandler = {
onDragStart(gesture, app) {
if (intersection(gesture.elementsUnderCursor, app.selectedElements).size) {
mode = "dragging";
}
},
onPointerMove(gesture) {
// ignore pointer-moves when we haven't started dragging
if (isScreenshot) return;
if (!isEditor) return;
if (isOnMap(event)) return;
if (sidebarState.displayedItem !== "comments") return;
if (hasDragged.check(event)) return;
if (currentTool !== "NONE") return;
if (isPanning) return;
if (isZooming) return;
if (event.shiftKey) return;
<MapPosition>
<DragBox>
<SVGPolygon
path={pathFromCoordinates(
element.coords,
viewport
)} />
</DragBox>
<SelectionFrame
polygon={selectionFramePolygon(element.coords, viewport)} />
const cache = new WeakMap<ElementCoords, Path2D>()
function getCachedPath(element) {
const fromCache = cache.get(element.coords)
if (fromCache) return fromCache;
const path = calculatePath(element.coords);
cache.set(element.coords, path);
return path;
}
function getFullRouteGeometry(coords, viewport) {
const roundedZoom = Math.round(viewport.zoom)
const fromCache = cache.get(roundedZoom).get(coords)
if (fromCache) return clipToViewport(fromCache, viewport);
const simplified = simplify(coords, 1 / roundedZoom)
cache.get(roundedZoom).set(coords, simplified);
return clipToViewport(simplified, viewport);
}
const MIN_FONT_SIZE = 24;
function drawTextElement(ctx, text, fontSize) {
const scale = fontSize / MIN_FONT_SIZE;
if (scale <= 1) {
ctx.scale(scale, scale)
ctx.drawImage(getTexture(text), 0, 0);
} else {
drawText(ctx, text, fontSize)
}
}
<MapPosition>
<DragBox>
<SVGLine
path={pathFromCoordinates(
element.coords,
viewport
)} />
</DragBox>
<SelectionFrame
polygon={selectionFramePolygon(element.coords, viewport)} />
children = [
MyApp.Repo,
MyAppWeb.Telemetry,
{Phoenix.PubSub, name: MyApp.PubSub},
MyAppWeb.Endpoint,
MyApp.PresenceDrainer # <-- NEW!
]
defmodule MyApp.PresenceDrainer do
use GenServer
require Logger
def start_link(opts \\\\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
@impl GenServer
def init(_init_arg) do
defmodule MyApp.GracefulShutdownHandler do
use GenServer
require Logger
def start_link(opts \\\\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
@impl GenServer
def init(_init_arg) do