Update Ember syntax (#1704)
It has been a while since Ember has moved away from views to components :)
This commit is contained in:
parent
e0379d3cb4
commit
a6de3c7882
83
ember.md
83
ember.md
|
@ -7,68 +7,65 @@ category: JavaScript libraries
|
||||||
|
|
||||||
### Routes
|
### Routes
|
||||||
|
|
||||||
App.Router.map(function() {
|
Router.map(function() {
|
||||||
this.resource('trips', function() {
|
this.route('trips', function() {
|
||||||
this.route('item', { path: '/:trip_id' });
|
this.route('item', { path: '/:tripId' });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.route('upcoming');
|
this.route('upcoming');
|
||||||
this.route('about', { path: '/about' });
|
this.route('about', { path: '/aboutus' });
|
||||||
this.route('schedules');
|
this.route('schedules');
|
||||||
this.route('history');
|
this.route('history');
|
||||||
this.route('post');
|
this.route('post', { path: '/post/:postId' });
|
||||||
});
|
});
|
||||||
|
|
||||||
### A route
|
### A route
|
||||||
|
|
||||||
App.IndexRoute = Ember.Route.extend({
|
import Route from '@ember/routing/route';
|
||||||
setupController: function(controller) {
|
|
||||||
controller.set('title', 'my app');
|
|
||||||
// <h1>{{title}}</h1>
|
|
||||||
},
|
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
export default PostRoute extends Route {
|
||||||
controller.set("model", model);
|
model({ postId }) {
|
||||||
this.controllerFor('topPost').set('model', model);
|
// Post will be accessible as `this.model` in the controller
|
||||||
},
|
// or `{{@model}}` in the template.
|
||||||
|
return this.store.find('post', postId);
|
||||||
model: function(params) {
|
|
||||||
return this.store.find('posts');
|
|
||||||
return this.store.find('post', params.post_id);
|
|
||||||
},
|
|
||||||
|
|
||||||
serialize: function(model) {
|
|
||||||
// this will make the URL `/posts/foo-post`
|
|
||||||
return { post_slug: model.get('slug') };
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
### View
|
|
||||||
|
|
||||||
App.InfoView = Ember.View.extend({
|
|
||||||
templateName: 'input', /* optional */
|
|
||||||
|
|
||||||
fooName: "Hello" /* {{ view.fooName }} */
|
|
||||||
|
|
||||||
click: function(e) {
|
|
||||||
"I was clicked";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
### Component
|
||||||
|
|
||||||
### markup
|
import Component from '@glimmer/component';
|
||||||
|
import { tracked } from '@glimmer/tracking';
|
||||||
|
|
||||||
<img {{bindAttr src="avatarURL"}}>
|
export default PostEditor extends Component {
|
||||||
<button {{action follow}}>
|
@tracked title;
|
||||||
|
|
||||||
Value binding:
|
get fullTitle() {
|
||||||
|
return `Post: ${title}`;
|
||||||
|
}
|
||||||
|
|
||||||
{{view Ember.TextField class="input block" valuebinding="emailAddresses"}}
|
titleUpdate(event) {
|
||||||
|
this.title = event.target.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Actions:
|
### Template
|
||||||
|
|
||||||
<button {{action invite emailAddresses}}>Invite></button>
|
<div ...attributes>
|
||||||
|
<label for="title">Title</label>
|
||||||
|
<input
|
||||||
|
id="title"
|
||||||
|
value={{@post.title}}
|
||||||
|
{{on 'input' this.updateTitle}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{this.fullTitle}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Invoking the component:
|
||||||
|
|
||||||
|
<PostEditor class='my-post' @post={{@model}} />
|
||||||
|
|
||||||
<a href="#" {{action set "isEditingContacts" true target="view"}}
|
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
|
Loading…
Reference in New Issue