-
-
Save yaobind/b795e9768916895ac865a22fafeb2d1b 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 EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
import { inject as service } from '@ember/service'; | |
import { schedule } from '@ember/runloop'; | |
// For learning purposes only! Please do not do this | |
let log = document.createElement('div'); | |
log.id = 'log'; | |
document.body.appendChild(log); | |
let i = 1; | |
function appendEntry(str) { | |
let p = document.createElement('p'); | |
p.style.fontFamily = 'monospace'; | |
p.innerText = `${i++}: ${str}`; | |
log.prepend(p); | |
} | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
routerState: service('router-state'), | |
rootURL: config.rootURL, | |
init() { | |
this._super(...arguments); | |
this.isInitialVisit = true; | |
}, | |
willTransition() { | |
if (this.isInitialVisit) { | |
appendEntry('Initial visit'); | |
} else { | |
appendEntry('Subsequent visit'); | |
} | |
}, | |
didTransition() { | |
appendEntry(`Transitioned`) | |
this.get('routerState').set('isInitialVisit', false); | |
}, | |
}); | |
Router.map(function() { | |
this.route('a'); | |
this.route('b'); | |
}); | |
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'; | |
export default Ember.Route.extend({ | |
}); |
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.Route.extend({ | |
routerState: Ember.inject.service('router-state'), | |
actions: { | |
goBack() { | |
// I need to do some check here to prevent user leaving our app, but isInitialVisit is always false | |
console.error(this.get('routerState').isInitialVisit); | |
if (!this.get('routerState').isInitialVisit) { | |
window.history.back(); | |
} | |
}, | |
}, | |
}); |
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.Route.extend({ | |
}); |
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.Service.extend({ | |
isInitialVisit: 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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
#log { | |
position: fixed; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
background: #efefe; | |
border: 2px solid #999; | |
height: 300px; | |
overflow: scroll; | |
} |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment