Skip to content

Commit

Permalink
fix arguments bug in throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Oct 30, 2017
1 parent b27b1dd commit 7f9a991
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 848 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"development": {
"presets": [
["env", {
"targets": {"node": 8},
"targets": {"node": "current"},
"modules" : false
}]
],
Expand All @@ -12,7 +12,7 @@
"test": {
"presets": [
["env", {
"targets": {"node": 8}
"targets": {"node": "current"}
}]
]
}
Expand Down
62 changes: 37 additions & 25 deletions __tests__/debounce.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
const { debounce } = require('../rambdax')
const { delay, debounce } = require('../rambdax')

describe('', () => {
it('', async () => {
let counter = 0
const inc = () => {
counter++
}
test('', async () => {
let counter = 0
let aHolder
let bHolder

const delay = ms => new Promise(resolve => {
setTimeout(resolve, ms)
})
const incWrapped = debounce(inc, 500)
incWrapped()
expect(counter).toBe(0)
await delay(200)
incWrapped()
expect(counter).toBe(0)
await delay(200)
incWrapped()
expect(counter).toBe(0)
await delay(200)
incWrapped()
expect(counter).toBe(0)
await delay(700)
expect(counter).toBe(1)
})
const inc = (a,b) => {
aHolder = a
bHolder = b
counter++
}
const incWrapped = debounce(inc, 500)

incWrapped(1,2)
expect(counter).toBe(0)
expect(aHolder).toBe(undefined)
expect(bHolder).toBe(undefined)

await delay(200)

incWrapped(2,3)
expect(counter).toBe(0)

await delay(200)

incWrapped(3,4)
expect(counter).toBe(0)
expect(aHolder).toBe(undefined)
expect(bHolder).toBe(undefined)

await delay(200)
incWrapped(5,6)
expect(counter).toBe(0)

await delay(700)
expect(counter).toBe(1)
expect(aHolder).toBe(5)
expect(bHolder).toBe(6)
})

test('immediate debounce', async () => {
Expand Down
12 changes: 5 additions & 7 deletions __tests__/intersection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const R = require('../rambdax')

describe('intersection', () => {
it('', () => {
expect(
R.intersection([ 1, 3, 5 ], [ 2, 3, 5 ])
).toEqual([ 3, 5 ])
})
})
test('', () => {
expect(
R.intersection([ 1, 3, 5 ], [ 2, 3, 5 ])
).toEqual([ 3, 5 ])
})
51 changes: 31 additions & 20 deletions __tests__/throttle.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
const { throttle } = require('../rambdax')
const R = require('../rambdax')

describe('', () => {
it('', async () => {
let counter = 0
const inc = () => {
counter++
}
test('', async () => {
let counter = 0
let aHolder
let bHolder

const delay = ms => new Promise(resolve => {
setTimeout(resolve, ms)
})
const incWrapped = throttle(inc, 1000)
await delay(500)
incWrapped()
incWrapped()
incWrapped()
expect(counter).toBe(1)
await delay(1500)
incWrapped()
expect(counter).toBe(2)
})
const inc = (a,b) => {
aHolder = a
bHolder = b
counter++
}

const incWrapped = R.throttle(inc, 1000)

incWrapped(1,2)

await R.delay(500)

incWrapped(2,3)
incWrapped(3,4)

expect(counter).toBe(1)
expect(aHolder).toBe(1)
expect(bHolder).toBe(2)

await R.delay(1000)

incWrapped(5,6)

expect(counter).toBe(2)
expect(aHolder).toBe(5)
expect(bHolder).toBe(6)
})

Loading

0 comments on commit 7f9a991

Please sign in to comment.