Giter VIP home page Giter VIP logo

Comments (13)

mesqueeb avatar mesqueeb commented on June 15, 2024 1

Hi,
I found a bug in openDBChannel that I fixed in the latest version.

Can you do npm i vuex-easy-firestore@latest and confirm for me?

instead of this:

dispatch('users/openDBChannel', {where: [['uid', '==', 'XYZ']]}))

please try this again:

yourModule = {
  sync: {
    where: [
      ['uid', '==', '{uid}']
    ]
  }
}
// and just do this:
dispatch('users/openDBChannel', { uid: 'XYZ' })

I found a bug that prevented that bottom one from working, but should now be fixed.

Please try it for me and confirm you get this:

createEasyFirestore({
  firestorePath: 'users/',
  firestoreRefType: 'collection',
  moduleName: 'users',
  sync: {
    where: [
      ['uid', '==', '{uid}']
    ]
  }
})

// Run
dispatch('users/openDBChannel', { uid: 'ABC' })
state : { // Result after dispatch('users/openDBChannel', { uid: 'ABC' })
   users: {
      'ABC' : data
   }
}
dispatch('users/openDBChannel', { uid: 'XYZ' })
state : { // Result after dispatch('users/openDBChannel', { uid: 'ABC' })
   users: {
      'ABC' : data
      'XYZ' : data // XYZ is added instead of overwriting
   }
}

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

I'm very confused by your setup.
Is there a reason you need to use firestoreRefType: 'doc' as opposed to collection?

If you just save it like so:

createEasyFirestore({
  firestorePath: 'users/',
  firestoreRefType: 'collection',
  moduleName: 'users',
})

you already have all the setup you need. And users will be added automatically just like you want it to.

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb Tried with collection but how to get multiple like that? Its just replaced their old own object

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

The example I gave above. It will save all users like you want:

state : {
   users: {
      'ABC' : userData,
      'XYZ' : userData,
   }
}

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb Thanks, im not sure why I got..

createEasyFirestore({
  firestorePath: 'users/',
  firestoreRefType: 'collection',
  moduleName: 'users',
  sync: {
    where: [
      ['uid', '==', '{uid}']
    ]
  }
})

// Run
dispatch('users/openDBChannel', { uid: 'ABC' })
state : { // Result after dispatch('users/openDBChannel', { uid: 'ABC' })
   users: {
      'ABC' : 'data'
      // _conf: (...)
      // _sync: (...)
   }
}
dispatch('users/openDBChannel', { uid: 'XYZ' })
state : { // Result after dispatch('users/openDBChannel', { uid: 'ABC' })
   users: {
      'XYZ' : 'data'
      // _conf: (...)
      // _sync: (...)
   }
}

That 'ABC' : 'data' from prev is gone

Note: I'm using where because I don't want to get the whole users

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

@l2aelba I understand what's happening now. The other user document is being removed.

  • a 'collection' is usually for multiple documents grouped in a single vuex module
  • a 'doc' for a single doc also saved in a single vuex module

In your case I want to understand:

  • How many ID's you need to filter on?
  • Why do you need to filter on those IDs?
    This is important to understand if you could maybe set up your firestore DB design differently.

Based on this information I think I can help you better.

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb
Filter ? This we will get the whole users from DB and filter it by client-side?

Are you talking about sync.fillables or where ?

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

No not fillables, I'm talking about where
I mean: you want to only get user's { uid: 'ABC' } and { uid: 'XYZ' }.

Is it always those two? Is it more? Is there a reason you need to filter on specific UID's?

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb Gotcha! You are right!

I got with..

dispatch('users/openDBChannel', { where: [ ['uid', '==', uid] ] })

I did wrong with where in the wrong place like

// dispatch('users/openDBChannel')
sync: {
   where: [
      ['uid', '==', '{uid}']
   ]
}

Thanks so much!

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

@l2aelba Yes, today I have rewrote the library so it's possible to pass new where filters on each openDBChannel.

But, I still want to know why you need to do this.

There's a possibility in your case it's better to use fetchAndAdd instead of openDBChannel. But I don't understand what your app is, or why you want to filter on single ID's.

It's also usually better to just add an extra field to the users you want to retrieve to filter on.
Eg. if you add a field like thisIsTheOne: true to all users you need (eg. 'ABC' and 'XYZ') then you can just do
dispatch('openDBChannel', {where: [['thisIsTheOne', '==', true]]})

Why do you need to filter each time on a specific ID?

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb I making a chat app
I don't want user to watch all changes from all users (Firebase Reading is cost money)

I just want that user to watch changes just their friends :)

So this is just about performance and money

from vuex-easy-firestore.

l2aelba avatar l2aelba commented on June 15, 2024

@mesqueeb Confirmed! It's work now! and thank for this 👍

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

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.

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.