Skip to content

ember data section class syntax (#543) - #553

Merged
jenweber merged 9 commits into
octanefrom
unknown repository
Mar 10, 2019
Merged

jenweber merged 9 commits into
octanefrom
unknown repository

Conversation

@ghost

@ghost ghost commented Mar 1, 2019 •

Copy link
Copy Markdown

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?

@attr() firstName;
@attr() lastName;

fullName: computed('firstName', 'lastName', function() {

Copy link
Copy Markdown
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
Copy Markdown
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
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

@ghost ghost Mar 5, 2019 •

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
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


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

Copy link
Copy Markdown
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
Copy Markdown
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.

@attr() firstName;
@attr() lastName;

fullName: computed('firstName', 'lastName', function() {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

ghost commented Mar 11, 2019

Copy link
Copy Markdown
Author

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

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