Skip to content

Instantly share code, notes, and snippets.

@EWhite613
Last active August 14, 2019 20:41
Show Gist options
  • Save EWhite613/0a1917cff72d5720d69e0382276e6722 to your computer and use it in GitHub Desktop.
Save EWhite613/0a1917cff72d5720d69e0382276e6722 to your computer and use it in GitHub Desktop.
Query param weird example v2
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
nested: {
foo: 'bar'
},
queryParams: ['nested.foo']
});
import Ember from 'ember';
const {get, set} = Ember
const countObj = {count: 0}
export default Ember.Route.extend({
queryParams: {
'nested.foo': {
// By default, controller query param properties don't
// cause a full transition when they are changed, but
// rather only cause the URL to update. Setting
// `refreshModel` to true will cause an "in-place"
// transition to occur, whereby the model hooks for
// this route (and any child routes) will re-fire, allowing
// you to reload models (e.g., from the server) using the
// updated query param values.
refreshModel: true,
// By default, the query param URL key is the same name as
// the controller property name. Use `as` to specify a
// different URL key.
as: 'foobar'
}
},
_optionsForQueryParam (qp) {
const queryParams = get(this, 'queryParams')
return get(queryParams, qp.urlKey) || get(queryParams, qp.prop) || queryParams[qp.urlKey] || queryParams[qp.prop] || {}
},
model (params) {
console.log('witness', params)
set(countObj , 'count', countObj.count + 1)
return params
},
setupController (controller, model) {
this._super(controller, model)
controller.countObj = countObj
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{nested.foo}}
{{countObj.count}}
{{outlet}}
<br>
<br>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment