Last active
June 26, 2017 16:33
-
-
Save drwpow/a06a49ee5a68c707902fcf1c2e6fe390 to your computer and use it in GitHub Desktop.
RxJS in Vue.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs/Observable'; | |
import 'rxjs/add/observable/fromEvent'; | |
import 'rxjs/add/operator/throttleTime'; | |
import 'rxjs/add/operator/debounceTime'; | |
export default { | |
data() { | |
resize$: {}, | |
}, | |
created() { | |
this.resize$ = Observable | |
.fromEvent(window, 'resize') // event to watch | |
.debounceTime(16) // 16ms | |
.subscribe(e => this.resizeHandler(e)); | |
}, | |
destroy() { | |
this.resize$.unsubscribe(); | |
}, | |
methods: { | |
resizeHandler(e) { | |
// resize code goes here | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment