0.5.0 • Published 6 months ago

@nbottarini/observable v0.5.0

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

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'
0.5.0

6 months ago

0.4.1

6 months ago

0.4.0

6 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.2

1 year ago

0.2.0

2 years ago