Versions

  • v5

    2/10/2025
    Open: Version
    Changes from v4 to v5
    +0
    -0
    ⦚ 60 unchanged lines ⦚
    ⦚ 60 unchanged lines ⦚
  • v4

    2/10/2025
    Open: Version
    Changes from v3 to v4
    +1
    -1
    ⦚ 46 unchanged lines ⦚
    const resroredState = restore();
    console.info("restored state", resroredState);
    const runtime = createActor(logic), {
    id: doc.guid,
    input: input,
    ⦚ 9 unchanged lines ⦚
    ⦚ 46 unchanged lines ⦚
    const resroredState = restore();
    console.info("restored state", resroredState);
    const runtime = createActor(logic, {
    id: doc.guid,
    input: input,
    ⦚ 9 unchanged lines ⦚
  • v3

    2/10/2025
    Open: Version
    Changes from v2 to v3
    +0
    -0
    ⦚ 60 unchanged lines ⦚
    ⦚ 60 unchanged lines ⦚
  • v2

    2/10/2025
    Open: Version
    Changes from v1 to v2
    +1
    -1
    ⦚ 46 unchanged lines ⦚
    const resroredState = restore();
    console.info("restored state", resroredState);
    const runtime = createActor(withYjsHydrate(logic, doc), {
    id: doc.guid,
    input: input,
    ⦚ 9 unchanged lines ⦚
    ⦚ 46 unchanged lines ⦚
    const resroredState = restore();
    console.info("restored state", resroredState);
    const runtime = createActor(logic), {
    id: doc.guid,
    input: input,
    ⦚ 9 unchanged lines ⦚
  • v1

    2/10/2025
    Open: Version
    Changes from v0 to v1
    +60
    -0

    import { createActor } from "https://esm.sh/xstate@5.19.2?target=esnext";
    import type {
    AnyActorLogic,
    AnyStateMachine,
    CallbackActorLogic,
    EventObject,
    InspectionEvent,
    Observer,
    Snapshot,
    } from "https://esm.sh/xstate@5.19.2?target=esnext";
    import * as Y from "https://esm.sh/yjs@^13.6.20?target=esnext";
    import hydrate, { withYjsHydrate } from "https://esm.town/v/dinavinter/hydrate";

    const map = new Map<string, ReturnType<typeof createActorFromYjs>>();

    export function yjsActor(logic: AnyActorLogic, doc?: Y.Doc | string, input?: any) {
    if (typeof doc === "string" || !doc) {
    doc = new Y.Doc({ guid: doc || `@actor.${logic.id}`, meta: { collection: `@actor.${logic.id}` } });
    }

    async function start() {
    if (!map.has(doc.guid)) {
    if (doc.shouldLoad) {
    // user.whenLoaded with timeout of 1s
    await Promise.race([doc.whenLoaded, new Promise((resolve) => setTimeout(resolve, 1000))]);
    }
    map.set(doc.guid, createActorFromYjs(logic, doc, input));
    }

    return map.get(doc.guid)!;
    }

    async function send(event: EventObject) {
    const actor = await start();
    actor.send(event);
    }
  • v0

    2/10/2025
    Open: Version
    +0
    -0


1
Next
Updated: February 10, 2025