I thought I’d briefly share some observations from my learning and using Ionic2 with AngularFire and Firebase over the last few weeks. I’ve managed to build what I consider a fairly sophisticated app with great ease. Compared to the Android apps I’ve built I’ve been fantastically impressed with the speed at which new ideas can be explored with this platform. I had used Appcelerator several years ago and this seems so much easier. I recognize there are differences in approaches, but the current-day toolchain is proving very attractive.
Now my quick observation…
Getting used to an always-available, asynchronously maintained database source with Firebase has been interesting. I’ve literally had to change my whole approach to working with external data. Decades of working with transactional-oriented on-request solutions with traditional SQL-oriented sources has made it a bit challenging, but I’m adapting - and changing my coding styles in the process.
When I first started with Ionic and Firebase (through AngularFire2) I kept trying to force Firebase into behaving like a more traditional source - not so much the data itself - but the manner in which I accessed it. I’d build elaborate wrappers to follow the chain of asynchronous events with promises and callbacks and it became, well, quite challenging.
My new approach is to place watchers (observable handles returned through “subscribe”) into a global provider module. I start them up when my app starts and let them collect and maintain data autonomously.
The modules/pages that need to access data now just request copies of those data from the globals module or employ methods in the globals module to perform in-memory scans of said data.
Basically, I’m using Firebase to capture my data and treat them like always-available arrays and dictionaries of data that my app can peek at whenever and wherever it’s needed. Individual modules no long make requests on their own to find data. They now assume the data is there and available, all the time.
This way of working seems to work very well for data sets measured in megabytes (or less) vs. extremely large data sets (that couldn’t possibly be handled in the same manner).
Frustrations of working with a new platform and set of tools is slowly melting and become great admiration. And, I look forward to Ionic2’s final releases and continued development.