Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Forked from thoov/user.hbs
Last active May 8, 2018 16:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knownasilya/5db86b6ddbd2c8bcabbed77567ec3798 to your computer and use it in GitHub Desktop.
Save knownasilya/5db86b6ddbd2c8bcabbed77567ec3798 to your computer and use it in GitHub Desktop.
Thought exercise on "Ember Controllerless"

@model, @action and @service basically expose the underlying thing that they decorate to the component set by @associatedComponent (which is made up and not a great name).

I can also see something like @model({ pauseRendering: false }) and @model({ waitForParent: false }) for the data loading.

{{!-- This is the user-route component --}}
<p>{{@data.firstName}}</p>
<p>{{@data.lastName}}</p>
{{!-- can also access @queryParams --}}
<button type='button' onclick={{action @someAction @data.username}}>Trigger someAction</button>
import Route from '@ember/routing/route';
import { action } from '@ember-decorators/object';
import { model } from '@ember-decorators/model';
// The following is an invented API
import { associatedComponent } from '@ember-decorators/route';
@associatedComponent('user-route')
export Class extends Route {
@service queryParams
@model
data() {
const { sort } = this.queryParams.forRoute(this)
// Anything returned from here would be accessible on the
// template via `data`
return fetch(`/v1/data?sort=${sort}`).then(res => res.json());
}
willEnter() {}
didEnter() {}
willLeave() {}
didLeave() {}
@action
someAction() {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment