- 
      
 - 
        
Save batok/df6c4bb53db624260c430b1069c9e16b to your computer and use it in GitHub Desktop.  
    Promises
  
        
  
    
      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'; | |
| const { RSVP, | |
| Mixin, | |
| Logger: { info }, | |
| run | |
| } = Ember; | |
| let MyMixin = Mixin.create({ | |
| beforeModel() { | |
| this._super(...arguments); | |
| info('at mixin'); | |
| return timeoutPromise(3000) | |
| .then(() => {this.beforeModel2()}); | |
| } | |
| }); | |
| function timeoutPromise(milliseconds) { | |
| return new Promise(function(resolve,reject) { | |
| run.later(this, resolve, milliseconds); | |
| }); | |
| } | |
| export default Ember.Route.extend(MyMixin, { | |
| /* | |
| beforeModel() { | |
| // OJO debe llevar return si queremos que la promesa del mixin se agote | |
| return this._super(...arguments); | |
| console.log(new Date(), " beforeModel"); | |
| //return timeoutPromise(); | |
| }, | |
| */ | |
| beforeModel2() { | |
| info("El beforeModel2 de la ruta"); | |
| }, | |
| model() { | |
| console.log(new Date(), " model"); | |
| return timeoutPromise(5000); | |
| }, | |
| afterModel() { | |
| console.log(new Date(), " afterModel"); | |
| return timeoutPromise(5000); | |
| } | |
| }); | 
  
    
      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.9.2", | |
| "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.6.0", | |
| "ember-data": "2.6.0", | |
| "ember-template-compiler": "2.6.0" | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment