npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@seanchas116/mobx-loro

v0.0.4

Published

MobX bindings for Loro CRDT

Readme

@seanchas116/mobx-loro

npm version License: MIT

MobX wrappers for Loro CRDT containers, enabling automatic UI updates when CRDT data changes.

Installation

npm install @seanchas116/mobx-loro loro-crdt mobx

Quick Start

import { LoroDoc } from "loro-crdt";
import { getMap, getList } from "@seanchas116/mobx-loro";
import { reaction } from "mobx";

const doc = new LoroDoc();

// Get observable wrappers
const map = getMap(doc, "myMap");
const list = getList(doc, "myList");

// Automatically react to changes
reaction(
  () => map.toJSON(),
  (json) => console.log("Map changed:", json),
);

React Integration

import React from "react";
import { observer } from "mobx-react-lite";
import { LoroDoc, LoroMap } from "loro-crdt";
import { getList } from "@seanchas116/mobx-loro";

type TodoData = {
  title: string;
  completed: boolean;
};

const TodoList = observer(({ doc }: { doc: LoroDoc }) => {
  const todos = getList(doc, "todos");

  return (
    <div>
      <h2>Todos ({todos.length})</h2>
      {todos.toArray().map((todo: any, i: number) => (
        <div key={i}>
          <input
            type="checkbox"
            checked={todo.get("completed")}
            onChange={() => todo.set("completed", !todo.get("completed"))}
          />
          {todo.get("title")}
        </div>
      ))}
      <button
        onClick={() => {
          const todo = todos.pushContainer(new LoroMap<TodoData>());
          todo.set("title", "New Todo");
          todo.set("completed", false);
        }}
      >
        Add Todo
      </button>
    </div>
  );
});

Key Features

  • Automatic Reactivity: Seamless MobX integration for CRDT containers
  • Type Safety: Full TypeScript support with automatic type transformations
  • Flyweight Pattern: Single instance per container
  • All Loro Containers: Map, List, Tree, MovableList, and Text support
  • Nested Containers: Automatic wrapping with proper typing

Type Safety

The library provides automatic type inference from your schema:

import { LoroDoc, LoroMap, LoroList } from "loro-crdt";
import { getList, getMap } from "@seanchas116/mobx-loro";

// Define your document schema
type Schema = {
  metadata: LoroMap<{ lastModified: number }>;
  todos: LoroList<LoroMap<{ title: string; done: boolean }>>;
};

const doc = new LoroDoc<Schema>();

// Types are automatically inferred from the schema
const metadata = getMap(doc, "metadata");
// Type: ObservableLoroMap<{ lastModified: number }>

const todos = getList(doc, "todos");
// Type: ObservableLoroList<LoroMap<{ title: string; done: boolean }>>

// Nested containers are also properly typed
const firstTodo = todos.get(0);
// Type: ObservableLoroMap<{ title: string; done: boolean }>

Collaborative Todo Store

import { makeAutoObservable } from "mobx";
import { LoroDoc, LoroMap } from "loro-crdt";
import { getList } from "@seanchas116/mobx-loro";

class TodoStore {
  doc = new LoroDoc();

  constructor() {
    makeAutoObservable(this);
  }

  get todos() {
    return getList(this.doc, "todos");
  }

  addTodo(title: string) {
    const todo = this.todos.pushContainer(new LoroMap());
    todo.set("id", crypto.randomUUID());
    todo.set("title", title);
    todo.set("completed", false);
  }

  // Sync with other peers
  applyUpdate(update: Uint8Array) {
    this.doc.import(update);
  }

  getUpdate(): Uint8Array {
    return this.doc.exportFrom();
  }
}

License

MIT © Ryohei Ikegami