Skip to content

Instantly share code, notes, and snippets.

View foxnewsnetwork's full-sized avatar

Thomas Chen foxnewsnetwork

View GitHub Profile
@foxnewsnetwork
foxnewsnetwork / components.did-load.js
Last active March 20, 2018 22:43
Component double render
import Ember from 'ember';
export default Ember.Component.extend({
willInsertElement() {
Ember.tryInvoke(this, 'action');
}
}).reopenClass({
positionalParams: ['action']
});
@foxnewsnetwork
foxnewsnetwork / component-writing-guide.markdown
Last active April 17, 2018 16:34
Advanced guide on how to write sensible ember components

Motivation

Have you ever run into the infamous ember double render bug?

Do you find yourself breaking out import { scheduleOnce } from '@ember/runloop' all the time?

Are you frustrated about "god" components that can't be tested?

If so, this gist is for you!

import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'QueryParams Demo',
referrerLocation: null,
queryParams: ['referrerLocation']
});
import Ember from 'ember';
export default Ember.Component.extend({
tagName: '',
after: 0,
willDestroyElement() {
Ember.run.cancel(this.timeoutHandle);
},
@foxnewsnetwork
foxnewsnetwork / canvas-container.component.js
Last active May 17, 2018 20:42
Async Attrs Component Demo (with cache + error handling)
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'canvas',
attributeBindings: ['width', 'height'],
width: 200,
height: 274,
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Video Problems'
});
import Ember from 'ember';
const DOGE = 'http://i0.kym-cdn.com/entries/icons/mobile/000/013/564/doge.jpg';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
DOGE
});
@foxnewsnetwork
foxnewsnetwork / collection.js
Created June 29, 2018 19:27
Collection Filter Demo
const COLLECTION = {
"collection": {
"id": "SOME-COLLECTION-ID",
"name": "WALKING-SIMULATOR",
"games": {
"DEATH-STRANDING-XXX-1": {
"id": "DEATH-STRANDING-XXX-1",
"image": "https://i.ytimg.com/vi/i2nuHEGhwiw/sddefault.jpg"
"genres": [
{ "id": "GENRE-ID-1" },
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@foxnewsnetwork
foxnewsnetwork / adventures-in-reasonml-js-api-typing.md
Last active September 12, 2018 16:19
ReasonML JavaScript API Bindings for Union Types

Problem Background

Recently, I've been trying to experiment with using ReasonML in production, however, this generally involves writing bindings to existing libraries... and unfortunately, some of these libraries expose extremely difficult to type interfaces; consider trying to wrap the following getUserInfo function (written in typescript for illustration purposes):

type xInfo = {
    info: string,
    message: string
};