@nbottarini/observable
v0.5.0
Published
Tiny Observable pattern implementation for creating observable properties
Downloads
222
Readme
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'