'Is there a way to import rxjs into a plain js web custom component?

I'm trying to create web custom components using plain js. I would like to use rxjs and observables to fetch json content from a REST endpoint that I am also creating using python pyramid. However, an error - 'TypeError: global is undefined' - is being thrown when I import rxjs.

import 'https://unpkg.com/@reactivex/[email protected]/dist/global/rxjs.umd.js';

also tried:

import 'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js';

I would like to NOT use npm at all.



Solution 1:[1]

<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js"></script>

then:

const { Observable, from } = rxjs;

Solution 2:[2]

With NodeJS and plain JS:

<script src="node_modules/rxjs/dist/bundles/rxjs.umd.js"></script>


   // And JS code sample...  
 
    this.networkStatus$ = rxjs.merge(
        rxjs.of(null),
        rxjs.fromEvent(window, 'online'),
        rxjs.fromEvent(window, 'offline')
    )//.subscribe( )

    this.applicationStatus$ = new rxjs.BehaviorSubject(this.getApplicationStatus());

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ferd tomale
Solution 2 Didier68