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 CLOSED = Symbol('CLOSED') | |
const OPEN = Symbol('OPEN') | |
const HALF_OPEN = Symbol('HALF_OPEN') | |
const MSG = 'Functionality disabled due to previous errors.' | |
module.exports = (asyncFn, gracePeriodMs = 3000, threshold = 1, message = MSG) => { | |
let state = CLOSED | |
let failures = 0 | |
let openedAt | |
function handleSuccess(value) { | |
if(state !== CLOSED) { |
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 callBackend(url) { | |
return fetch(url) | |
.then(parseResponse) | |
} | |
const withCircuitBreaker = circuitBreaker(callBackend) | |
withCircuitBreaker('http://my.backend.com') | |
.then(doSomethingWithData, handleError) |
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 createMyType = (startVal) => { | |
let name = "Magic Object" | |
let magic = 32 | |
let val = startVal | |
return { | |
add: (b) => { val += magic + b }, | |
sub: (b) => { val += magic - b }, | |
getVal: () => val | |
} |
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
return Object.create(baseObejct, { | |
name: { | |
writable: true, | |
value: "Magic Object", | |
}, | |
magic: { | |
writable: true, | |
value: 32, | |
}, | |
val: { |
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
window.BENCH = ((target) => { | |
const MyType = function(startVal) { | |
this.val = startVal | |
this.name = "Magic Object" | |
this.magic = 32 | |
} | |
MyType.prototype.add = function(b) { | |
this.val += this.magic + b | |
return this |
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 MyType = function(startVal) { | |
this.val = startVal | |
... | |
} | |
MyType.prototype.add = function(b) { ... } | |
MyType.prototype.sub = function(b) { ... } | |
... | |
for(let i = 0; i < 1000000; i++) { |
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 createMyType = (startVal) => { | |
let val = startVal | |
let magic = ... | |
return { | |
add: (b) => { | |
val += magic + b | |
}, | |
sub: (b) => { ... }, |
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 test(ar) { | |
return ar2 tratatat | |
} |
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
if (__DEV__) { | |
//do dev-only stuff that's not really interesting in production | |
} |
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
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify('production') | |
} | |
}) |
OlderNewer