Comments (13)
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.
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.
@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.
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.
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.
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.
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.
Been waiting for this update.
Thanks mate.
from vuex-easy-firestore.
Let me know if any troubles arise!
Sent with GitHawk
from vuex-easy-firestore.
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.
@coolhand79 I agree, but could you open a new issue for this? Thanks!!
Sent with GitHawk
from vuex-easy-firestore.
Much appreciated!! I try to help people wherever I can.
Sent with GitHawk
from vuex-easy-firestore.
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
andcloseDBChannel
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:
- Maps, Arrays and Subcollections, Oh My! | Get to Know Cloud Firestore #4
- How to Structure Your Data | Get to Know Cloud Firestore #5
Keep the discussion going and good luck!
from vuex-easy-firestore.
Related Issues (20)
- cannot read resolve of undefined HOT 7
- Feature: Add firestore.getAll() on the web HOT 7
- Question: can we rely on the `signedIn` getter to check if the user is signed in? HOT 3
- Guard 'id' will still add 'id' on update HOT 1
- Reacting to changes in vue-router HOT 1
- Retrieve subcollections together with document HOT 2
- feat(docs): add firestore guide
- RangeError: Maximum call stack size exceeded HOT 6
- ProjectId not provided in firebase.initializeApp despite being provided HOT 3
- Can't get it to work no matter what! HOT 6
- Two-way binding HOT 4
- Getters undefined when working with users collection + sign in onAuthStateChanged [Help]
- fetch only returns id in doc HOT 2
- Update library for firebase v9 HOT 3
- Adding "in" or "array-contains" to the where clause
- setPathVars should be better documented HOT 1
- Doc insertion from multiple apps at he same index
- project build process HOT 1
- E2E test with Cypress
- syncStack / rejects HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-easy-firestore.