Last active
October 11, 2022 14:18
Revisions
-
ccnokes revised this gist
Nov 8, 2019 . No changes.There are no files selected for viewing
-
ccnokes revised this gist
Feb 20, 2017 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,17 +4,19 @@ require('rxjs/add/operator/map'); require('rxjs/add/observable/merge'); function createOnline$() { //merge several events into one return Observable.merge( //use .map() to transform the returned Event type into a true/false value Observable.fromEvent(window, 'offline').map(() => false), Observable.fromEvent(window, 'online').map(() => true), //start the stream with the current online status Observable.create(sub => { sub.next(navigator.onLine); sub.complete(); //this one only emits once, so now we end it }) ); } // implement it const onlineSub = createOnline$().subscribe(isOnline => console.log(isOnline)); onlineSub.unsubscribe(); -
ccnokes revised this gist
Feb 20, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,5 +15,6 @@ function createOnline$() { ); } // implement it const onlineSub = createOnline$().subscribe(console.log); onlineSub.unsubscribe(); -
ccnokes revised this gist
Feb 20, 2017 . No changes.There are no files selected for viewing
-
ccnokes created this gist
Feb 20, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ const { Observable } = require('rxjs/Observable'); require('rxjs/add/observable/fromEvent'); require('rxjs/add/operator/map'); require('rxjs/add/observable/merge'); function createOnline$() { return Observable.merge( Observable.fromEvent(window, 'offline').map(() => false), Observable.fromEvent(window, 'online').map(() => true), //start the stream with the current online status Observable.create(sub => { sub.next(navigator.onLine); sub.complete(); }) ); } const onlineSub = createOnline$().subscribe(console.log); onlineSub.unsubscribe();