Created
November 16, 2017 00:50
-
-
Save ramybenaroya/36ed7dd2b376d4214ec27f5b1fb066c6 to your computer and use it in GitHub Desktop.
Refs
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 Mixin = Ember.Mixin.create({ | |
$ref(ref) { | |
return this.get('refMap.' + ref); | |
}, | |
_addRef(ref, component) { | |
this.set('refMap.' + ref, component); | |
}, | |
_removeRef(ref) { | |
if (ref) { | |
this.set('refMap.' + ref, null); | |
} | |
}, | |
init(...args){ | |
this._super(); | |
this.set('refMap', Ember.Object.create()) | |
}, | |
didReceiveAttrs({ newAttrs, oldAttrs }){ | |
if (oldAttrs && oldAttrs._ref) { | |
this.parentView._removeRef(oldAttrs._ref); | |
} | |
if (newAttrs._ref) { | |
this.parentView._addRef(newAttrs._ref, this); | |
} | |
}, | |
_removeRefOnDestroy: Ember.on('willDestroyElement', function() { | |
this.parentView._removeRef(this.get('_ref')); | |
}) | |
}) | |
export default Ember.Component.extend(Mixin, { | |
didRender(){ | |
setInterval(() => { | |
const inner = this.$ref('inner'); | |
if (inner){ | |
this.$ref('inner').send('highlight'); | |
} | |
}, 3000); | |
}, | |
actions: { | |
highlight(){ | |
this.$().css({ | |
color: 'red' | |
}); | |
setTimeout(() => { | |
this.$().css({ | |
color: 'black' | |
}); | |
}, 500) | |
} | |
} | |
}); |
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
{ | |
"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