Comments (2)
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.
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)
- GraphQL issues with __typename and interfaces/unions
- It's impossible to use case insensitive search via "where" statement HOT 1
- Can `findFirst()` support the `where` parameter as function? HOT 1
- TypeError: Class constructor GraphQLList cannot be invoked without 'new' HOT 3
- Can we have models with multi-fields IDs? HOT 1
- Can we store a literal object to an entity's field? HOT 8
- Using zod to generate table schema
- comparator missing for find by id
- Using wildcard/parameters in baseUrl in toHandlers method HOT 4
- Required oneOf relation HOT 6
- Poor performance when creating linked entities
- Database ID is not unique when extracted to a setup helper file (using Vitest) HOT 4
- Help Creating Type-Safe Models HOT 2
- Support transient attributes HOT 5
- Library's state and future HOT 13
- manyOf relationship in nullable objects HOT 1
- pnpm resolves msw optional dependency as v2 instead of v1 HOT 4
- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get') while generating handlers HOT 1
- Add toHandlers('json-api') support
- REST toHandlers() PUT and POST do not work with @mswjs/http-middleware due to req.body being a string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data.