Skip to content

Instantly share code, notes, and snippets.

@pswai
pswai / components.stop-ember-bubble.js
Last active September 18, 2017 08:30
Ember Event Sequence
import Ember from 'ember';
export default Ember.Component.extend({
disabled: false,
click() {
if (!this.get('disabled')) {
console.log('stop-ember-bubble.js: '.padStart(25), 'Ember `click` event stopped');
return false;
}
@pswai
pswai / components.x-foo.js
Last active September 15, 2017 02:06
Event objects in Ember
import Ember from 'ember';
export default Ember.Component.extend({
// Component-level event handler receives jQuery.Event
click(e) {
console.log('clickHookEvent', e);
},
actions: {
// {{action 'actionHelper'}} does not receive event
@pswai
pswai / controllers.application.js
Created August 21, 2017 07:34
Dependent Key Redundancy
import Ember from 'ember';
export default Ember.Controller.extend({
foo: {
bar: 'test'
},
lastUpdatedFoo: Ember.computed('foo', 'foo.bar', function () {
return Date.now();
}),
@pswai
pswai / controllers.application.js
Last active July 31, 2017 01:44
Ember Set Relationship to itself
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
const store = this.get('store');
const posts = [
store.createRecord('post', { title: 'foo' }),
store.createRecord('post', { title: 'bar' })
];
@pswai
pswai / controllers.application.js
Last active June 20, 2017 09:17
Evaluate ember-changeset
import Ember from 'ember';
import Changeset from 'ember-changeset';
export default Ember.Controller.extend({
pojo: {
foo: 123,
bar: 456,
baz: Ember.Object.create()
},
@pswai
pswai / components.bar-comp.js
Last active August 18, 2022 17:32
JS/HBS Hierarchy in Components
import Ember from 'ember';
export default Ember.Component.extend({
// Count here demonstrates that this component provides data
count: 0,
dataToBeYielded: Ember.computed('count', function() {
return `Hello from bar! Count is ${this.get('count')}.`;
}),
@pswai
pswai / components.bar-comp.js
Created March 13, 2017 04:01
Function-style HOC
import Ember from 'ember';
import Foo from './foo-comp';
import decorate from './decorate-hoc';
export default decorate(Foo);
@pswai
pswai / controllers.application.js
Created March 8, 2017 06:49
ArrayProxy does not have `concat`
import Ember from 'ember';
export default Ember.Controller.extend({
proxy: Ember.computed(() => Ember.ArrayProxy.create({ content: [1, 2, 3] })),
concatProxy: Ember.computed('proxy', function () {
// Uncomment this and it breaks
// return this.get('proxy').concat([4, 5, ,6]);
return this.get('proxy');
@pswai
pswai / controllers.application.js
Created February 28, 2017 07:46
disabling input
import Ember from 'ember';
export default Ember.Controller.extend({
// Change this to view the effect
isDisabled: false
});
@pswai
pswai / controllers.application.js
Created February 8, 2017 06:14
Unknown Property
import Ember from 'ember';
export default Ember.Controller.extend({
unknownProperty(key) {
if (key === 'foo') {
return 'i am foo';
}
return undefined;
}