vue-db

Get rid of as many mutable states as possible

View the Project on GitHub

About

The sole goal of vue-db is to unleash vue 3 reactivity system full potential to get rid of as many mutable states as possible. When other state management library encrouages maintaining a separate copy of data store, vue-db tries to do the opposite.

It looks like a lot, but it is a 500 line library only depending on vue. Install it via npm install vue-db, then register to vue app

import * as vdb from 'vue-db'

app.use(vdb);

Form

Instead of using https://vuex.vuejs.org/ to hold the state, vue-db use the vue component instance itself as data store.

Checkout following examples

code live demo
counter counter vdb.load with $root from current page
flat form flat form vdb.walk to dump form state
nested form nested form vdb.load with $parent allowing multiple form instances
todo list todo list vdb.waitNextTick to add new todo item

Async data binding

Data from backend need to be loaded asynchronously. Instead of using a mutable https://vuex.vuejs.org/ store to hold the backend data, vue-db provides async data binding to bind vue component data with backend table.

Checkout following examples

code live demo
todo client server todo client server vdb.defineResource and vdb.defineCommand to bind with backend data

Type-safe RPC

If both server and client are written in typescript, the .d.ts file can be used as type-safe RPC data schema. vue-db allow you to import type and hand-write a RPC stub with very little code, instead of resorting to full blown code generation solution. Also vdb.defineResource support declaring nested resource, allow client to query for a object graph in one RPC roundtrip. However, the wire-protocol and server side implementation is excluded from the scope. vue-db is just a tiny library depending only on vue 3, it will not enforce a server/client framework to you.

Checkout following examples

code live demo
nested resource nested resource vdb.defineResource refer other resource

SSR

Fetching initial data for server side rendering is a hard job. It normally requires you to extract out async data dependency into a central place, which makes CSR and SSR code different. vue-db aims to making same component code run in both client and server. You no longer need to lift the data fetching logic to page level, every component can declare its own async data dependency.

vue-db can work with any SSR framework, we recommend vue-fusion

Checkout following examples

code live demo
static page static page renderToString in node with async data provided by vdb.query
server side render server side render async data vdb.query in server side, then hydrated in client side