Skip to content

Instantly share code, notes, and snippets.

View sminutoli's full-sized avatar

S Minutoli sminutoli

View GitHub Profile
@sminutoli
sminutoli / bind-once.js
Last active November 13, 2017 19:31 — forked from m3g4p0p/bind-once.js
Bind functions to instances in a way that maintains strict equality when done multiple times
const bindings = new WeakMap()
const getFns = context => {
if (!bindings.has(context)) {
bindings.set(context, {})
}
return bindings.get(context)
}
const bindOnce = (fn, context, ...args) => {
import { Counter, createCounter, increment, decrement } from '../../entities/Counter';
import { CounterAction } from './actions';
import { CounterActionTypes } from './types';
import { identity } from './lodash-identity';
export type CounterState = Counter;
const initialState: CounterState = createCounter();
function counterReducer (state: CounterState = initialState, action: CounterAction): CounterState {
const Cow = {
airInLungs: 0,
getAirInLungs() {
return this.airInLungs
},
breathe () {
this.airInLungs = this.lungCapacity
},
moo () {
let output = "m"
function render(){
const {selectedDashboardOption, chewedImages} = this.state;
const dashboardProperties = getSelectedDashboardProps(selectedDashboardOption);
const {width, height, title, chartSeries, x, y, xScale, xLabel, xRange, yLabel, yScale, yDomain} = dashboardProperties;
// asumiendo que dashboardProperties tiene mas props que estas, si no directamente haces ...dashboardProperties
const props = {
data: chewedImages,
width,
height,
title,
//ES5
var SpecialItem = Object.create(Item); //delego todos los mensajes que no conozco a Item
Object.assign( SpecialItem, {
updateQuality: function fnUpdateQuality(){
if(this.quality > 10) return; // si tengo mas de 10, no redirijo el mensaje a mi prototipo
Object.getPrototypeOf(this).updateQuality.call(this); // hago que el mensaje siga la cadena de prototipos
}
});
@sminutoli
sminutoli / dptc15.es5.js
Last active February 17, 2017 17:37
Ejemplos para DPTC#15
// ES5
var Item = {
quality: 0,
sellIn: 10,
update: function fnUpdate(){
this.updateQuality();
this.updateSellIn();
if(recursion) return fnUpdate.call(this); // esto no depende de la propiedad update del objeto
},
updateQuality: function fnUpdateQuality(){
@sminutoli
sminutoli / actionCreator.js
Created November 10, 2016 19:59
TDD Action Creator paso 3
const actionTypes = {
TRANSACTION_SUCCESS: 'my action type'
}
export actionTypes;
export function transactionSuccess(result){
return {
type: actionTypes.TRANSACTION_SUCCESS, // podría haber devuelto 'my action type'
result
}
@sminutoli
sminutoli / actionCreator.test.js
Created November 10, 2016 19:57
TDD Action Creator paso 3
import { describe, it } from 'mocha';
import expect from 'expect';
import { actionTypes, transactionSuccess } from './actionCreator';
describe('ItemTransactionActions.actionTypes', () => {
it('should expose TRANSACTION_SUCCESS', () => {
const actual = actionTypes.TRANSACTION_SUCCESS;
expect(actual).toExist();
});
@sminutoli
sminutoli / actionCreator.js
Created November 10, 2016 19:55
TDD Action Creators paso 2
const actionTypes = {
TRANSACTION_SUCCESS: 'my action type'
}
export actionTypes;
export function transactionSuccess(){
return {
type: actionTypes.TRANSACTION_SUCCESS // podría haber devuelto 'my action type'
}
}
@sminutoli
sminutoli / actionCreator.test.js
Created November 10, 2016 19:50
TDD Action Creator paso 2
import { describe, it } from 'mocha';
import expect from 'expect';
import { actionTypes, transactionSuccess } from './actionCreator';
describe('ItemTransactionActions.actionTypes', () => {
it('should expose TRANSACTION_SUCCESS', () => {
const actual = actionTypes.TRANSACTION_SUCCESS;
expect(actual).toExist();
});
});