1.1.5 • Published 5 years ago

obsrvble v1.1.5

Weekly downloads
58
License
-
Repository
github
Last release
5 years ago

Logo

OBSRVBLE

A simple built-in observer toolkit for small JS projects.

Usage

npm i obsrvble

API doc

Observable

subscribe

subscribe(observer) Subcribe an observer to the observable object

unsubscribe

unsubscribe(observer) Unsubscribe an oberver from the observable object

unsubscribeAll

unsubscribeAll() Unsubscribe all the observers from the observable object

dispatch

dispatch(event, ...d) Dispatch an event and resolve the concerned observers

Observer

constructor

Creates a new observer constructor(event, resolver)

get event

The event associated with the observer get event()

Example

Create an observable object:

import {Observable} from "obsrvble";

export class Foo extends Observable {
    callThisToDispatch(bar) {
        this.dispatch("myEvent", bar);
    }
}

Subscribe an observer:

import {Observer} from "obsrvble";

const foo = new Foo();
foo.subscribe(new Observer(
    'myEvent',
    params => {
        // Do something here
        console.log(params[0]); // hello!
    }
));
foo.callThisToDispatch("hello!");

Why?

Because. I did not found any simple KISS observer / observable toolkit on NPM. This is my 🎁 to the community, cheers!

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago