1.0.3 • Published 11 months ago

@tipy/observable v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Observable

Observable is a very tiny library to notify events to its subscribers.

Its main goal is to subscribe events to the instance of the observable class and then trigger the events themselves by calling notify function, check the section how to use it.

Install

yarn add @tipy/observable

How to use

It is quite simple, basically you first create an instance of the Observable class, then subscribe one or more events and excute notify function. let's see this in an example.

import Observable from '@tipy/observable';

const obs = new Observable();

const test1 = () => console.log('test 1');
const test2 = () => console.log('test 2');

obs.subscribe(test1);
obs.subscribe(test2);

obs.notify();

// functions test1 and test2 will be called when notify is executed
// test 1
// test 2

API

Function nameParametersDescription
subscribefunction(data?)you must pass a function as an argument to the subscribe function. data is optional
unsubscribefunctionyou must pass the function you want to unsubscribe
notifydata?data is optional. if passed, it will pass along to the subscribed functions
1.0.3

11 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago