MDSLKTR / pouch-vue

Pouchdb bindings for Vue.js
MIT License
90 stars 17 forks source link

pouch-vue trigger way to much events ! #52

Closed elmatou closed 4 years ago

elmatou commented 4 years ago

Not really a bug, not really a feature.

Using pouch-vue ase a Vue plugin, it instantiates on every components render. In vue-dev-tool it look like this :

image

That is only part of the dump, here is the typical event.

name:"pouchdb-db-created"
type:"$emit"
source:"<BInput>"
payload:Array[1]
0:Object
db:Object
ok:true

It seems a but to much of events triggered, and maybe to much of db created. Can't we make leverage of provide / inject ?

https://vuejs.org/v2/api/#provide-inject

elmatou commented 4 years ago

Looking at the code I see that $pouch is instantiated in each component as a mixin. It do not look like it is very useful, maybe I can try to instantiate it as a "Vuejs Instance Properties". By this the object would be set one a for all and not in each component (reducing memory load, events, ...)

@assemblethis @MDSLKTR, would anybody mind if I try a PR on this matter?

elmatou commented 4 years ago

I found the culprit !

https://github.com/MDSLKTR/pouch-vue/blob/9637b04655f91330693b5c854c256c642e5aba55/src/index.js#L45-L47

there is no use to create the database upon component creation. it is checked in every methods: https://github.com/MDSLKTR/pouch-vue/blob/9637b04655f91330693b5c854c256c642e5aba55/src/index.js#L143-L145

MDSLKTR commented 4 years ago

Since i don't use or maintain this library anymore, feel free to change things for the better. Any PRs can be merged. This library started as a proof of concept so there are flaws for sure.

elmatou commented 4 years ago

To be honest, With no news, I figured out, that despite the warning in the README, this project is a bit stalled.

So, I started my fork, for my own purpose : https://github.com/elmatou/vue-pouchdb-lite

MDSLKTR commented 4 years ago

No worries, this is certainly true

assemblethis commented 4 years ago

Looking at the code I see that $pouch is instantiated in each component as a mixin. It do not look like it is very useful, maybe I can try to instantiate it as a "Vuejs Instance Properties". By this the object would be set one a for all and not in each component (reducing memory load, events, ...)

@assemblethis @MDSLKTR, would anybody mind if I try a PR on this matter?

You could try using pouch-vue as an event bus which is what the Boatnet project does: https://github.com/nwfsc-fram/boatnet-module/blob/master/bn-pouch/src/_services/pouch.service.ts

A new Vue instance is instantiated in the last line: export const pouchService = new PouchService();

Then they attach listeners to a Vuex store where state is kept: https://github.com/nwfsc-fram/boatnet-module/blob/master/bn-pouch/src/_store/pouch.module.ts

It's one way of doing it.

dgleba commented 4 years ago

@assemblethis Can you comment on the difference between your proposal and @elmatou's fork at: https://github.com/elmatou/vue-pouchdb-lite?