←
Chris Nicholas3,553 posts
Chris Nicholas avatar

Chris Nicholas

@ctnicholasdev

Developer experience @liveblocks • Interactive articles on chrisnicholas.dev 🌱

◷ Joined July 2020▧ 935 Photos and videos
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 13

It works by: 1️⃣ Scanning your project for multiplayer ideas. 2️⃣ Letting you choose which parts to set up. 3️⃣ Reading relevant get started guides—there's 77. 4️⃣ Setting up @liveblocks and linking to a free API key. 5️⃣ Done!

Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 13

New skill: /𝚖𝚊𝚔𝚎-𝚖𝚞𝚕𝚝𝚒𝚙𝚕𝚊𝚢𝚎𝚛 Run it on your app and it'll turn it into real-time project, with collaborative editing, cursors, avatars, more! $ npx skills add ctnicholas/skills

0:26
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 10

Set up your own Slack for free! My open source demo features real-time messages, threads, reactions, DMs, notifications, statuses, and multiple workspaces. → lblcks.io/WQVfKMQ

0:26
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 5

I've set up a multiplayer language learning app! You can annotate PDFs, and everything updates in realtime with @liveblocks. Plus, talk to your student, or your AI assistant, which can generate documents for you! It's free → lblcks.io/KURe1NG

0:27
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

You don't need to build any of this yourself. It's all baked into `LiveList`, the realtime array in @liveblocks Storage, ready for JavaScript and React. Servers, connections, syncing, conflict resolution—handled for you. The issue tracker below runs on it.

Post attachment
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

Final trick: ditch decimal for base 96. That's every printable ASCII character, so indices look like !, % or ). Plain string comparison sorts them, and the extra characters fit between decimal digits. Same precision, much shorter indices.

0:07
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

Pushing to the end is the most common list operation, so in real apps indices can grow longer than the data they're ordering. Our fix is viewport-based growth: when the last index runs out of room, add 3 digits at once, then add to the last one. 0.8 → 0.9 → 0.9001 → 0.9002

0:11
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

Real decimals have a catch too. Keep adding to the end of a list and floating point precision gives out after around 50 inserts—watch it break below. Switching to strings removes the limit, but creates a new issue: indices get longer and longer.

0:06
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

If Alice and Bob happen to choose the identical index, say `0.75`, there's no way to agree which comes first. So each user gets a unique ID that's tacked onto the end. Alice writes `0.75-001`, Bob writes `0.75-002`, and the tie disappears.

0:13
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

Using this method, every change affects only one index, so other items don't get renumbered. Alice and Bob can add, remove, and move items simultaneously, and both lists settle on the same order. Nothing cascades, nothing conflicts. Well, almost ↓

0:09
Chris Nicholas avatar
Chris Nicholas@ctnicholasdev·Nov 3

Fractional indexing turns this around. Rather than deriving an index from position, every item stores its own—picture it as a decimal between `0` and `1`. New item between `0.1` and `0.5`? Use the midpoint, `0.3`. Then between `0.1` and `0.3`, `0.2`. You never run out of space.

0:11