downup
Tiny listener on numerical value changes. Works in Node and with Browserify.
Install
With npm do:
$ npm install downup --save
Usage
Basic examples
var Downup = ; // Create instancevar downup = ; // Add listenerdownup; // Will trigger since default value is 0downup; // Will trigger again with offset -1downup; // Will not triggerdownup; // Remove all listeners attached to number 1downup; // Will not trigger since the listener has been removeddownup;
Sticky example
// Update on scroll (please debounce this ;)window; // Listen to menu and add sticky classvar menu = document; downup;
Instance Methods
downup extends TinyEmitter and inherit from its instance methods.
on(number, callback[, context])
Subscribe to a number
number
- the number to subscribe tocallback
- the function to call when number is reachedcontext
- (OPTIONAL) - the context to bind the event callback to
once(number, callback[, context])
Subscribe to an event only once
number
- the number to subscribe tocallback
- the function to call when number is reachedcontext
- (OPTIONAL) - the context to bind the event callback to
off(number[, callback])
Unsubscribe from an number. If no callback is provided, it unsubscribes you from all callbacks registered to this number.
number
- the number to unsubscribe fromcallback
- the function used when binding to the number
update(number)
Update downup.value
and trigger any registered numbers between old value and this one
number
- the new value
set(number)
Similar to update(number)
but it will not trigger any event.
number
- the new value
emit(number[, offset])
Trigger a specific number (should not be used...)
number
- the number to emitoffset
- the offset to pass to the callbacks
Test and Build
Build (Tests, Browserifies, and minifies)
npm installnpm run build
Test
npm installnpm test
License
MIT