ngx-store
ngx-store copied to clipboard
Decorators on regular classes
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?
Decorators are designed for singleton classes (like Angular's Components and Services). In your case, I'd go for one of the possible solutions:
- Implement
OnDestroy
interface and callUser.ngOnDestroy
method manually - Make User class
@Injectable()
- Use services for managing the data