leocode/RxStores

Initializer collides with custom variables

Closed this issue · 1 comments

There is a strange issue which causes custom class fields to become undefined right after init is done.

Example:

export class SomeStore extends Store<string[]> {
  private updateTrigger$ = new Subject<void>();

  init() {
    this.updateTrigger$.subscribe(/* ... */);
  }
}

The workaround is to rename the init function to something like initStore(), and define constructor like this:

constructor() {
  super();
  this.initStore();
}

This is an expected behavior. Derived class initializes its properties after base constructor call completes.
Planned rework doesn't include any init(), though. Will be taken care of with #6.