react-custom-scroll
Advanced tools
Comparing version 4.1.4 to 4.1.5
{ | ||
"name": "react-custom-scroll", | ||
"version": "4.1.4", | ||
"version": "4.1.5", | ||
"description": "An easily designable, cross browser (!!), custom scroll with ReactJS Animations and scroll rate **exactly** like native scroll", | ||
@@ -5,0 +5,0 @@ "main": "index", |
@@ -24,4 +24,4 @@ [![NPM version][npm-image]][npm-url] | ||
**From unpkg cdn:** | ||
* [Js file](https://unpkg.com/react-custom-scroll@4.1.4/dist/reactCustomScroll) | ||
* [css file](https://unpkg.com/react-custom-scroll@4.1.4/dist/customScroll.css) | ||
* [Js file](https://unpkg.com/react-custom-scroll@4.1.5/dist/reactCustomScroll) | ||
* [css file](https://unpkg.com/react-custom-scroll@4.1.5/dist/customScroll.css) | ||
@@ -28,0 +28,0 @@ Wrap your content with the custom scroll component |
import React, { Component, createRef } from 'react' | ||
import reactDOM from 'react-dom' | ||
import styles from './cs.scss' | ||
import { simpleDebounce } from './simpleDebounce' | ||
const simpleDebounce = (func, delay) => { | ||
let timer | ||
function cancel() { | ||
clearTimeout(timer) | ||
} | ||
function debounced() { | ||
cancel() | ||
timer = setTimeout(() => { | ||
func() | ||
}, delay) | ||
} | ||
debounced.cancel = cancel | ||
return debounced | ||
} | ||
const ensureWithinLimits = (value, min, max) => { | ||
@@ -24,0 +7,0 @@ min = !min && min !== 0 ? value : min |
export const simpleDebounce = (func, delay) => { | ||
let timer | ||
return function() { | ||
function cancel() { | ||
clearTimeout(timer) | ||
} | ||
function debounced() { | ||
cancel() | ||
timer = setTimeout(() => { | ||
@@ -10,2 +14,5 @@ func() | ||
} | ||
} | ||
debounced.cancel = cancel | ||
return debounced | ||
} |
@@ -44,2 +44,14 @@ import {simpleDebounce} from '../main/simpleDebounce' | ||
}) | ||
}) | ||
it('should cancel scheduled function call on debounced.cancel call', () => { | ||
let counter = 0 | ||
const debounced = simpleDebounce(() => counter++, 10) | ||
debounced() | ||
jasmine.clock().tick(5) | ||
debounced.cancel() | ||
jasmine.clock().tick(15) | ||
expect(counter).toEqual(0) | ||
}) | ||
}) |
253252
2695