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
const bindings = new WeakMap() | |
const getFns = context => { | |
if (!bindings.has(context)) { | |
bindings.set(context, {}) | |
} | |
return bindings.get(context) | |
} | |
const bindOnce = (fn, context, ...args) => { |
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 { 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 { |
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
const Cow = { | |
airInLungs: 0, | |
getAirInLungs() { | |
return this.airInLungs | |
}, | |
breathe () { | |
this.airInLungs = this.lungCapacity | |
}, | |
moo () { | |
let output = "m" |
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
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, |
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
//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 | |
} | |
}); |
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
// 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(){ |
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
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 | |
} |
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 { 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(); | |
}); |
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
const actionTypes = { | |
TRANSACTION_SUCCESS: 'my action type' | |
} | |
export actionTypes; | |
export function transactionSuccess(){ | |
return { | |
type: actionTypes.TRANSACTION_SUCCESS // podría haber devuelto 'my action type' | |
} | |
} |
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 { 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(); | |
}); | |
}); |
NewerOlder