Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
caiogondim committed Feb 6, 2018
1 parent 19b4d3e commit 5844aa5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const memoizedRamda = R.memoize(fibonacci)
const memoizedImemoized = iMemoized.memoize(fibonacci)
const memoizedLRUSingleCache = lruMemoize(fibonacci)
const memoizedLRUWithLimit = lruMemoize(fibCount)(fibonacci)
const memoizedNano = nano(fibonacci);
const memoizedNano = nano(fibonacci)
const memoizedFastMemoizeCurrentVersion = fastMemoize(fibonacci)

const benchmark = new Benchmark.Suite()
Expand Down Expand Up @@ -100,7 +100,7 @@ benchmark
memoizedLRUWithLimit(fibNumber)
})
.add('nano-memoize', () => {
memoizedNano(fibNumber)
memoizedNano(fibNumber)
})
.add(`fast-memoize@current`, () => {
memoizedFastMemoizeCurrentVersion(fibNumber)
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ function memoize (fn, options) {
//

function isPrimitive (value) {
return value == null || typeof value === "number" || typeof value === "boolean"; // || typeof value === "string" 'unsafe' primitive for our needs
return value == null || typeof value === 'number' || typeof value === 'boolean' // || typeof value === "string" 'unsafe' primitive for our needs
}

function monadic (fn, cache, serializer, arg) {
var cacheKey = isPrimitive(arg) ? arg : serializer(arg)

var computedValue = cache.get(cacheKey);
if (typeof computedValue==="undefined") {
var computedValue = cache.get(cacheKey)
if (typeof computedValue === 'undefined') {
computedValue = fn.call(this, arg)
cache.set(cacheKey, computedValue)
}

return computedValue;
return computedValue
}

function variadic (fn, cache, serializer) {
var args = Array.prototype.slice.call(arguments, 3)
var cacheKey = serializer(args)

var computedValue = cache.get(cacheKey);
if (typeof computedValue==="undefined") {
var computedValue = cache.get(cacheKey)
if (typeof computedValue === 'undefined') {
computedValue = fn.apply(this, args)
cache.set(cacheKey, computedValue)
}

return computedValue;
return computedValue
}

function assemble (fn, context, strategy, cache, serialize) {
Expand Down
14 changes: 4 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,19 @@ test('memoize functions with spread arguments', () => {
expect(memoizedMultiply(2, 4, 5, 6)).toEqual([8, 10, 12])
})


test('single arg primitive test', () => {
function kindOf (arg) {
return (arg && typeof arg ==="object" ? arg.constructor.name : typeof arg)
return (arg && typeof arg === 'object' ? arg.constructor.name : typeof arg)
}

const memoizedKindOf = memoize(kindOf)

// Assertions
expect(memoizedKindOf(2)).toEqual("number")
expect(memoizedKindOf("2")).toEqual("string")
expect(memoizedKindOf(2)).toEqual('number')
expect(memoizedKindOf('2')).toEqual('string')
})

test('inject custom cache', () => {
let hasMethodExecutionCount = 0
let setMethodExecutionCount = 0

// a custom cache instance must implement:
Expand All @@ -111,8 +109,7 @@ test('inject custom cache', () => {
// - set
// - delete
const customCacheProto = {
has (key) {
hasMethodExecutionCount++
has (key) {
return (key in this.cache)
},
get (key) {
Expand Down Expand Up @@ -144,7 +141,6 @@ test('inject custom cache', () => {
memoizedMinus(3, 1)
memoizedMinus(3, 1)

// expect(hasMethodExecutionCount).toBe(2)
expect(setMethodExecutionCount).toBe(1)
})

Expand All @@ -171,8 +167,6 @@ test('inject custom serializer', () => {
expect(serializerMethodExecutionCount).toBe(2)
})



test('explicitly use exposed monadic strategy', () => {
let numberOfCalls = 0
function plusPlus (number) {
Expand Down

0 comments on commit 5844aa5

Please sign in to comment.