-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Firestore Support #274
Comments
I've been prototyping something and hope to work with @tjmonsi to get it in releasable shape soon. Stay tuned! |
WOW nice! Would be another component not part of the polymerfire? For example another web component called polymerfirestore? |
TBD, as I said, stay tuned! |
Thanks I will :) |
Re-opening to leave as a single feature request. |
Should we do it as a behavior/mixin or a component? |
@tjmonsi A component like firebase-query would be great since it would make the 'getting started' part much easier. |
I guess a similar approach to how it's done with the real-time database would be best. Have a With the extended query functionality (like chaining wheres/orders) it will be challenging to implement an all-purpose query component... |
Btw, I'm open to testing this as soon as you have a branch/repo public somewhere :) |
@Scarygami will ping you once I am done. (Just finishing a devfest site and some experiments) |
FWIW, I don't know that the existing approach is going to work well for Cloud Firestore, especially due to the query complexity that is possible as compared to the Realtime Database. I'm probably going to try to pull my experimental library into a branch so everyone can take a look and see if you like my approach (it's a class mixin, not an element). |
@mbleigh yeah that's my thought as well. |
I'm curious what this might look like. Suppose you could simply modify the firebase-app tag to point to your firestore database. The firebase-query and firebase-document elements would still work. If you want to add pagination you would simply add a "page-size" attribute to your query, and advance the start-at pointer. This would cut down on the amount of work required to migrate over to firestore. |
In general, if you try to treat things that aren't the same as being the same, you're going to have a bad time. Cloud Firestore is fundamentally different from the RTDB in many ways, so trying to shoehorn it will have negative tradeoffs when the square peg doesn't actually fit the round hole. Again, I'm trying to get my experimental library in a branch for people to try out as a potential approach. |
Here's the problem. If anyone has an existing project, they're going to have to touch every query and document element to get this to work. There's nothing that says that there has to be a 1-to-1 correspondence between firebase elements and underlying classes and the JavaScript library. |
@phidias51 As for the |
@mbleigh I love your implementation ;) I hope to be well received by the community and be available in polymerfire. Also, I'm writing a blog post about my experience with Polymer and Firestore. Do you have any plans to make the repo public? I want to know how much can I describe and refer your class mixin implementation in my post. |
@imarian97 if you wait until next week I think we'll have it in a branch on this repo 😄 I'd love to see your blog post if you have a way to share drafts before you publish. |
Perfect, I'm planning to publish it next week and for sure I'll share it before |
All right, I've gone ahead and taken a rough pass at porting my experimental work into PolymerFire, and you can check it out at #278. Folks who are interested, feel free to install the |
Played a little bit with the mixin and really liking it so far. Send a PR for an issue I ran into with firebase-app not being ready before the mixin tried to do something with firestore. Some questions/suggestions:
I leave these topics up for discussion and can send PRs for ideas we agree upon. |
I was a little anxious how it would work as a mixin, but the solution seems really neat and tidy. I like not having to add non-rendering dom.
|
@mbleigh Here is my blog post on our new blog (built with Firestore and polymer) 😄 https://goldielabsite.firebaseapp.com/post/firestore-new-blog. We are planning to publish it tomorrow (to our domain: goldielab.com) and I hope you like it. |
So far looks very promising. Kudos. |
I'll merge this to master by tomorrow. Then release a new version. |
I'd love to get an official release with Firestore in it. However, with this main branch I continue to get the following error:
When I apply a version of the fixes available in https://github.com/firebase/polymerfire/pull/279/files this goes away. |
I'm referring to #274 (comment) As @Scarygami mentioned, the element strips away the snapshots, only returning the data. I want to fetch subcollections and need the Are there any plans to do so? Many thanks :) |
@merlinnot I'm a little confused on why you went with a Mixin to bind Polymer properties to database value(s) rather than use Polymer elements as was done with Firebase Realtime Database? @tjmonsi Is this how it's going to be done moving forward? |
@JaySunSyn @MarcMouallem
|
IMO, “mixin vs. elements” is the wrong question. Why not both? IIUC, e.g. Firebase Realtime Database support in PolymerFire is implemented as On the one hand, there is an extra performance cost for registering web component as an HTML element, DOM declaration and data binding. Every property does come at a cost (observers, listeners, etc.) that are not necessary for working with Cloud Firestore. But on the other hand, web components are extremely easy to use. Avoiding web components breaks the original Polymer's “There's an element for that” idea. |
Please remember that Polymer was initially conceived as a library that helps create declarative, encapsulated, reusable elements, and use them to break apps up into right-sized components, making code cleaner and less expensive to maintain (https://developers.google.com/web/updates/2014/01/Chrome-Dev-Summit-Polymer-declarative-encapsulated-reusable-components). One of the key words here is “declarative”. Declarative code has powerful advantages, which all boil down to hiding complexity and exposing it simply. With declarative code, we tell the computer what to do, not how to do it. That makes declarative code easier to understand and therefore to create. Anyone can tell someone what to do. Telling someone how to do it can be much harder. What's more, describing programs in chunks of what is not only easy, it takes less code. Declarative code opens up the world of programming to more people, and helps those people do more while expending less time and effort. Web components help lower the barrier to entry for building complex, well-structured apps. See the following amazing article for more info: https://scotch.io/bar-talk/universal-web-components. If you think that web components are not suitable for non-visual elements (there is an extra performance cost for registering web component as an HTML element, DOM declaration and data binding; every property does come at a cost (observers, listeners, etc.) that are not necessary for working non-visual elements), you are wrong. Yes, many of the web components available now are visual, but not all. Take a look e.g. at As the layer we're using for composability is the DOM using attributes for our APIs, our elements will be significantly more interoperable than they've been in the past. Imagine a future where elements or components written with different libraries can be used together with a level of ease. Elements will (ideally) be created with a minimal amount of script and will try to reuse the functionality of other sub-elements where possible. The original idea of web components was: “web apps in the near future will be composed almost entirely from elements (tags)” (see https://addyosmani.com/blog/the-webs-declarative-composable-future/). You can think of web components as Lego bricks. People can build apps with no code (see https://medium.com/@ladyleet/building-apps-with-no-code-a-web-component-future-4cf29a27ccdd). Creating mixins instead of elements killing the Polymer's philosophy behind “Everything is an element” mantra. I can't help feeling that Polymer is moving in the wrong direction. See e.g. the deprecation of declarative Polymer slowly killing the original idea behind “declarative” and moves in the direction of increasing complexity. Where there used to be HTML files with a bit of JS code (all kinds of people who would not be considered programmers can and do work with HTML code), there are JavaScript files with a bit of HTML (HTML templates are now defined by providing a template getter that returns a string — not the See https://github.com/ebidel/declarative-web-components and https://github.com/Polymer/lit-html to see the differences in the approaches. The latest Polymer changes only confirms this idea. Importing web components by package name, rather than the path to the package (as required by the HTML specification) means that people can't anymore just drop some tags (HTML elements) to the page and run the code without requiring any special tools or build steps. This doesn't fit with Polymer's “Use the Platform” motto. But that's a whole different story… P.S. Why GraphQL is one of the top mainstream tech to learn in 2018 (trend, buzzword)? Some people claim GraphQL is a REST killer. But why the fuss? Because it's declarative! It gives you the power to ask (show) for what you need and get exactly that, nothing more and nothing less. One call to one endpoint is enough. You simply send a string that describes the data you want and how you want it structured and you get it back in JSON (you tell what to do, not how to do it). GraphQL queries always return predictable results. You can think about GraphQL as declarative data fetching for modern web apps. I'm super excited to see what I can build using the declarative GraphQL data query language and declarative Polymer web components together. 😉 @ebidel @addyosmani @justinfagnani @notwaldorf @robdodson How do you feel about all this? |
I agree with you on your point about the mixin and element but I will have to stop you there when you said about Workbox, lit-html, Web Animations API and CSS Animations. You see not all SHOULD be in the HTML tag. I agree, it is easier to be declarative, but not all declarative parts should be in the DOM. You see And Workbox or service workers are specialized Web workers, which cannot and will not handle DOM. That means a DOM element to handle code for service worker will not work. I am sorry if I am triggered by this but understanding what should be in the DOM and what should not be in the DOM should be clear. It doesn't mean that if it is NOT in DOM, then it is NOT declarative. As for And for "This [ES6] is not only increases the barrier to entry for people who want to just break their HTML apps into well-abstracted components, it forces to write more code." I only have this to say - ES6 is THE standard. It makes it you write LESS CODE which in turn makes your app RUNS FASTER.
The thing is, Polymer 3 still allows you to write it in HTML tag, just use And don't think that JS is imperative only. It has declarative parts! Think functional programming and you'll get the drift. The thing is, your post above has a lot of misleading assumptions on Polymer going away from using the platform when in fact it is using the platform
The point is, if your "declarative" path is taking you AWAY from being performant on the platform, then it is should be taken out. Period. To end, all declarative objects has its imperative internals. Which goes into my thought process on the Firestore Mixin - it is an imperative internal of the Firestore Element i'm coding (which is i am not yet done because of work) If you looked at the code pattern here, they used So the |
You're definitely a little triggered, but no too much ;) Just as an update, I'm still going to write some tests for the mixin, but I'm not entirely sure if I'll manage to do it this weekend. I have some paid work to do too ;) |
Yeah me too, and they keep piling up. I have to really release this and have to work on the firestore-element soon. And then create little scenarios to make it sure it works. |
By your logic, we should still program in assembler. Optimizing for performance is short-sighted, because the platform improves all the time, and because hardware improves. We still think manipulating the DOM is slow, but @Swizec has recently pointed out that's technically no longer true. Optimizing for developer experience will serve everyone better in the long term, and transpilers can take care of optimizing for performance under the hood. |
Nitpicking on that particular line alone would really mean what you have said, but your missing the context of it.
I do agree, but I do hope you put it in the context of what I said to what @FluorescentHallucinogen was suggesting: Deprecating some custom-elements over proper usage of the platform on the context of service workers, web animation api, css animations, and usage of ES6 code. The latter are far more superior in terms of both performance and user dev experience than the former custom-elements created for it and coding in ES5. But if we really want it to be declarative, by all means, create a custom-element that will use those API to abstract the imperative part of it and make it declarative. And I didn't say anything about manipulating DOM being slow, or not better used. All I am saying that there are new APIs involved and they are the improvements in the platform and we should use it, not fall trap on old declarative code that doesn't use the improvements in the platform. These new APIs are here to serve everyone in long term. If they think they are still imperative, create a declarative abstraction of it to help others. |
FWIW the reason I went with a mixin instead of declarative elements is because I felt that Firestore's query model was going to end up making a declarative element fairly unpalatable. With the complex interactions of I don't have any objection in theory from declarative Firestore elements, but feel the mixin is overall a better developer experience for this case. If someone designs a rad declarative API that feels great, I'd certainly be willing to consider the pull request (not that I have had much time to consider pull requests on this repo 😢). |
Tests are not finished yet, but I've already started and I have some progress: https://github.com/merlinnot/polymerfire/tree/fix-issue-333 I'll try to make a PR tomorrow 🛌 |
Could you please show your sample code as an example of how you are using it to manage the "loading" state? I want to do the same thing and I'm finding it difficult. |
is this still the most up to date branch? Planning on integrating this in an app and hopefully help in the development process! |
Yes, this is the most up-to-date branch. I could use some help, I'm really busy lately. |
I would be happy to. Quick question though...are there any issues with collections specifically? I have the following:
which is the correct length, but the values are undefined. I'm about to do a deep dive on the source code, but hopefully you can point me in the right direction before! |
After some more testing, it seems the problem is only on initial load. I added a document to the collection, and surprisingly it correctly displayed. After reloading the app, all values were once again undefined. |
@kr05 I've had a number of issues working with this branch and have made a number of fixes into PRs and https://github.com/westbrook/polymerfire/tree/firebase-no-empty-strings if you want to see if your issue persists therein. @merlinnot I've been working with the above branch in production for a couple of weeks with no issues. If there is some way I could support getting those changes or others mainlined so an official release can be cut, please let me know. |
I’m using the current polymerfire#firestore in production with no issues (variety of documents and collections). The branch with tests has some changes which I made during the testing, but it’s not finished and there might be arbitrary large number of issues ;) Feel free to make a PR against my branch (the one with tests), I’ll review it ASAP (I really want to make it production-ready). We can combine it into one, well tested and really nicely written solution and make one PR upstream so it’s easier for Firebase guys to review and merge. You can reach out to me on Slack, email, here, however you want. We can even do some pair programming if you feel like it, Google Meet or a visit in Amsterdam will do ;) |
@kr05 that would be incredibly helpful if you could add a failing test to my branch with tests. I haven’t seen such behavior before. |
I have a feeling that the culprit is "assignedDocument". The argument "instance" is null. I can't say for certain if it's the cause of the problem, but I have a feeling it shouldn't be null. I'll keep trying to find a solution. As for the main firestore branch, I just installed it and my collection loads sucessfully! |
@mbleigh @kr05 @merlinnot Could someone tell me how to initialize the firebase-app component for usage with the firestore mixin? As far as I can tell the firebase-app component is only meant to work with firebase realtime database, since the 'database-url' property only references the Firebase Realtime Database. |
The only thing you need is project ID. |
Is there any leftover problem that is keeping this issue from getting closed and the branch from getting pushed to master? It has been 9 months now since Firestore has been first introduced and there is still no official Polymer solution from the Firebase team. @merlinnot has made some great contributions and I am currently using them without any issues. It would be great to see this issue finally getting closed 👍 |
No tests = doesn’t work ;) |
Guys very nice work, im new, but I like Polymer and I realy want to use it with Firestore, but I cant understand very well how to use it with this mixin :( ¿could you help me with a practical example? Please. Thanks a lot, you are doing an excelent job. |
If you’re just starting, don’t start with Polymer 2 and this library. Go with lit-html and RxJS or Redux + Redux Saga, it will make you a happier person :) |
So just found out that firebase has released a new feature called firestore. Lovely (sarcastic way). I read about it and it does seem interesting and looks more powerful than the real time database. Now the question is any plans on creating polymerfirestore? LOL LOL
The text was updated successfully, but these errors were encountered: