subscribe-ui-event
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -10,7 +10,8 @@ /** | ||
module.exports = { | ||
connections: {}, | ||
EE: new EventEmitter(), | ||
connections: {}, | ||
enableResizeInfo: false, | ||
enableScrollInfo: false, | ||
listeners: {}, | ||
enableScrollInfo: false, | ||
enableResizeInfo: false | ||
removers: [] | ||
}; |
@@ -18,2 +18,3 @@ /** | ||
var rAFThrottle = require('./lib/rAFThrottle'); | ||
var removers = require('./globalVars').removers; | ||
var subscriptions = require('./globalVars').subscriptions; | ||
@@ -67,2 +68,11 @@ | ||
this._ctx = undefined; | ||
// remove the remover from removers array | ||
for (var i = removers.length - 1; i >= 0; i--) { | ||
var remover = removers[i]; | ||
if (remover === this) { | ||
removers.splice(i, 1); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -87,2 +97,3 @@ }; | ||
var remover = connectThrottle(throttledEvent, cb, context, throttledMainEvent); | ||
removers.push(remover); | ||
@@ -144,2 +155,3 @@ if (listeners[throttledMainEvent]) { | ||
var remover = connectThrottle(throttledEvent, cb, context); | ||
removers.push(remover); | ||
@@ -146,0 +158,0 @@ if (listeners[throttledEvent]) { |
{ | ||
"name": "subscribe-ui-event", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A single, throttle built-in solution to subscribe to browser UI Events.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -47,3 +47,3 @@ # subscribe-ui-event | ||
Provide throttled version of window or document events, such like `scroll`, `resize` and `visibilitychange` to subscribe. | ||
Provide throttled version of window or document events, such like `scroll`, `resize`, `touch` and `visibilitychange` to subscribe, see below. | ||
@@ -101,4 +101,4 @@ **Note on IE8 or the below, the throttle will be turned off because the event object is global and will be deleted for setTimeout or rAF.** | ||
1. scroll - window.scoll | ||
2. scrollStart - The start window.scoll | ||
3. scrollEnd - The end window.scoll | ||
2. scrollStart - The start of window.scoll | ||
3. scrollEnd - The end of window.scoll | ||
4. resize - window.resize | ||
@@ -108,3 +108,17 @@ 5. resizeStart - The start window.resize | ||
7. visibilitychange - document.visibilitychange (IE8 doesn't support) | ||
8. touchmoveStart - The start of window.touchmove | ||
9. touchmoveEnd - The end of window.touchmove | ||
10. touchmove - window.touchmove | ||
11. touchstart - window.touchstart | ||
12. touchend - window.touchend | ||
### unsubscribe | ||
```js | ||
Void unsubscribe(String eventType, Function callback) | ||
``` | ||
Unsubscribe an event listener, suggest to use `subscription.unsubscribe()`, because it may accidentally unsubscribe those events having the same `eventType` and `callback` but different `throttleRate`. | ||
## License | ||
@@ -111,0 +125,0 @@ |
33085
16
709
125