IjzerenHein / firestorter

Use Google Firestore in React with zero effort, using MobX 🤘
http://firestorter.com
MIT License
378 stars 50 forks source link

Suggestion: Collection.hasData #67

Closed damonmaria closed 5 years ago

damonmaria commented 5 years ago

I find myself regularly using collection.docs.length > 0 in my React components. While being verbose it also causes excess re-renders as documents are added and removed, changing the length but length > 0 is still true.

What if there was a @computed hasData(): boolean property on Collection that internally did this check. This would then match the definition of Document.hasData ("True whenever the collection has any docs") and would solve the re-rendering issue.

damonmaria commented 5 years ago

Happy to do a PR.

IjzerenHein commented 5 years ago

That sounds like a very good idea. I had thought about is as well, but hadn't really found a use-case for it myself, but this sounds like a very valid one. Considering, Document has data, and Collection has docs, would you consider hasDocs to be a better name?

damonmaria commented 5 years ago

Agreed, hasDocs is more "does what it says on the can" than hasData.

IjzerenHein commented 5 years ago

Released as https://github.com/IjzerenHein/firestorter/releases/tag/v1.2.2