Giter Site home page Giter Site logo

Comments (5)

aboodman avatar aboodman commented on August 25, 2024

Good question. It's because for this application each new page load is a different (anonymous) "user" and so it's right to create a new client state for each page load. We don't need to wait for initial sync to see if there's any data there.

The shapes on the other hand should only be created once for the entire room.

from reflect-draw.

aboodman avatar aboodman commented on August 25, 2024

PS: Fine to ask questions here, but also discord is available. You can ask reflect questions there too: https://discord.replicache.dev.

from reflect-draw.

tslocke avatar tslocke commented on August 25, 2024

The shapes on the other hand should only be created once for the entire room.

I'm entirely confused about how the above code achieves this : )

The docs say

onSync is called when a sync begins, and again when the sync ends. The parameter syncing is set to true when onSync is called at the beginning of a sync, and false when it is called at the end of a sync.

So I would expect that callback to be called on the first sync, regardless of whether this is a new room or a reload of an existing one. The only reason it's not called over and over, as I understand, is the callback de-registers itself (53).

Every time the page loads it's going to assign that callback to r.onSync, so it's going to be called once.

I mean, I can see it behaves as you say, but I have no idea why!

Maybe my mental model of what a "sync" is, is wrong. I understand that to mean any time mutations from some other client are applied to the state of this client.

Related question: how is a room created anyway? Is it this? new Client(r, roomID, workerURL); (if it's a newly seen roomID, the new room is created?)

from reflect-draw.

aboodman avatar aboodman commented on August 25, 2024

The initShapes method runs on every page load after sync, but the first thing it does is check the stored state to see whether its run before:

https://github.com/rocicorp/replidraw-do/blob/main/src/datamodel/shape.ts#L104

If it finds the initialized key in the synced data it does nothing.

Actually now that I think of it this code dates to a version of Replidraw where persistence was turned off for performance, so I think we could now run this mutator before sync and it would work the same way. Because we now store the synced data locally so we can detect whether we've already initialized without waiting for first sync.

from reflect-draw.

aboodman avatar aboodman commented on August 25, 2024

Related question: how is a room created anyway? Is it this? new Client(r, roomID, workerURL); (if it's a newly seen roomID, the new room is created?)

Yes, this is right. The client-side API for reflect is still a bit wonky - we will soon merge Client and Replicache, but that's how it works conceptually. You just declare the room you want to connect to, and if it's new, it's created.

from reflect-draw.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.