Last active
February 19, 2017 21:13
-
-
Save tarponjargon/fb1680bfea201aeb4a0d886aafa3eed5 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| // this would not be here, I'd import it to both the route and the controller (perhaps from environment.js) | |
| const cfg = { | |
| defaultQueryParams: { | |
| q: null, | |
| sort_method: 'relevance', //<--when added with setProperties in init() - strings are added just fine | |
| filter1: [], // <--when added with setProperties in init() - arrays are added as 'undefined' | |
| filter2: [] | |
| } | |
| }; | |
| export default Ember.Controller.extend({ | |
| queryParams: Object.keys(cfg.defaultQueryParams), // <--this works just fine, no need to manually specify | |
| init(){ | |
| this._super(...arguments); | |
| this.setProperties(cfg.defaultQueryParams); // <--works for setting strings, but not arrays | |
| }, | |
| filter2: [], // <--when added directly, arrays are added as 'Array[0]' | |
| actions: { | |
| addFilter: function(key, value) { | |
| alert(`adding "${value.toString()}" to controller property '${key}'`); | |
| console.log("DUMP OF EMBER 'this':", this); | |
| this[key].pushObject(value.toString()); | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| import config from './config/environment'; | |
| const Router = Ember.Router.extend({ | |
| location: 'none', | |
| rootURL: config.rootURL | |
| }); | |
| Router.map(function() { | |
| this.route('results'); | |
| }); | |
| export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| // this would not be here, I'd import it to both the route and the controller (perhaps from environment.js) | |
| const cfg = { | |
| defaultQueryParams: { | |
| q: null, | |
| sort_method: 'relevance', | |
| filter1: [], | |
| filter2: [] | |
| } | |
| }; | |
| export default Ember.Route.extend({ | |
| queryParams: {}, | |
| init() { | |
| this._super(...arguments); | |
| //specify from cfg.defaultQueryParams rather than each one explicitly | |
| Object.keys(cfg.defaultQueryParams).forEach((qp) => { | |
| this.queryParams[qp] = { refreshModel: true }; | |
| }); | |
| // setting each queryParams `refreshModel: true` using a loop does work! yay! See console: | |
| console.log("ROUTE queryParams:", this.queryParams); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.11.0", | |
| "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.10.2", | |
| "ember-data": "2.11.0", | |
| "ember-template-compiler": "2.10.2", | |
| "ember-testing": "2.10.2" | |
| }, | |
| "addons": {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment