Giter VIP home page Giter VIP logo

Comments (13)

mesqueeb avatar mesqueeb commented on June 15, 2024 6

Hi everyone. I updated the library that it's easier to close and open with a new variable.

This should now work out of the box:

store.dispatch('projects/openDBChannel', { orgId: '123' })
store.dispatch('projects/closeDBChannel', { clearModule: true })
store.dispatch('projects/openDBChannel', { orgId: '456' })

To update npm i vuex-easy-firestore@latest

What changed under the hood :

your_module._conf.firestorePath now keeps the variable placeholder as is, and is only replaced with the variable in a new getter called firestorePathComplete

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024 1

Dear James,
You can do something like:

store.dispatch("chats/messages/closeDBChannel", { clearModule: true })
store.state.chats.messages._conf.firestorePath 
// output => "chats/WprFVJWGR10Y6S4W9zv3/messages"
store.state.chats.messages._conf.firestorePath.replace(/\/([A-Za-z0-9]+)\//, `/${[NEW_ID]}/`)
// output => "chats/NEW_ID/messages"
store.dispatch("chats/messages/openDBChannel")

(credit to @jgiovanni and his post)

It should work fine. Just adjust a little to your config.

I will think about better ways to do this in the future and let you know here if I come up with any new ideas or if I add a new functionality to the library.

Feel free to continue the conversation and let me know if you're stuck. If you get it working please close the issue. Thakns!

from vuex-easy-firestore.

jlave-dose avatar jlave-dose commented on June 15, 2024 1

@mesqueeb Thanks for your reply. I did have to change the code slightly since String.prototype.replace doesn't mutate the original string and also to accept a new parameter according to @berendsmatt's reply above:

this.$store.dispatch('projects/closeDBChannel', { clearModule: true })
const newFirestorePath = this.$store.state.projects._conf.firestorePath.replace(/\/([A-Za-z0-9]+)\//, '/{orgId}/')
this.$store.state.projects._conf.firestorePath = newFirestorePath
this.$store.dispatch('projects/openDBChannel', { orgId: '123' })

from vuex-easy-firestore.

coolhand79 avatar coolhand79 commented on June 15, 2024 1

I created an issue, but I'm not quite sure how to turn it into a bug....

BTW - you're crushing it! You've got something here, I really like it!

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024 1

After about two years of open source, I finally got accepted for Github Sponsors!

πŸ’œ github.com/sponsors/mesqueeb πŸ’œ

A little about me:

  • I love open-source
  • 6 months ago I got a son, and am trying to be an awesome father πŸ˜…
  • I'm doing freelance work here and there as my main job

If anyone was helped with vuex-easy-firestore, I'd greatly appreciate any support!

BTW, donations get's paid DOUBLE by GitHub! (they're alchemists... 🦾)

Going forward πŸ‘¨πŸΌβ€πŸ’»

  • I got great plans for the future of vuex-easy-firestore going above and beyond!! Look forward to it!!
  • On to many more years of open-sourcing! πŸŽ‰

from vuex-easy-firestore.

berendsmatt avatar berendsmatt commented on June 15, 2024

Hi Luca,

I thought it was going to work this way...
store.dispatch("projects/closeDBChannel", { clearModule: true }) this.$store.dispatch('projects/openDBChannel', { orgId: <newOrgId> })
Can the call openDBChannel set a NEW_ID if one is passed?
store.state.chats.messages._conf.firestorePath.replace(/\/([A-Za-z0-9]+)\//, /${[NEW_ID]}/)

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

Hi Luca, ...

@berendsmatt you currently cannot pass a new path-variable (id) just like that because on the first openDBChannel the firestore path gets replaced with the path with the variables filled in.
Therefor on the second time it will not know where to place your new path-variable.

I will need to improve this and will do so this weekend.

Please see James’ reply above. This is the best method!

To review that method: manually do a replace of your old path variable with the new one in your_module._conf.firestorePath and also pass it again on openDBChannel to be sure where-filters that use that variable won’t break.

Sorry if it’s a bit confusing right now. : S

Sent with GitHawk

from vuex-easy-firestore.

berendsmatt avatar berendsmatt commented on June 15, 2024

Been waiting for this update.
Thanks mate.

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

Let me know if any troubles arise!

Sent with GitHawk

from vuex-easy-firestore.

coolhand79 avatar coolhand79 commented on June 15, 2024

Could it be that same treatment needs to be added for sync options so that filter conditions can be changed when re-opening a DBChannel?

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

@coolhand79 I agree, but could you open a new issue for this? Thanks!!

Sent with GitHawk

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

Much appreciated!! I try to help people wherever I can.

Sent with GitHawk

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

Hi everyone in this thread!

I just wanted to comment on the topic of how to work with multiple sub-collections in Firestore (and this library).

In my opinion it is usually better to work with a flatter database and filter on certain fields (using where()).
Eg. when you have a collection of user [lists] with each a sub-collection with [items].

  • You'll have a hard time querying items when searching through multiple lists;
  • with this library you'll need to do openDBChannel and closeDBChannel and open again with new pathVariables all the time.
  • It will also be harder to implement functionality to allow an item to be added in multiple lists etc.

That's why in such a case it's usually better to have some basic "lists" info on a single document with maybe just the names of the lists. And have a single "items" collection which is not nested, with all items. Then query for items .where('list', '==', 'something').

Thinking about the best database structure is very important. And I want to emphasize that if you need to use a lot of pathVariables and also open and closeDBChannel a lot with vuex-easy-firestore, there is a big chance you do not have the best database structure.

I highly recommend everyone to watch these specific two videos on Firestore database structure by the Firebase team. They helped me a lot:

Keep the discussion going and good luck!

from vuex-easy-firestore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.