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

updates more get instances and language in object model #124

Merged
merged 1 commit into from
Jul 31, 2018

Conversation

cspanring
Copy link
Contributor

Attempt to check off task 2 in emberjs/guides#2303 and update some of the language around get and set, including when to and when not to use it.

@jenweber please have a look. might conflict slightly with #122

@cspanring cspanring force-pushed the object-model-get-2303 branch from ae0ab0d to 545aae4 Compare July 30, 2018 17:10
Copy link
Contributor

@jenweber jenweber left a comment

Choose a reason for hiding this comment

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

@cspanring I suggested some minor changes to wording. Can you rebase/merge in master now that the other PR is in? I think some of the changes are taken care of.

and [`set()`][8] accessor methods:
When reading a property value of an object, you can in most cases use the common Javascript dot notation, e.g. `myObject.myProperty`.

The one big exception to this rule are [Ember proxy objects][9]: if you're working with Ember proxy objects, including promise proxies for async relationships in Ember Data, you have to use Ember's [`get()`][7] accessor method to read values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight edit:

[Ember proxy objects][9] are the one big exception to this rule. If you're working with Ember proxy objects, including promise proxies for async relationships in Ember Data, you have to use Ember's [get()][7] accessor method to read values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think maybe we need a small example here.

For example, say there is an Ember Data model, blogPost, which has many comment records associated with it. We could access attributes of the blogPost itself using dot notation, like blogPost.title. However, to show the comments that are part of the relationship, we would need to use blogPost.get('comments').


The one big exception to this rule are [Ember proxy objects][9]: if you're working with Ember proxy objects, including promise proxies for async relationships in Ember Data, you have to use Ember's [`get()`][7] accessor method to read values.

For updating property values use Ember's [`set()`][8] method. It will propagate the value change to computed properties, observers, templates, etc. If you "just" use Javascript's dot notation to update a property value, computed properties won't recalculate, observers won't fire and templates won't update.
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, I suggest that you flip the order of this sentence. "Always use Ember's [set()][8] method to update property values."

@cspanring cspanring force-pushed the object-model-get-2303 branch from 545aae4 to f11a660 Compare July 31, 2018 00:48
@cspanring
Copy link
Contributor Author

@jenweber thanks for your feedback! rebased, updated the language and added a simple Ember Data example to that section. please have a look again.

@jenweber jenweber merged commit 62b6ab7 into ember-learn:master Jul 31, 2018
@jenweber
Copy link
Contributor

Thanks Christian!

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