ngx-store icon indicating copy to clipboard operation
ngx-store copied to clipboard

Decorators on regular classes

Open inwaar opened this issue 5 years ago • 1 comments

We have an issue that happens once in a while that makes boolean values to be reset in likely AOT mode. I know there is a solution to add onDestroy, but it can be used only for components and services. Is there anything for simple classes like:

class User {
export class User {
    @LocalStorage('userToken') private token: string = null;
    @LocalStorage('userSomeBooleanProperty') private someBooleanProperty: boolean = false;
}

someBooleanProperty resets to false sometimes.

is this somehow related to #16 and #20? or the decorators of the library are supposed to be used only for components and services?

inwaar avatar Nov 21 '19 12:11 inwaar

Decorators are designed for singleton classes (like Angular's Components and Services). In your case, I'd go for one of the possible solutions:

  1. Implement OnDestroy interface and call User.ngOnDestroy method manually
  2. Make User class @Injectable()
  3. Use services for managing the data

DanielKucal avatar Jan 26 '20 00:01 DanielKucal