https://github.com/skybrud/sky-window
Lightweight module for standard use of rxJs observables
https://github.com/skybrud/sky-window
Last synced: 10 months ago
JSON representation
Lightweight module for standard use of rxJs observables
- Host: GitHub
- URL: https://github.com/skybrud/sky-window
- Owner: skybrud
- License: mit
- Created: 2017-03-16T07:27:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T07:49:09.000Z (over 8 years ago)
- Last Synced: 2025-07-25T02:04:43.692Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# sky-window
> Simple js lightweight module for window events based on RxJs - handles resize and scroll events.
## Dependencies
- [RxJs](https://github.com/ReactiveX/rxjs)
## Usage
1. Install RxJs
2. Import sky-window
``` js
SkyWindow.resize.subscribe(() => {
// On resize do what I type here
});
SkyWindow.scroll.subscribe(() => {
// On scroll do what I type here
});
```
## How it works
Sky-window uses hot observbles by invoking `.share` which is the same as `.publish().refCount()`. This means that when at least one instance is listening til e.g. resize it will run, but if refcount is 0 it will automaticly be unsubscribed. In addition resize will only fire 100ms after the last resize event.
``` js
resize: Observable.fromEvent(window, 'resize').share().debounce(() => Observable.timer(100)),
scroll: Observable.fromEvent(window, 'scroll').share(),
```
# Credits
This module is made by the Frontenders at [skybrud.dk](http://www.skybrud.dk/). Feel free to use it in any way you want. Feedback, questions and bugreports should be posted as issues. Pull-requests appreciated!