You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to be able to set the default value for properties marked up with @localStorage().
Here is an example of an ideal usage from an AuthService.
@LocalStorage('AuthService.user')
protected user = ANONYMOUS;
Currently, if you set user, then reload the page local storage is overwritten with anonymous on object initialization.
I wish that if 'AuthService.user' was set user would be assign to it instead of ANONYMOUS on object construction. Alternatively, it would be nice to specify the default in the Decorator if it's not possible to maintain the TS default property value semantics like @LocalStorage('AuthService.user', ANONYMOUS)
Currently we work around this in our constructor as follows,
let storedUser = this.storage.retrieve('AuthService.user');
if (storedUser) {
this.user = storedUser;
} else {
this.user = ANONYMOUS;
}
which is a lot of boilerplate to carry around for a default value.
The text was updated successfully, but these errors were encountered:
Hi, i agree with you, the current behavior needs a bit of boilerplate to use a default value. Unfortunately i can't determine at the decorator level if i am at the initialization step and i shouldn't override an existing value or not.
The best i could do would be add another parameter to the decorator which would be the default value.
It would be nice to be able to set the default value for properties marked up with @localStorage().
Here is an example of an ideal usage from an AuthService.
Currently, if you set user, then reload the page local storage is overwritten with anonymous on object initialization.
I wish that if 'AuthService.user' was set user would be assign to it instead of ANONYMOUS on object construction. Alternatively, it would be nice to specify the default in the Decorator if it's not possible to maintain the TS default property value semantics like
@LocalStorage('AuthService.user', ANONYMOUS)
Currently we work around this in our constructor as follows,
which is a lot of boilerplate to carry around for a default value.
The text was updated successfully, but these errors were encountered: