Skip to content

Instantly share code, notes, and snippets.

@btecu
Last active September 19, 2018 15:01
Show Gist options
  • Save btecu/1ea116e14e0ea5240859fd29152b2f6f to your computer and use it in GitHub Desktop.
Save btecu/1ea116e14e0ea5240859fd29152b2f6f to your computer and use it in GitHub Desktop.
Component Lifecycle Mut
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super(...arguments);
console.log('\ninit', this.get('vInit'));
this.set('vInit', 99);
},
didReceiveAttrs() {
this._super(...arguments);
console.log('\ndidReceiveAttrs', this.get('vDidReceiveAttrs'));
this.set('vDidReceiveAttrs', 99);
},
willRender() {
this._super(...arguments);
console.log('\nwillRender', this.get('vWillRender'));
this.set('vWillRender', 99);
},
didInsertElement() {
this._super(...arguments);
//console.log('\ndidInsertElement', this.get('vDidInsertElement'));
//this.set('vDidInsertElement', 99);
}
});
import Ember from 'ember';
const {
Controller,
observer
} = Ember;
export default Controller.extend({
appName: 'Ember Twiddle',
vInit: 1,
vDidReceiveAttrs: 2,
vWillRender: 3,
vDidInsertElement: 4,
oInit: observer('vInit', function() {
console.log('init changed value', this.get('vInit'));
}),
oDidReceiveAttrs: observer('vDidReceiveAttrs', function() {
console.log('didReceiveAttrs changed value', this.get('vDidReceiveAttrs'));
}),
oWillRender: observer('vWillRender', function() {
console.log('willRender changed value', this.get('vWillRender'));
}),
oDidInsertElement: observer('vDidInsertElement', function() {
console.log('didInsertElement changed value', this.get('vDidInsertElement'));
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{x-child
vInit=vInit
vDidReceiveAttrs=vDidReceiveAttrs
vWillRender=vWillRender
vDidInsertElement=vDidInsertElement}}
import { run } from '@ember/runloop';
export default function destroyApp(application) {
run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
import { start } from 'ember-cli-qunit';
setResolver(resolver);
start();
{
"version": "0.10.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": "3.2.1",
"ember-template-compiler": "3.2.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment