Last active
May 17, 2020 17:02
-
-
Save splincode/7a3ef971cc4889f429e376cfc114f159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@StateRepository() | |
@State({ | |
name: 'counter', | |
defaults: 0 | |
}) | |
@Injectable() | |
class CounterState extends NgxsDataRepository<number> | |
implements NgxsDataDoCheck, NgxsDataAfterReset { | |
private subscription: Subscription; | |
constructor(private customer: CustomerService) { | |
super(); | |
} | |
/** | |
* @description: | |
* This method guarantees that it will be called after the application is rendered | |
* and all services of the Angular are loaded, so you can subscribe to the necessary | |
* data streams (any observables) in this method and unsubscribe later in the method `ngxsDataAfterReset` | |
*/ | |
public ngxsDataDoCheck(): void { | |
console.log(this.isInitialised); // true | |
console.log(this.isBootstrapped); // true | |
this.subscription = this.customer.events.subscribe((e) => console.log(e)); | |
} | |
public ngxsDataAfterReset(): void { | |
this.subscription?.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment