-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ember "Context" Example * Forgot backing class
- Loading branch information
1 parent
baec35a
commit 11975c8
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<UserProfile /> |
8 changes: 8 additions & 0 deletions
8
content/4-component-composition/5-context/ember/user-profile.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {{this.user.username}}</p> | ||
<p>Email: {{this.user.email}}</p> | ||
<button {{on "click" (fn this.userService.updateUserName "Jane")}}> | ||
Update username to Jane | ||
</button> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
content/4-component-composition/5-context/ember/user-profile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Component from '@glimmer/component'; | ||
import { service } from '@ember/service'; | ||
|
||
export default class UserProfileComponent extends Component { | ||
@service userService; | ||
|
||
get user() { | ||
return this.userService.user; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
content/4-component-composition/5-context/ember/user-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Service from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class UserServiceService extends Service { | ||
@tracked id = 1; | ||
@tracked username = 'unicorn42'; | ||
@tracked email = '[email protected]'; | ||
|
||
get user() { | ||
return { | ||
id: this.id, | ||
username: this.username, | ||
email: this.email, | ||
}; | ||
} | ||
|
||
@action | ||
updateUserName(newUsername) { | ||
this.username = newUsername; | ||
} | ||
} |