QurateInc / vue-pouch-db

Vue Pouch DB is a VueJS Plugin that binds PouchDB with Vue and keeps a synchronised state with the database. Has support for Mango queries which are processed locally within the VuePouchDB state.
MIT License
126 stars 14 forks source link

Plugins methods #9

Closed vdcrea closed 6 years ago

vdcrea commented 6 years ago

Hi, and thanks for this vue plugin.

Is it possible to trigger a plugin's method from Vue logic? I'am trying to use pouchdb-authentication, so configured my global set for vue-pouch-db like that:

const bucket = new VuePouchDB.Bucket({
    config: {
      options: {
        skip_setup: true
      },
    },
    plugins: [
      require('pouchdb-authentication')
    ]
  })

I tried this.$bucket.login() and this.$bucket.state.login() but I run out of idea to understand how to use plugins.

vdcrea commented 6 years ago

Ok I finally got it, reading the source and testing, vue-cli's webpack may not like to require the plugins.

This doesn't work with vue-cli's webpack template:

const bucket = new VuePouchDB.Bucket({
    plugins: [
      require('pouchdb-authentication')
    ]
  })

But this works:

import PouchdbAuthentication from 'pouchdb-authentication'
const bucket = new VuePouchDB.Bucket({
    plugins: [
      PouchdbAuthentication
    ]
  })

Then to trigger the plugin's method, use a named db, ex: this.$bucket.db('dbname').login(username, password).