Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Last active May 17, 2018 19:45
Show Gist options
  • Save jamesarosen/ad1ca8f413bc17fb1b4d679d56996000 to your computer and use it in GitHub Desktop.
Save jamesarosen/ad1ca8f413bc17fb1b4d679d56996000 to your computer and use it in GitHub Desktop.
query-params-debugging
import Ember from 'ember';
console.clear()
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
clearLog() {
this.get('log').clear()
},
foo: undefined,
incrementFoo() {
this.get('log').append('foo++')
const foo = parseInt(this.get('foo') || 0)
const router = this.get('router')
router.transitionTo(router.currentRouteName, { queryParams: { foo: foo + 1 } })
},
log: Ember.inject.service(),
queryParams: ['foo'],
router: Ember.computed(function() {
return Ember.getOwner(this).lookup('router:main')
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
bar: undefined,
queryParams: ['bar'],
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('child')
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
log: Ember.inject.service(),
init() {
this._super(...arguments)
this.get('log').append(`Ember ${Ember.VERSION}`)
},
beforeModel() {
this.get('log').append('route:application#beforeModel')
},
model(params, transition) {
this.get('log').append(`route:application#model ${transition.queryParams.foo}`)
},
afterModel() {
this.get('log').append('route:application#afterModel')
},
setupController() {
this.get('log').append('route:application#setupController')
return this._super(...arguments)
},
queryParams: {
foo: {
refreshModel: true
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
log: Ember.inject.service(),
beforeModel() {
this.get('log').append('route:child#beforeModel')
},
model(params, transition) {
this.get('log').append(`route:child#model ${transition.queryParams.foo}`)
},
afterModel() {
this.get('log').append('route:child#afterModel')
},
setupController() {
this.get('log').append('route:child#setupController')
return this._super(...arguments)
},
});
import Ember from 'ember';
export default Ember.Service.extend({
content: Ember.computed(function() {
return []
}),
append(msg) {
this.set('content', this.get('content').concat(msg))
},
clear() {
this.set('content', [])
},
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
a, a:focus, a:hover, a:visited {
color: blue;
}
a.active {
color: green;
}
<h1>Welcome to {{appName}}</h1>
<nav>
{{link-to 'Index' 'index'}}
{{link-to 'Child' 'child'}}
</nav>
<section>
<label>
foo
<output>{{foo}}</output>
</label>
<button onclick={{action incrementFoo}}>foo++</button>
</section>
<section>
<h3>
Log
<button onclick={{action clearLog}}>Clear</button>
</h3>
<ol>
{{#each log.content as |i|}}
<li>{{i}}</li>
{{/each}}
</ol>
</section>
<main>
{{outlet}}
</main>
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment