Skip to content

A small utility function that extends the class it is passed with abilities to observe changes to its properties with RxJS

License

Notifications You must be signed in to change notification settings

PetterSa/observablepropertychanges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Observable Property Changes

A small utility function that extends the class it is passed with abilities to observe changes to its properties with RxJS

⚠ Warning ⚠

Because of strange limitations, using this on a class that has ES private properties will break anything that tries to use them.

See discussions:

tc39/proposal-class-fields#106

https://github.com/littledan/proposal-proxy-transparent

https://github.com/rdking/proposal-proxy-transparency/issues

When this gets resolved I will fix this! Looking forward to it!

Usage example

npm i observable-property-changes
import ObservablePropertyChanges, { WithPropertyObserver } from 'observable-property-changes';
class Example {
    prop = 'A value'
}
const ObservableExample = ObservablePropertyChanges(Example);
const observableExample: Example & WithPropertyObserver = new ObservableExample();
observableExample.observableForProperty('prop').subscribe(prop => console.log('Prop changed value to ' + prop))

observableExample.prop = 'Another value';
// This is printed: Prop changed value to Another value

About

A small utility function that extends the class it is passed with abilities to observe changes to its properties with RxJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published