Classic Ember
This file contains 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 Component from '@ember/component'; | |
export default Component.extend({ | |
actions: { | |
updateLastName(event) { | |
this.set('lastName', event.target.value); | |
} | |
} | |
}); |
This file contains 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 Component from '@ember/component'; | |
export default Component.extend({ | |
classNames: ["one", "two", "three"], | |
//tagName: 'span', | |
// Set some data attributes | |
//'data-internal-attribute': true, | |
//attributeBindings: ['data-internal-attribute'], | |
// Event Handlers | |
// mouseDown(event) { | |
// console.log('mouseDown'); | |
// }, | |
// click(event) { | |
// console.log('click', event.target.tagName); | |
// }, | |
// mouseUp(event) { | |
// console.log('mouseUp'); | |
// }, | |
// in-built jquery | |
// didInsertElement() { | |
// console.log(this.$().html()); | |
// }, | |
}); |
This file contains 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 Component from '@ember/component'; | |
/* | |
LIFECYCLE HOOKS | |
* init | |
* didInsertElement | |
* willRender | |
* didRender | |
* didUpdateAttrs | |
* didReceiveAttrs | |
* willUpdate | |
* didUpdate | |
* willDestroyElement | |
* willClearRender | |
* didDestroyElement | |
1. Initialising | |
2. Updating | |
3. Destroying | |
*/ | |
export default Component.extend({ | |
init() { | |
this._super(...arguments); | |
console.log('init'); | |
}, | |
didInsertElement() { | |
this._super(...arguments); | |
this.$('input').focus(); | |
console.log('didInsertElement'); | |
}, | |
didRender() { | |
this._super(...arguments); | |
console.log('didRender'); | |
}, | |
didReceiveAttrs() { | |
this._super(...arguments); | |
console.log('didReceiveAttrs'); | |
}, | |
willUpdate() { | |
this._super(...arguments); | |
console.log('willUpdate'); | |
}, | |
didUpdate() { | |
this._super(...arguments); | |
console.log('didUpdate'); | |
}, | |
willClearRender() { | |
this._super(...arguments); | |
console.log('willClearRender'); | |
}, | |
willDestroyElement() { | |
this._super(...arguments); | |
console.log('willDestroyElement'); | |
}, | |
didDestroyElement() { | |
this._super(...arguments); | |
console.log('didDestroyElement'); | |
}, | |
}); |
This file contains 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 Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
/* ============================== */ | |
export default Controller.extend({ | |
showLifecycleComponent: false, | |
showHtmlDemoComponent: false, | |
showDataFlowComponent: false, | |
actions: { | |
updateFirstName(event) { | |
this.set('model.firstName', event.target.value); | |
}, | |
updateLastName(event) { | |
this.set('model.lastName', event.target.value); | |
}, | |
toggleComponent(property) { | |
this.toggleProperty(property); | |
} | |
} | |
}); |
This file contains 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 EmberObject, { computed } from '@ember/object'; | |
export default EmberObject.extend({ | |
firstName: '', | |
lastName: '', | |
fullName: computed('firstName', 'lastName', function() { | |
return `${this.firstName} ${this.get('lastName')}`; | |
}), | |
}).reopenClass({ | |
someFunction() { | |
console.log('Called from User'); | |
} | |
}); |
This file contains 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
/** | |
EmberObject | |
* computed - push based reactivity. needs dependent keys vs getters | |
* Object.create() vs new Object() | |
* init vs constructor | |
* reopenClass vs static | |
**/ | |
import Route from '@ember/routing/route'; | |
import EmberObject, { computed } from '@ember/object'; | |
const User = EmberObject.extend({ | |
init() { | |
this._super(...arguments); | |
console.log('USER INIT', ...arguments); | |
}, | |
firstName: '', | |
lastName: '', | |
fullName: computed('firstName', function() { | |
return `${this.firstName} ${this.get('lastName')}`; | |
}), | |
}).reopenClass({ | |
someFunction() { | |
console.log('Called from User'); | |
} | |
}); | |
export default Route.extend({ | |
model() { | |
// reopenClass function | |
User.someFunction(); | |
return User.create({ | |
firstName: 'Travis', | |
lastName: 'Bickle' | |
}); | |
} | |
}); |
This file contains 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.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment