Closed
Description
TL:DR Here's a demo of how the v5 could be more expressive (see app.component). https://stackblitz.com/edit/angular-q7fbm7
The new API is looks good from a minimalist perspective, but it misses the opportunity to simplify tasks should be easy. Let's say you want to do something very common - query a list, then make secondary queries for denormalized data with a specific key.
// v4
const books = db.list('/books', { query: { limitToFirst: 5 } })
// v5 (this is not approachable code IMO)
this.ref = db('books', ref => ref.limitToFirst(5) )
const books = ref.snapshotChanges().map(arr => {
return arr.map(snap => Object.assign(snap.payload.val(), { $key: snap.key }) )
})
Proposal
Make common tasks easier to read and perform. The new flexibility can be preserved, while giving developers a simple and approachable API. I hacked together this wrapper of my vision here: https://stackblitz.com/edit/angular-q7fbm7
// option to make queries with objects - much easier than chaining methods in most cases
const ref = db.query('books', { limitToFirst: 5 })
// use a new get method to make the API expressive and flexible
const books = ref.get({ withKeys: true })
// Do other useful stuff while we're at it
ref.get({ reverse: true }) /// reverse list
ref.get({ callback: callbackFn }) /// map the array with your own callback
Metadata
Metadata
Assignees
Labels
No labels