btimby / nimtok

IPFS / Nimiq messaging
MIT License
3 stars 0 forks source link

Extract VueOrbitDB to standalone project. #7

Open btimby opened 3 years ago

btimby commented 3 years ago

I think my Vue plugin VueOrbitDB is abstract and useful enough to stand alone.

https://github.com/btimby/nimtok/blob/main/src/plugins/orbitdb.js

It has the following benefits:

  1. It can be imported into any other module or component and provide access to the orbitdb singleton.
  2. It provides a higher-level pubsub api that:
    1. Filters self.
    2. Can call Vuex store actions when pubsub messages arrive.
  3. Is generic enough to be useful. I will continue to expand it as need dictates.
btimby commented 3 years ago

Tons of progress now, all orbitdb functionality is now in a top-level orbitdb.js module, and uses the plugin. At a high-level, the orbitdb plugin allows you to subscribe to pubsub as well as databases. When data arrives, it can be pushed to vuex. On the other hand, the orbitdb plugin subscribes to vuex mutations, and can keep orbitdb up-to-date with vuex.

https://github.com/btimby/nimtok/blob/main/src/orbitdb.js

This way Vue components only write to vuex and orbitdb is kept synchronized. When events arrive from orbitdb, vuex is synchronized and components react.

I am pretty happy with the result so far, I also moved some unrelated state management into components and out of vuex, so vuex ONLY handles the global state.

btimby commented 3 years ago

I added avoidance for circular synchronization, for example:

  1. Data is read from orbitdb, and committed to vuex.
  2. orbitdb sees the mutation and writes it back to orbitdb.

I want to abstract this, so that whenver orbitdb sends a mutation, the payload includes a flag (that is NOT written to the vuex store). The flag should be used to skip sync in the store subscription handler.

btimby commented 3 years ago

Implement global property:

this.$orbitdb...

Ala vue-router:

https://github.com/vuejs/vue-router/blob/dev/src/install.js#L21

btimby commented 3 years ago

Add an easier way to query, currently I do:

dbname = await orbitdb.open('dbname', 'dbtype');
dbname.db.events.on('ready', () => {
  ...
  await dbname.db.close();
});
await dbname.db.load();

The above is for one-off queries.

btimby commented 3 years ago

Add a way to "follow" a feed or log database, on received event, advance the cursor and dispatch and action for new items.

See: https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions