Last active
July 3, 2017 09:47
-
-
Save c-emil/40a803a6866380468951f306c6108131 to your computer and use it in GitHub Desktop.
History 2
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'; | |
Ember.Route.reopen({ | |
historyOptions: { | |
isPrimaryRoute: false, | |
shouldSaveInHistory: true, | |
goBackRoute: null | |
}, | |
setHistoryOptions(historyOptions) { | |
this.set('historyOptions', { | |
isPrimaryRoute: false, | |
shouldSaveInHistory: true, | |
goBackRoute: null | |
}); | |
for (var historyOptionKey in historyOptions) { | |
this.set(`historyOptions.${historyOptionKey}`, historyOptions[historyOptionKey]); | |
} | |
}, | |
actions: { | |
} | |
/**setupHistoryOptions: Ember.on('init', function () { | |
this.set('historyOptions', { | |
isPrimaryRoute: false, | |
shouldSaveInHistory: true, | |
goBackRoute: null | |
}); | |
})*/ | |
}); | |
const HistoryMixin = Ember.Mixin.create({ | |
getCurrentRouteName() { | |
return this.controllerFor('application').get('currentRouteName'); | |
}, | |
actions: { | |
willTransition() { | |
const theRoute = Ember | |
.getOwner(this) | |
.lookup(`route:${this.getCurrentRouteName()}`); | |
const isPrimaryRoute = theRoute.get('historyOptions.isPrimaryRoute'); | |
const shouldSaveInHistory = theRoute.get('historyOptions.shouldSaveInHistory'); | |
console.log('SETTINGS (willTransition): \n\nisPrimaryRoute: ' + isPrimaryRoute + '\n' + 'shouldSaveInHistory: ' + shouldSaveInHistory); | |
}, | |
didTransition() { | |
Ember.run.next(this, function() { | |
const theRoute = Ember | |
.getOwner(this) | |
.lookup(`route:${this.getCurrentRouteName()}`); | |
const isPrimaryRoute = theRoute.get('historyOptions.isPrimaryRoute'); | |
const shouldSaveInHistory = theRoute.get('historyOptions.shouldSaveInHistory'); | |
console.log('SETTINGS (didTransition): \n\nisPrimaryRoute: ' + isPrimaryRoute + '\n' + 'shouldSaveInHistory: ' + shouldSaveInHistory); | |
}); | |
} | |
} | |
}); | |
export default HistoryMixin; |
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('first'); | |
alert('init 1'); | |
this.route('second'); | |
alert('init 2'); | |
}); | |
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'; | |
import HistoryMixin from '../mixins/history-mixin'; | |
export default Ember.Route.extend(HistoryMixin); |
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 HistoryMixin from '../mixins/history-mixin'; | |
export default Ember.Route.extend({ | |
setupHistoryOptions: Ember.on('init', function setHistoryOptions() { | |
alert('init 1 - from'); | |
this.setHistoryOptions({isPrimaryRoute: true}); | |
}) | |
}); |
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 HistoryMixin from '../mixins/history-mixin'; | |
export default Ember.Route.extend({ | |
setupHistoryOptions: Ember.on('init', function setHistoryOptions() { | |
alert('init 2 - from'); | |
this.setHistoryOptions({shouldSaveInHistory: false}); | |
}) | |
}); |
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.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment