persisting_state_of_components.md: Make it more clear that components are services (and promote light-services)

This commit is contained in:
Karol Lewandowski 2023-10-12 10:54:04 +02:00
parent 62af21d9f7
commit f7ca5c12f5

View File

@ -37,6 +37,7 @@ In addition, delegates track property modifications internally, which help decre
It is recommended to create a separate classes for a component and its state: It is recommended to create a separate classes for a component and its state:
```kotlin ```kotlin
@Service
@State(...) @State(...)
class MySettings : SimplePersistentStateComponent<MyState>(MyState()) class MySettings : SimplePersistentStateComponent<MyState>(MyState())
@ -57,6 +58,7 @@ In this case, the state class instance is typically stored as a field in the `Pe
When the state is loaded from the storage, it is assigned to the state field (see `loadState()`): When the state is loaded from the storage, it is assigned to the state field (see `loadState()`):
```java ```java
@Service
@State(...) @State(...)
class MySettings implements PersistentStateComponent<MySettings.State> { class MySettings implements PersistentStateComponent<MySettings.State> {
@ -85,6 +87,7 @@ Using a separate state class is the recommended approach.
In this case, `getState()` returns the component itself, and `loadState()` copies properties of the state loaded from storage to the component instance: In this case, `getState()` returns the component itself, and `loadState()` copies properties of the state loaded from storage to the component instance:
```java ```java
@Service
@State(...) @State(...)
class MySettings implements PersistentStateComponent<MySettings> { class MySettings implements PersistentStateComponent<MySettings> {