@nbottarini/observable
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

npm License: MIT CI Status

Observable-Js

Tiny Observable pattern implementation for creating observable properties

Installation

Npm:

$ npm install --save @nbottarini/observable

Yarn:

$ yarn add @nbottarini/observable

Usage

View1.ts:

export class View1 {
    public readonly buttonClicked = new Observable<ClickEvent>()
    public readonly textChanged = new Observable<TextChangedEvent>()
    
    // Do something internally to handle UI events 
    
    private handleButtonClick(e: ClickEvent) {
        this.buttonClicked.notify(e)
    }
}

View2.ts:

export class View2 {
    private sampleView: View1
    
    constructor() {
        this.sampleView = new View1()
        this.sampleView.buttonClicked.subscribe(this, this.onSampleViewButtonClicked)
    }

    onSampleViewButtonClicked(e: ClickEvent) {
        
    }
}

Observable properties:

const nameProperty = new ObservableProperty('John')
nameProperty.changed.subscribe(this, this.onNameChanged)

nameProperty.value = 'new name'

Readme

Keywords

Package Sidebar

Install

npm i @nbottarini/observable

Weekly Downloads

82

Version

0.5.0

License

MIT

Unpacked Size

11.3 kB

Total Files

8

Last publish

Collaborators

  • nbottarini