Skip to content

Enhancement: Make v5 More Expressive #1174

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

Closed
codediodeio opened this issue Oct 2, 2017 · 7 comments
Closed

Enhancement: Make v5 More Expressive #1174

codediodeio opened this issue Oct 2, 2017 · 7 comments

Comments

@codediodeio
Copy link
Contributor

codediodeio commented Oct 2, 2017

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
@Toxicable
Copy link

There has just been a rewrite of the Database API, see here #1158

@davideast
Copy link
Collaborator

@codediodeio Thanks for taking the time to send up this proposal! I'm interested in these changes but I don't think they belong in the core API. Perhaps we could provide an additional module?

@codediodeio
Copy link
Contributor Author

@Toxicable This is in reference to the rewrite.
@davideast A utility module providing Lodash-style simplification would be extremely useful. I predict new users will get frustrated when trying to do basic data wrangling in Angular.

@davideast
Copy link
Collaborator

@codediodeio great! Would you like to flush out a official proposal for a utility module?

@codediodeio
Copy link
Contributor Author

@davideast Is there a template for an "official proposal" or do you mean a PR?

@davideast
Copy link
Collaborator

@codediodeio First we need an issue. There's no official template. You can take a look at what I've done in the past (#1158). It doesn't have to be perfect. The main thing is to include the interfaces and a small code sample so we can get a good idea of how it would be used.

@codediodeio
Copy link
Contributor Author

@davideast Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants