Skip to content

Instantly share code, notes, and snippets.

@MiguelMadero
Last active August 23, 2016 12:39
Show Gist options
  • Save MiguelMadero/35eb6277981c685fbef58fa067369587 to your computer and use it in GitHub Desktop.
Save MiguelMadero/35eb6277981c685fbef58fa067369587 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
init () {
this._super(...arguments);
console.log(this.get('name') + " component init");
},
willInsertElement () {
console.log(this.get('name') + " component willInsertElement");
},
willClearRender () {
console.log(this.get('name') + " component willClearRender");
},
willDestroyElement () {
console.log(this.get('name') + " component willDestroyElement");
}
});
import Ember from 'ember';
import {addV2Classes, addV1Classes} from 'twiddle/utils/use-v2';
export default Ember.Component.extend({
willInsertElement () {
this._super(...arguments);
addV2Classes();
},
willClearRender () {
this._super(...arguments);
// Unfortunately component hooks have a similar issue
//debugger;
addV1Classes();
//debugger;
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('blog');
this.route('with-component');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
import Ember from 'ember';
import {addV2Classes, addV1Classes} from 'twiddle/utils/use-v2';
export default Ember.Route.extend({
onActivate: function() {
addV2Classes();
window.console.log('blog activate');
}.on('activate'),
onDeActivate: function(){
addV1Classes();
// Adding a debugger statemeent here shows that the style is reset before we remove the content, so this is the *wrong* hook
// debugger
window.console.log('blog deactivate');
}.on('deactivate'),
actions: {
willTransition: function() {
window.console.log('blog onWillTransition');
},
didTransition: function() {
window.console.log('blog onDidTransition');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
onActivate: function() {
window.console.log('index activate');
}.on('activate'),
onDeActivate: function(){
window.console.log('index deactivate');
}.on('deactivate'),
actions: {
willTransition: function() {
window.console.log('index onWillTransition');
},
didTransition: function() {
window.console.log('index onDidTransition');
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.v1 {
background: red;
}
.v2 {
background: yellow;
}
<div class="v1">
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{#link-to "blog"}}Route Mixin{{/link-to}}
{{#link-to "with-component"}}Component Toggle{{/link-to}}
{{#link-to "index"}}Index{{/link-to}}
<br>
<br>
</div>
{{my-component name="blog"}}
{{my-component name="index"}}
{{use-v2}}
{{my-component name="with-component"}}
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
let changeCounter = 0;
export function addV2Classes () {
changeCounter++;
$('.v1').toggleClass('v2 v1');
}
export function addV1Classes () {
changeCounter--
if (changeCounter === 0) {
$('.v2').toggleClass('v2 v1');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment