Last active
March 6, 2018 14:19
-
-
Save runspired/fc66f09d303217750a4291e14c0be577 to your computer and use it in GitHub Desktop.
Inner Component Routing
This file contains 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.Component.extend({ | |
}); |
This file contains 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.Component.extend({ | |
}); |
This file contains 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 layout from '../templates/components/inner-link'; | |
const { | |
assert, | |
get | |
} = Ember; | |
const Link = Ember.Component.extend({ | |
layout, | |
tagName: 'a', | |
targetRouteName: '', | |
models: null, | |
queryParams: null, | |
parent: null, | |
click() { | |
this.parent.transitionTo( | |
this.targetRouteName, | |
this.models, | |
this.queryParams | |
); | |
}, | |
didReceiveAttrs() { | |
let queryParams; | |
let params = get(this, 'params'); | |
if (params) { | |
// Do not mutate params in place | |
params = params.slice(); | |
} | |
assert('You must provide one or more parameters to the link-to component.', (() => { | |
if (!params) { | |
return false; | |
} | |
return params.length; | |
})()); | |
this.set('targetRouteName', params.shift()); | |
let lastParam = params[params.length - 1]; | |
if (lastParam && lastParam.isQueryParams) { | |
queryParams = params.pop(); | |
} else { | |
queryParams = { values: {} }; | |
} | |
this.set('queryParams', queryParams); | |
// 4. Any remaining indices (excepting `targetRouteName` at 0) are `models`. | |
this.set('models', params); | |
} | |
}); | |
Link.reopenClass({ | |
positionalParams: 'params' | |
}); | |
export default Link; |
This file contains 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.Component.extend({ | |
currentRoute: null, | |
model: null, | |
queryParams: null, | |
modelFor(models) { | |
return Promise.resolve(models); | |
}, | |
transitionTo(currentRoute, models, queryParams) { | |
return this.modelFor(models).then((model) => { | |
this.setProperties({ | |
currentRoute, | |
model, | |
queryParams | |
}); | |
}); | |
} | |
}); |
This file contains 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 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.10.6", | |
"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.9.0", | |
"ember-data": "2.9.0", | |
"ember-template-compiler": "2.9.0", | |
"ember-testing": "2.9.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment