Last active
May 9, 2018 21:12
-
-
Save aaxelb/fa18b2a5e39455bd1dd9510ac6b9a647 to your computer and use it in GitHub Desktop.
es6 classes reopen without 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'; | |
class ApplicationRoute extends Ember.Route { | |
beforeModel() { | |
super.beforeModel(...arguments); | |
console.log('ApplicationRoute: native beforeModel'); | |
} | |
} | |
export default ApplicationRoute; |
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'; | |
class ReopenedWithExtend extends Ember.Route.extend( | |
// Empty extend block | |
) { | |
beforeModel() { | |
super.beforeModel(...arguments); | |
console.log('Reopened (with extend): native beforeModel'); | |
} | |
} | |
// With the empty extend block above, this reopen only affects this one route | |
ReopenedWithExtend.reopen({ | |
init() { | |
this._super(...arguments); | |
const originalBeforeModel = this.beforeModel; | |
this.beforeModel = function() { | |
console.log('Reopened (with extend): injected beforeModel'); | |
originalBeforeModel.apply(this, arguments); | |
}; | |
}, | |
}); | |
export default ReopenedWithExtend; |
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'; | |
class ReopenedRoute extends Ember.Route { | |
beforeModel() { | |
super.beforeModel(...arguments); | |
console.log('Reopened (no extend): native beforeModel'); | |
} | |
} | |
// Without .extend() above, this reopen appears to affect all routes? | |
// Compare reopened-extend/route.js | |
ReopenedRoute.reopen({ | |
init() { | |
this._super(...arguments); | |
const originalBeforeModel = this.beforeModel; | |
this.beforeModel = function() { | |
console.log('Reopened (no extend): injected beforeModel'); | |
originalBeforeModel.apply(this, arguments); | |
}; | |
}, | |
}); | |
export default ReopenedRoute; |
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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL, | |
willTransition() { | |
console.log('----- will transition -----'); | |
}, | |
didTransition() { | |
console.log('----- did transition -----'); | |
}, | |
}); | |
Router.map(function() { | |
this.route('unopened'); | |
this.route('reopened'); | |
this.route('reopened-extend'); | |
}); | |
export default Router; |
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.13.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": true, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
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'; | |
class ClosedRoute extends Ember.Route { | |
beforeModel() { | |
super.beforeModel(...arguments); | |
console.log('Unopened: native beforeModel'); | |
} | |
} | |
export default ClosedRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment