All Projects → PSanetra → bind-observable

PSanetra / bind-observable

Licence: MIT License
Provides a typescript decorator which binds class properties to observable companion properties.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to bind-observable

Until Destroy
🦊 RxJS operator that unsubscribe from observables on destroy
Stars: ✭ 1,071 (+7040%)
Mutual labels:  rxjs, decorators
Dugong
Minimal State Store Manager for React Apps using RxJS
Stars: ✭ 10 (-33.33%)
Mutual labels:  rxjs, decorators
Ngx Auto Unsubscribe
Class decorator that will automatically unsubscribe from observables
Stars: ✭ 337 (+2146.67%)
Mutual labels:  rxjs, decorators
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+760%)
Mutual labels:  rxjs, decorators
rx-ease
Spring animation operator for rxjs 🦚✨
Stars: ✭ 16 (+6.67%)
Mutual labels:  rxjs
vue-rxjs
Yet another rxjs binding library for Vue.js
Stars: ✭ 14 (-6.67%)
Mutual labels:  rxjs
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (+353.33%)
Mutual labels:  rxjs
reactive-hooks
Reactive Hooks Library
Stars: ✭ 29 (+93.33%)
Mutual labels:  rxjs
ngrx-signalr-core
A library to handle realtime SignalR (.NET Core) events using @angular, rxjs and the @ngrx library
Stars: ✭ 18 (+20%)
Mutual labels:  rxjs
route-decorators
ES7 decorators that simplify Koa and Express route creation
Stars: ✭ 71 (+373.33%)
Mutual labels:  decorators
polog
Логирование должно быть красивым
Stars: ✭ 26 (+73.33%)
Mutual labels:  decorators
angular-minesweeper
Play a different version of the classic Minesweeper game built with Angular
Stars: ✭ 54 (+260%)
Mutual labels:  rxjs
react-rxjs-state-management-hoc-example
Showcasing how RxJS can work in React with state management and higher-order components.
Stars: ✭ 14 (-6.67%)
Mutual labels:  rxjs
javascript-fun
source code generator for www.javascript.fun
Stars: ✭ 32 (+113.33%)
Mutual labels:  rxjs
kiwi
Built using only nodejs core. Lightweight, intuitive together with great performance and response timing.
Stars: ✭ 45 (+200%)
Mutual labels:  decorators
discord.ts
🤖 Create your discord bot by using TypeScript and decorators!
Stars: ✭ 315 (+2000%)
Mutual labels:  decorators
signalr-client
SignalR client library built on top of @aspnet/signalr. This gives you more features and easier to use.
Stars: ✭ 48 (+220%)
Mutual labels:  rxjs
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (+73.33%)
Mutual labels:  decorators
react-rxjs-communicating-between-components
React + RxJS - Communicating Between Components with Observable & Subject
Stars: ✭ 33 (+120%)
Mutual labels:  rxjs
reactive-store
A store implementation for state management with RxJS
Stars: ✭ 29 (+93.33%)
Mutual labels:  rxjs

BindObservable decorator

npm version Travis Coverage Status

This library provides the @BindObservable() decorator, which binds a property to a observable companion property. The companion Observable always emits the latest value of the bound property.

Installation

npm install bind-observable --save

Usage

The following code binds the property myProp to the observable property myProp$ and prints two values ('initialValue' and 'newValue') to the console.

class MyClass {

  @BindObservable()
  public myProp: string = 'initialValue';
  public myProp$!: Observable<string>;

}

const myInstance = new MyClass();

myInstance.myProp$.subscribe(console.log);

myInstance.myProp = 'newValue'

Details

This decorator adds property accessors to the PropertyDescriptor of the decorated property. It will emit the getter value after every underlying setter call. You can use the emitRawSetterValue option to emit the raw setter value and not a value, which is possibly modified by underlying setter and getter calls.

The decorator will also emit initial property values only if these values are explictly defined. In the following example the observable initializedProp$ does emit a undefined value. On the other hand uninitializedProp$ will emit its first value on the first assignment.

class MyClass {

  @BindObservable()
  public uninitializedProp?: string;
  public uninitializedProp$!: Observable<string>;

  @BindObservable()
  public initializedProp: string | undefined = undefined;
  public initializedProp$!: Observable<string>;

}

const myInstance = new MyClass();

// Prints nothing to the console
myInstance.uninitializedProp$.subscribe(console.log);

// Prints 'undefined' to the console
myInstance.initializedProp$.subscribe(console.log);

Known Bugs

This decorator does not work if used directly on property accessors, but it can be used together with other decorators which add accessors to the PropertyDescriptor.

class TestClass {
  private _myProp: string | undefined;

  public get myProp(): string | undefined {
    return this._myProp
  }

  // This does not work :-(
  @BindObservable()
  public set myProp(value: string | undefined) {
    this._myProp = value
  }

  private myProp$!: Observable<string | undefined>;

  // This works even if DecoratorX and DecoratorY modify the property accessors
  @DecoratorX()
  @BindObservable()
  @DecoratorY()
  private myPropWithMultipleDecorators: string = 'initialValue';
  private myPropWithMultipleDecorators$!: Observable<string>;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].