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

ember data section class syntax (#543) #553

Merged
merged 9 commits into from Mar 10, 2019
Merged

ember data section class syntax (#543) #553

merged 9 commits into from Mar 10, 2019

Conversation

ghost
Copy link

@ghost ghost commented Mar 1, 2019

Current progress addressing #543.
See background discussion in the dev-ember-learning channel.

open questions / related issues

  1. what should we teach in introducing Ember Data Models? computeds vs. decorators #554
  2. standardize decorators and remove usage of ember-decorators
  3. In that discussion, @pzuraq noted we should use const { Model, attr } = DS; to then use @attr for model attributes. I think this syntax is clearer, but it is slightly inconsistent with example ember-data snippets. (e.g. extending DS.JSONSerializer). Should we use destructuring anywhere we import from DS?

lastName: DS.attr(),
export default class Person extends Model {
@attr() firstName;
@attr() lastName;

fullName: computed('firstName', 'lastName', function() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mix of syntaxes has problems. See #554.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think for now we can just make this a standard ES6 getter, and not a computed property

@ghost ghost changed the title WIP class syntax WIP ember data section class syntax (#543) Mar 1, 2019
@@ -204,22 +208,23 @@ Requests for `user-profile` would now target `/user_profile/1`.
Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary
headers can be set as key/value pairs on the `JSONAPIAdapter`'s `headers`
object and Ember Data will send them along with each ajax request.
(Note that we set headers in `init()` because default property values
(Note that we set headers in `constructor()` because default property values
Copy link
Author

@ghost ghost Mar 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using native classes supersede this implementation quirk ? IIRC, this pattern is because of EmberObject.extend #566

@ghost ghost changed the title WIP ember data section class syntax (#543) ember data section class syntax (#543) Mar 7, 2019
headers: computed('session.authToken', function() {
export default class ApplicationAdapter extends JSONAPIAdapter {
@service session;
@computed('session.authToken')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove @computed here and just make this a tracked property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather, session.authToken should be considered a tracked property, and this can just be a normal getter

@@ -580,15 +595,17 @@ You would define your relationship like this:

```javascript {data-filename=app/serializers/post.js}
import DS from 'ember-data';
const { EmbeddedRecordsMixin, JSONSerializer } = DS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EmbeddedRecordsMixin will be tricky, ideally we can avoid mixins altogether. We'll have to work with the Ember Data team to figure out what the future is here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. I chatted briefly with @runspired in #dev-ember-data to get a quick port of the syntax. Same theme there.

lastName: DS.attr(),
export default class Person extends Model {
@attr() firstName;
@attr() lastName;

fullName: computed('firstName', 'lastName', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think for now we can just make this a standard ES6 getter, and not a computed property

@runspired
Copy link
Contributor

In that discussion, @pzuraq noted we should use const { Model, attr } = DS; to then use @attr for model attributes. I think this syntax is clearer, but it is slightly inconsistent with example ember-data snippets. (e.g. extending DS.JSONSerializer). Should we use destructuring anywhere we import from DS?

Yes. See also the blueprints we just merged that do destructure.

@jenweber jenweber merged commit fa6aeab into ember-learn:octane Mar 10, 2019
@jenweber
Copy link
Contributor

Thank you @efx for your work and sorting out some of these open questions!

@ghost ghost deleted the fix-543 branch March 11, 2019 12:50
@ghost
Copy link
Author

ghost commented Mar 11, 2019

certainly @jenweber ! I'll follow up with another PR that addresses #566 and the tutorial section.

lenoraporter pushed a commit to lenoraporter/guides-source that referenced this pull request Jul 19, 2020
* WIP class syntax

* fix relationships snippets

* mostly convert adapters + serializers

* update to runspired's explanation of double extend

* update other examples, fix typos

* address comments to clean up examples

* unify destructuring style
lenoraporter pushed a commit to lenoraporter/guides-source that referenced this pull request Jul 19, 2020
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.

4 participants