Skip to content

Instantly share code, notes, and snippets.

@mixonic
Last active May 18, 2017 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mixonic/cfaa68c575d83a784469c8f061cb7d1a to your computer and use it in GitHub Desktop.
Save mixonic/cfaa68c575d83a784469c8f061cb7d1a to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
function log(string) {
let node = $('<p>').text(`${string} (input? ${$('input').length > 0})`);
node.appendTo('body');
}
export default Ember.Component.extend({
tagName: 'input',
willRender() {
log('willRender');
},
willDestroyElement() {
log('willDestroyElement');
},
focusOut() {
log('focusOut');
},
didRender() {
log('didRender');
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
isItemVisible: true,
actions: {
toggle(property) {
if (this.get(property)) {
$('input')[0].focus();
}
this.toggleProperty(property);
}
}
});
<h1>focusOut dispatch during teardown</h1>
<br>
Clicking the "Toggle Visibility" button will cause the input to be programmatically focused, and will set a property causing it to be removed from rendering.
<br><br>
In Ember 2.7, the `willDestroyElement` hook is called before the input is removed from the DOM.
<br><br>
In Ember 2.8, the `willDestroyElement` hook is called before the input is removed from the DOM. Then, the `focusOut` handler is called during `input` removal.
<br><br>
<!-- -------------------------- -->
<button {{action 'toggle' 'isItemVisible'}}>Toggle Visibility</button>
<br>
{{#if isItemVisible}}
{{blurring-item}}
{{/if}}
<br>
<br>
{
"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": "release",
"ember-template-compiler": "release",
"ember-testing": "release",
"ember-data": "1.13.15"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment