Skip to content

Instantly share code, notes, and snippets.

@EWhite613
Last active August 14, 2019 20:41

Revisions

  1. EWhite613 revised this gist Aug 14, 2019. 1 changed file with 5 additions and 10 deletions.
    15 changes: 5 additions & 10 deletions routes.application.js
    Original file line number Diff line number Diff line change
    @@ -22,20 +22,15 @@ queryParams: {
    }
    },
    _optionsForQueryParam (qp) {
    const result = get(this, `queryParams.${qp.urlKey}`) || get(this, `queryParams.${qp.prop}`)
    if (!result) {
    const queryParams = this.queryParams
    const queryParams = get(this, 'queryParams')
    return get(queryParams, qp.urlKey) || get(queryParams, qp.prop) || queryParams[qp.urlKey] || queryParams[qp.prop] || {}

    return queryParams[qp.urlKey] || queryParams[qp.prop] || {}
    }

    return result
    },

    model (params) {
    console.log('witness', params)
    set(countObj , 'count', countObj.count + 1)
    return params
    console.log('witness', params)
    set(countObj , 'count', countObj.count + 1)
    return params
    },

    setupController (controller, model) {
  2. EWhite613 revised this gist Aug 14, 2019. No changes.
  3. EWhite613 revised this gist Aug 14, 2019. 3 changed files with 20 additions and 3 deletions.
    20 changes: 18 additions & 2 deletions routes.application.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    import Ember from 'ember';


    const {get, set} = Ember
    const countObj = {count: 0}
    export default Ember.Route.extend({

    queryParams: {
    @@ -21,10 +21,26 @@ queryParams: {
    as: 'foobar'
    }
    },
    _optionsForQueryParam (qp) {
    const result = get(this, `queryParams.${qp.urlKey}`) || get(this, `queryParams.${qp.prop}`)
    if (!result) {
    const queryParams = this.queryParams

    return queryParams[qp.urlKey] || queryParams[qp.prop] || {}
    }

    return result
    },

    model (params) {
    console.log('witness', params)
    set(countObj , 'count', countObj.count + 1)
    return params
    },

    setupController (controller, model) {
    this._super(controller, model)
    controller.countObj = countObj
    }
    });

    1 change: 1 addition & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    <br>
    <br>
    {{nested.foo}}
    {{countObj.count}}
    {{outlet}}
    <br>
    <br>
    2 changes: 1 addition & 1 deletion twiddle.json
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,4 @@
    "addons": {
    "ember-data": "3.4.2"
    }
    }
    }
  4. EWhite613 revised this gist Aug 14, 2019. 3 changed files with 3 additions and 6 deletions.
    4 changes: 1 addition & 3 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,5 @@ export default Ember.Controller.extend({
    nested: {
    foo: 'bar'
    },
    queryParams: [{
    foobar: 'nested.foo'
    }]
    queryParams: ['nested.foo']
    });
    2 changes: 1 addition & 1 deletion routes.application.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ import Ember from 'ember';
    export default Ember.Route.extend({

    queryParams: {
    'foobar': {
    '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
    3 changes: 1 addition & 2 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@
    <h1>Welcome to {{appName}}</h1>
    <br>
    <br>
    {{log model}}
    {{model.nested.foo}}
    {{nested.foo}}
    {{outlet}}
    <br>
    <br>
  5. EWhite613 created this gist May 14, 2019.
    11 changes: 11 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import Ember from 'ember';

    export default Ember.Controller.extend({
    appName: 'Ember Twiddle',
    nested: {
    foo: 'bar'
    },
    queryParams: [{
    foobar: 'nested.foo'
    }]
    });
    30 changes: 30 additions & 0 deletions routes.application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    import Ember from 'ember';


    export default Ember.Route.extend({

    queryParams: {
    'foobar': {
    // 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'
    }
    },

    model (params) {
    console.log('witness', params)
    return params
    }
    });

    8 changes: 8 additions & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <h1>Welcome to {{appName}}</h1>
    <br>
    <br>
    {{log model}}
    {{model.nested.foo}}
    {{outlet}}
    <br>
    <br>
    19 changes: 19 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {
    "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"
    }
    }