elmatou / vue-pouchdb-lite

A really lite Vue plugin to get your PouchDB databases in every instance.
MIT License
13 stars 5 forks source link

Vue-pouchdb-lite for vuejs v3? #1

Open baradhili opened 3 years ago

baradhili commented 3 years ago

Just wondering if its possible to use this in vuev3?

Thanks

elmatou commented 3 years ago

I did not migrate to vuejs 3 for now. I can't tell if it will work out of the box. looking at https://v3.vuejs.org/guide/migration/introduction.html I don't see anything that will break.

Maybe the data merging strategy for mixins should be checked: https://v3.vuejs.org/guide/migration/data-option.html#overview and the new emit options should be overseen too : https://v3.vuejs.org/guide/migration/emits-option.html

elmatou commented 3 years ago

and The beforeDestroy lifecycle option has been renamed to beforeUnmount

baradhili commented 3 years ago

For other people.. There are a bunch of steps to get pouchdb to import (nothing about working, simply to get past the import step!) in vue3/vite

  1. shim global - <script>window.global = window</script>
  2. fix externalized "events" - add the following to vite.config.js
    optimizeDeps: {
    allowNodeBuiltins: ['pouchdb-browser', 'pouchdb-utils']
    },

    and do yarn add events

then look at the above things

@elmatou I'll fork this repo to do this for the moment

baradhili commented 3 years ago

ok I have something that loads in vue3.. a bit of changes in the way it plugin is exported and I suspect emits now are injects... I haven't written anything using it yet :)

elmatou commented 3 years ago

HI @baradhili

Feel free to fork and make any PR you want. You are using Vite which bundle and load modules with Rollup as Vue-LCI uses Webpack. It is quite natural that it needs some tweaks.

I'll be very glad to review PR on vue3 support, it is the next step for every VueJS developer. As for Vite if it do not break Vue-CLI support I'll accept the PR too, just keep them separate for simplicity.

BananaAcid commented 2 years ago

Hi, i am working on a PR on this, got it working so far, but I am not sure if I something is still broken -

Doing https://github.com/elmatou/vue-pouchdb-lite#reactive--live-selectors-mango-queries - using peopleInOtherDatabase, is setting person.name = "new Name" supposed to change the doc in the db? If a remote DB is used (database: 'https://......../...'), should it update reactively by itself? (if not how would working directly with a remote db need to save changes?) I am not sure of the behavior -

In case you are interested: https://github.com/BananaAcid/vue3-pouchdb-lite ... feedback would be great

elmatou commented 2 years ago

Hi, I have no Vue3 project currently to test this extensively.

The live selector only works for reading doc, as it often return an array for results, they are copied to the data object of the vue instance, and kept accurate when database changes.

If you want changes in doc to be saved in db on each change (which is not recommended with couchdb, as it keep a trace of any changes). You will need to save the record in a specific data object and set a watcher on it.

As it is not a very "lite" feature and not a recommended practice by couchdb, I will not merge this in the lib.

BananaAcid commented 2 years ago

Thanks for the info. Have it in use with a project, works throughout as expected. Dependencies are still an issue (need to be forced to newest version using ncu -u and then npm i --force).