Control your magic strings in Firebase projects
Firebase's real-time database JavaScript API makes it really easy to wind up with a ton of magic strings in your codebase. Since you access data via "refs" like:
In that example, "customers/1" is a magic string that points to some data in the database. Magic strings are well known as something to avoid in software development. And here we are updating a database with one, yikes!
These can easily be managed via patterns. I've been abstracting these into their own modules in an "API-like" pattern. For example:
And then use it like:
TweetAlso
protected-ref
is a firebase package that manifested from this TIL: https://til.hashrocket.com/posts/hyrbwius3s-protect-yourself-against-firebase-database-refs