Skip to content

Instantly share code, notes, and snippets.

@nkgm
nkgm / Generators.scala
Last active August 29, 2015 14:20
Principles of Reactive Programming - Generators Desugared
trait Generator[+T] {
self =>
def generate: T
def map[S](f: T => S): Generator[S] = new Generator[S] {
def generate = f(self.generate)
}
def flatMap[S](f: T => Generator[S]): Generator[S] = new Generator[S] {
@nkgm
nkgm / controllers.application.js
Last active August 22, 2016 16:10
liquidfirst-test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@nkgm
nkgm / components.list-properties.js
Last active May 9, 2017 20:12
Positional Parameters
import Ember from 'ember';
const {computed} = Ember;
const ListPropertiesComponent = Ember.Component.extend({
object: computed.readOnly('params.firstObject'),
properties: computed('params.[]', {
get() {
let [,...props] = this.get('params');
return props;
@nkgm
nkgm / controllers.application.js
Last active May 9, 2017 20:06 — forked from alexspeller/controllers.application.js
array.length != array.[]
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
array: ['a', 'b', 'c'],
lengthBased: Ember.computed('array.length', function() {
return this.get('array').join(" ");
}),
@nkgm
nkgm / controllers.application.js
Last active April 15, 2018 15:24 — forked from ofersadgat/controllers.application.js
Computed Update Count
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
fullName: '',
firstName: Ember.computed('fullName', function() {
return this.get('fullName').split(' ')[0];
}),
@nkgm
nkgm / controllers.application.js
Last active April 15, 2018 17:49 — forked from bendemboski/controllers.application.js
Optimizing computed property recalculation
import Ember from 'ember';
// A computed property chain of property(fullName) <- computed(firstName) <- computed(greeting) will
// always recalculate computed(firstName) and computed(greeting) when property(fullName) changes.
// This means that computed(greeting) will be recalculated even when computed(firstName) didn't change
// as a result of property(fullName)'s change. If you find yourself stuck in an "unnecessary expensive
// updates" situation, here is something you can do to optimize:
export default Ember.Controller.extend({
appName: 'Optimizing computed property recalculation',