Skip to content

Instantly share code, notes, and snippets.

@drwpow
Last active June 26, 2017 16:33
Show Gist options
  • Save drwpow/a06a49ee5a68c707902fcf1c2e6fe390 to your computer and use it in GitHub Desktop.
Save drwpow/a06a49ee5a68c707902fcf1c2e6fe390 to your computer and use it in GitHub Desktop.
RxJS in Vue.js
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