Skip to content

Instantly share code, notes, and snippets.

@k-fish
Last active August 24, 2016 16:31
Show Gist options
  • Save k-fish/73c292481820dad8eaf2fdbbce26d29b to your computer and use it in GitHub Desktop.
Save k-fish/73c292481820dad8eaf2fdbbce26d29b to your computer and use it in GitHub Desktop.
Transition refresh example (refresh post transition promise works)
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('main', { resetNamespace: true, path: ''}, function() {
this.route('a-route', {path: 'a-route/:id'});
this.route('b-route');
});
});
export default Router;
import Ember from 'ember';
let inc = 0;
export default Ember.Route.extend({
model() {
inc = inc + 1;
return Ember.RSVP.resolve({inc: inc});
},
afterModel(model) {
model.inc = model.inc + 0.01;
},
actions: {
didTransition() {
inc = inc + 1;
this.set('controller.model.inc', inc);
},
},
});
import Ember from 'ember';
let id = 1;
export default Ember.Route.extend({
actions: {
trans(loc) {
//id = 1 - id;
this.transitionTo(loc, id).then(() => {
this.refresh();
});
},
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<br>
Model: {{model.inc}}
<br>
MAIN
<button {{action 'trans' 'main.a-route'}}>A route</button><button {{action 'trans' 'main.b-route'}}>B route</button>
<br>
{{outlet}}
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment