<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Yjs Internals on Random Tech Excursions</title><link>https://ssushant.me/yjs/</link><description>Recent content in Yjs Internals on Random Tech Excursions</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 01 Jan 0001 00:00:00 +0000</lastBuildDate><atom:link href="https://ssushant.me/yjs/index.xml" rel="self" type="application/rss+xml"/><item><title/><link>https://ssushant.me/yjs/chapter-1/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-1/</guid><description>&lt;h1 id="chapter-1-doc" class="relative group"&gt;Chapter 1: Doc &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-1-doc" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;Welcome! In Yjs, everything starts with the &lt;code&gt;Doc&lt;/code&gt;. It is the top-level container for all shared data. Think of it as a collaborative notebook that lives on your device. You can put shared types inside it, edit them, and later send those updates to other devices.&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="what-problem-does-doc-solve" class="relative group"&gt;What problem does Doc solve? &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#what-problem-does-doc-solve" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Imagine Alice and Bob are writing a shared note together. Alice is on her laptop, Bob is on his phone. They are not always online, but when they reconnect, their notes should become the same.&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-2/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-2/</guid><description>&lt;h1 id="chapter-2-ytype" class="relative group"&gt;Chapter 2: YType &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-2-ytype" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;In &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-1/"&gt;Chapter 1&lt;/a&gt;, we learned that &lt;code&gt;Doc&lt;/code&gt; is like a collaborative notebook. We created a &lt;code&gt;Y.Text&lt;/code&gt; inside it and synced two &lt;code&gt;Doc&lt;/code&gt;s with updates. But a notebook is only useful when you can write different kinds of things in it: lists, notes, settings, and more. In Yjs, those different kinds of things are called &lt;strong&gt;YTypes&lt;/strong&gt;.&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="what-problem-does-ytype-solve" class="relative group"&gt;What problem does YType solve? &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#what-problem-does-ytype-solve" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Imagine you and your roommate want to share a grocery list. You both need to add items, remove items, and see each other’s changes. If you use a normal JavaScript array, it looks like this:&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-3/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-3/</guid><description>&lt;h1 id="chapter-3-transaction" class="relative group"&gt;Chapter 3: Transaction &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-3-transaction" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;Welcome back! In the previous chapter, &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-2/"&gt;YType&lt;/a&gt;, we saw how shared types like &lt;code&gt;Y.Map&lt;/code&gt; and &lt;code&gt;Y.Text&lt;/code&gt; capture every change. But we didn&amp;rsquo;t talk about &lt;em&gt;when&lt;/em&gt; those changes are announced. If you change two things at once, should your app update twice? No. Yjs uses a &lt;strong&gt;Transaction&lt;/strong&gt; to bundle changes together into one neat package.&lt;/p&gt;&#10;&lt;h2 id="what-problem-does-transaction-solve" class="relative group"&gt;What problem does Transaction solve? &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#what-problem-does-transaction-solve" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Imagine you&amp;rsquo;re building a collaborative profile card. A &lt;code&gt;Y.Map&lt;/code&gt; holds the profile:&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-4/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-4/</guid><description>&lt;h1 id="chapter-4-update-encoding--decoding" class="relative group"&gt;Chapter 4: Update Encoding / Decoding &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-4-update-encoding--decoding" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;Welcome back! In the last chapter, &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-3/"&gt;Transaction&lt;/a&gt;, we saw how Yjs groups changes into batches and produces one &lt;code&gt;update&lt;/code&gt;. But what &lt;em&gt;is&lt;/em&gt; that update? It’s a &lt;strong&gt;binary message&lt;/strong&gt; that can be sent over a network. This chapter is about how Yjs packs changes into that message, and how another Yjs document unpacks them.&lt;/p&gt;&#10;&lt;p&gt;Imagine you and a friend both have a suitcase full of shared notes. When you edit a note, you don’t send your friend the entire suitcase. You fold just the changed notes into a small package, send it over, and your friend unfolds it and puts it into their own suitcase. That is exactly what Yjs does with &lt;strong&gt;updates&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-5/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-5/</guid><description>&lt;h1 id="chapter-5-snapshot" class="relative group"&gt;Chapter 5: Snapshot &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-5-snapshot" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;In &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-4/"&gt;Chapter 4: Update Encoding / Decoding&lt;/a&gt;, we learned how changes can be packed into binary updates and sent to other documents. Updates are like a movie: they show a story of changes over time. But sometimes you don’t want the whole movie. You want one still frame — a photograph of the document at a single moment. That’s exactly what a &lt;strong&gt;Snapshot&lt;/strong&gt; is.&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-6/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-6/</guid><description>&lt;h1 id="chapter-6-structstore" class="relative group"&gt;Chapter 6: StructStore &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-6-structstore" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;In the previous chapter, &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-5/"&gt;Snapshot&lt;/a&gt;, we learned that a snapshot contains a &lt;strong&gt;miniature StructStore&lt;/strong&gt;. But we didn’t open that door and look inside. Now it’s time to visit the warehouse.&lt;/p&gt;&#10;&lt;p&gt;Imagine Alice and Bob are syncing a shared todo list. Alice adds &lt;code&gt;&amp;quot;learn Yjs&amp;quot;&lt;/code&gt; to the list, then sends Bob an update. When Bob’s &lt;code&gt;Doc&lt;/code&gt; receives that update, it needs a place to unpack the incoming pieces. That place is the &lt;strong&gt;StructStore&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-7/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-7/</guid><description>&lt;h1 id="chapter-7-item--abstractstruct" class="relative group"&gt;Chapter 7: Item / AbstractStruct &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-7-item--abstractstruct" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;In &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-6/"&gt;Chapter 6: StructStore&lt;/a&gt;, we opened the warehouse door and saw sorted shelves of structs. Now it is time to examine the bricks themselves. Imagine Alice and Bob are working on a shared text note. Alice types &lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt; and sends it to Bob. Later Bob deletes &lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt;. How does Yjs remember that &lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt; existed but is now invisible? The answer is built from tiny, carefully placed building blocks called &lt;strong&gt;structs&lt;/strong&gt; — especially the &lt;strong&gt;Item&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title/><link>https://ssushant.me/yjs/chapter-8/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ssushant.me/yjs/chapter-8/</guid><description>&lt;h1 id="chapter-8-id" class="relative group"&gt;Chapter 8: ID &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#chapter-8-id" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p&gt;In &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-7/"&gt;Item / AbstractStruct&lt;/a&gt;, we looked at the bricks that make up a Yjs document. Those bricks live on shelves in the &#10; &#10; &lt;a href="https://ssushant.me/yjs/chapter-6/"&gt;StructStore&lt;/a&gt;. But how does Yjs tell one brick from another? When two people are editing offline, how does it know which change came from which device, and in what order?&lt;/p&gt;&#10;&lt;p&gt;The answer is a tiny but powerful concept: the &lt;strong&gt;ID&lt;/strong&gt;.&lt;/p&gt;</description></item></channel></rss>