Skip to content

Commit

Permalink
Ember "Context" Example (#160)
Browse files Browse the repository at this point in the history
* Ember "Context" Example

* Forgot backing class
  • Loading branch information
mastastealth authored Mar 30, 2023
1 parent baec35a commit 11975c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/4-component-composition/5-context/ember/app.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<UserProfile />
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 content/4-component-composition/5-context/ember/user-profile.js
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 content/4-component-composition/5-context/ember/user-service.js
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;
}
}

0 comments on commit 11975c8

Please sign in to comment.