+3
-6
@@ -35,3 +35,3 @@ 'use strict'; | ||
| // Stop raf if there is no more callbacks | ||
| if (emitter && emitter.e.scroll && emitter.e.scroll.length < 1) { | ||
| if (!emitter.e.scroll || emitter.e.scroll.length < 1) { | ||
| raf.cancel(rafId); | ||
@@ -47,6 +47,3 @@ } | ||
| raf.cancel(rafId); | ||
| if (emitter) { | ||
| emitter.off(); | ||
| emitter = null; | ||
| } | ||
| emitter = new Emitter(); | ||
| scrollY = 0; | ||
@@ -58,3 +55,3 @@ deltaY = 0; | ||
| function getEvent() { | ||
| if(ticking) { | ||
| if (ticking) { | ||
| var scroll = scrollTop(); | ||
@@ -61,0 +58,0 @@ deltaY = scroll - scrollY; |
+3
-3
| { | ||
| "name": "raf-scroll", | ||
| "version": "1.2.0", | ||
| "version": "1.3.0", | ||
| "description": "A scroll event that fires only once per frame.", | ||
@@ -10,4 +10,4 @@ "main": "index.js", | ||
| "scripts": { | ||
| "test": "./node_modules/.bin/prova -b ./test/**/*.js -l phantom -q", | ||
| "test-browser": "./node_modules/.bin/prova -b ./test/**/*.js -l chrome" | ||
| "test": "prova -b ./test/**/*.js -l phantom -q", | ||
| "test-browser": "prova -b ./test/**/*.js -l chrome" | ||
| }, | ||
@@ -14,0 +14,0 @@ "repository": { |
+25
-17
@@ -11,23 +11,31 @@ 'use strict'; | ||
| test('rAF call', function(assert) { | ||
| rafScroll.init(); | ||
| rafScroll.addOnce(function(event) { | ||
| assert.notDeepEqual(event.deltaY, 0, 'Event shouldn\'t be called if scroll hasn\'t changed.'); | ||
| assert.deepEqual(event.deltaY, 50, 'deltaY should reflect the latest change.'); | ||
| rafScroll.destroy(); | ||
| assert.end(); | ||
| }); | ||
| rafScroll.addOnce(function(event) { | ||
| assert.notDeepEqual(event.deltaY, 0, 'Event shouldn\'t be called if scroll hasn\'t changed.'); | ||
| assert.deepEqual(event.deltaY, 50, 'deltaY should reflect the latest change.'); | ||
| rafScroll.destroy(); | ||
| assert.end(); | ||
| }); | ||
| window.scrollTo(0, 50); | ||
| window.scrollTo(0, 50); | ||
| }); | ||
| test('Manual call', function(assert) { | ||
| rafScroll.init(); | ||
| window.scrollTo(0, 50); | ||
| window.scrollTo(0, 50); | ||
| raf(function() { | ||
| var ev = rafScroll.getCurrent(); | ||
| assert.notDeepEqual(ev.deltaY, 0, 'Calling getCurrent shouldn\'t affect/reset the deltaY value.'); | ||
| rafScroll.destroy(); | ||
| assert.end(); | ||
| }); | ||
| }); | ||
| raf(function() { | ||
| var ev = rafScroll.getCurrent(); | ||
| assert.notDeepEqual(ev.deltaY, 0, 'Calling getCurrent shouldn\'t affect/reset the deltaY value.'); | ||
| rafScroll.destroy(); | ||
| assert.end(); | ||
| }); | ||
| }); | ||
| test('.destroy()', function(assert) { | ||
| rafScroll.add(function() {}); | ||
| rafScroll.destroy(); | ||
| rafScroll.add(function(e) { | ||
| rafScroll.destroy(); | ||
| assert.equal(e !== undefined, true, 'the callback should have been called'); | ||
| assert.end(); | ||
| }); | ||
| }); |
4585
1.75%90
5.88%