Skip to content
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

[DOC release] Change misleading documentation for AdapterPopulatedRecordArray #5620

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

happycollision
Copy link
Contributor

@happycollision happycollision commented Sep 1, 2018

In my experimentation, I've discovered that though the promise returned from store.query() does have array-like methods on it, the actual AdapterPopulatedRecordArray is what the promise resolves to. The promise does not behave like a proxy (or what I think Ember Proxies do...). The documentation for store.query states this plainly, but the documentation here misrepresented that.

For example, the original code actually would behave like this:

  // GET /users?isAdmin=true
  var admins = store.query('user', { isAdmin: true });

  admins.then(function() {
    console.log(admins.get("length")); // Throws: "admins.get" is not a function
  });

@happycollision
Copy link
Contributor Author

I'm about to force push to change the commit message to meet your standards.

In my experimentation, I've discovered that though the promise returned from `store.query()` does have array-like methods on it, the actual `AdapterPopulatedRecordArray` is what the promise *resolves to*. For example, the `length` property of the object returned from `store.query` will always be `0`. The object which the promise resolves to will represent the actual length of the records that were queried.

The documentation for `store.query` states plainly that the AdapterPopulatedRecordArray is the *resolution* of the promise, but the documentation here misrepresented that.

For example, the original code actually would behave like this:
```javascript
  // GET /users?isAdmin=true
  var admins = store.query('user', { isAdmin: true });

  admins.then(function() {
    console.log(admins.get("length")); // Throws: "admins.get" is not a function
  });
```
@happycollision
Copy link
Contributor Author

And once more to remove things inside the commit message where I am speaking a little bit about things I don't know.

I realize that when I read commit messages that are merged, I take them to be the actual truth. In my original commit message, I made a comment referring to Ember's ProxyObjects, but I am really not 100% sure how those work. And that comment is actually not pertinent to this change anyhow.

@runspired
Copy link
Contributor

I'm in favor of this documentation change; however, historically speaking query did return a PromiseArray. we may have broken something over time without realizing it. In today's world of async await and better promise knowledge, just working with the promise is preferred anyway.

@runspired runspired merged commit 1cac25e into emberjs:master Sep 5, 2018
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

Successfully merging this pull request may close these issues.

2 participants