Giter Club home page Giter Club logo

Comments (2)

kettanaito avatar kettanaito commented on August 25, 2024

Option 1: WebSockets

Spawn a local WebSocket server to signal events from the db usage on the client to the server-side db usage.

Advantages

  • Real-time synchronization using an established protocol.

WebSocket is a great choice, as data updates may be bidirectional:

  • Client updated -> apply to the server.
  • Server update (i.e. Next.js API route) -> apply to the client.

Disadvantages

  • Need to spawn a server, which means having to run an extra command as a part of your work with data.
    • This can be negated, as the server may be spawned internally, without asking the user to execute any extra commands.

It would be great to spawn the WS server implicitly, never exposing it to the end-user. The server address could be mafically shared between the server- and the client-side DB instances.

Implementation

The library determines if the current environment is Node.js, and if so, creates a WebSocket server. The server listens to client-side update events and applies them to the server db instance. The server emits server-side update events to the client as well.

The client-side part of the library attempts to connect to the server. If the connection fails (no server counterpart), handle it gracefully. If the connection is established, the server and the client may be synchronized via socket events.

from data.

kettanaito avatar kettanaito commented on August 25, 2024

Observation: Next.js re-evaluates the db.js module where you create the database. This means even if the client signals to update the server-side db instance, and it updates, when the page refreshes all the server runtime is thrown away, and the db is instantiated anew.

from data.

Related Issues (20)

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.