Skip to content

HectorFront/templates-observables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Templates observables (Examples with React)

VanillaJS <- RxJS

Observable Global

Notify with event id

import {ObservableGlobal} from "./observables/observableGlobal";
export const _ObservableGlobal = ObservableGlobal;

function() App {
   ...
   
   _ObservableGlobal.notify('event_id', value);
   
   ...
}

Get value with event id

import {_ObservableGlobal} from './App';

...

useEffect(() => {
    const observer = value => {
        console.log(value);
    }
    _ObservableGlobal.subscribe('listener_id', observer, 'event_id');
    return () => _ObservableGlobal.unsubscribe('listener_id');
},[]);

...

Observable with Class instance

Notify with listener id

import {Observable} from "./observables/observable";
export const _Observable = new Observable();

function() App {
   ...

    _Observable.notify('listener_id', value);
   
   ...
}

Get value with listener id

import {_Observable} from './App';

...

useEffect(() => {
    const observer = value => {
        console.log(value);
    }
    _Observable.subscribe('listener_id', observer);
    return () => _Observable.unsubscribe('listener_id');
},[]);

...

npm i or yarn install

npm start or yarn start Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

What is an Observer?

An Observer is a consumer of values delivered by an Observable. Observers are simply a set of callbacks.

@authors: Hector Rodrigues da Silva and Giovane Santos Silva

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published