Last active
March 2, 2022 12:30
-
-
Save patocallaghan/01856d13489b2f9a6058a6c29f86b523 to your computer and use it in GitHub Desktop.
Ember Octane
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 '@glimmer/component'; | |
import { action } from '@ember/object'; | |
export default class HtmlDemo extends Component { | |
@action | |
updateFirstName(event) { | |
// This will throw an error because this.args is not mutable | |
this.args.firstName = 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 '@glimmer/component'; | |
import { action } from '@ember/object'; | |
export default class HtmlDemo extends Component { | |
//Event Handlers | |
@action | |
handleMouseDown(event) { | |
console.log('mouseDown'); | |
} | |
@action | |
handleClick(value, event) { | |
console.log('click', value, event.target.tagName); | |
} | |
@action | |
handleMouseUp(event) { | |
console.log('mouseUp'); | |
} | |
} |
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 '@glimmer/component'; | |
/* | |
LIFECYCLE HOOKS | |
* constructor | |
* willDestroy | |
* modifiers - https://github.com/ember-modifier/ember-modifier | |
* resources - https://github.com/NullVoxPopuli/ember-resources | |
*/ | |
export default class LifecycleHooks extends Component { | |
constructor() { | |
super(...arguments); | |
console.log('LIFECYCLE: constructor'); | |
} | |
willDestroy() { | |
super.willDestroy(...arguments); | |
console.log('LIFECYCLE: willDestroy'); | |
} | |
} |
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
/* | |
* Reactivity based on Autotracking | |
* Read-only by default | |
* It's just JS: new, static, getters, some decorators | |
* getters vs computed | |
* new Object() vs Object.create() | |
* constructor vs init | |
* static vs constructor | |
**/ | |
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
class User { | |
firstName; | |
@tracked lastName; | |
constructor(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
get fullName() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
static someFunction() { | |
console.log('Called from User'); | |
} | |
} | |
/* ============================== */ | |
export default class ApplicationController extends Controller { | |
@tracked showLifecycleComponent = false; | |
@tracked showHtmlDemoComponent = false; | |
@tracked showDataFlowComponent = false; | |
constructor() { | |
super(...arguments); | |
this.user = new User('Travis','Bickle'); | |
// static function | |
User.someFunction(); | |
} | |
@action | |
updateFirstName(event) { | |
this.user.firstName = event.target.value; | |
} | |
@action | |
updateLastName(event) { | |
this.user.lastName = event.target.value; | |
} | |
@action | |
toggleComponent(property) { | |
this[property] = !this[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 { modifier } from 'ember-modifier'; | |
export default modifier((element) => { | |
element.focus(); | |
}); |
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", | |
"ember-modifier": "2.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment