@genesislcap/foundation-layout 14.92.1 → 14.92.2-beta.revert-PA-913.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-layout](./foundation-layout.md) &gt; [LayoutComponentWithState](./foundation-layout.layoutcomponentwithstate.md)
4
-
5
- ## LayoutComponentWithState interface
6
-
7
- Interface to implement on an item which is a component of the layout and you wish to serialise state with. This is saved separately for each instance of the component, which allows you to restore multiple instances of the same component with different state.
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export interface LayoutComponentWithState<T>
13
- ```
14
-
15
- ## Remarks
16
-
17
- When the layout is saved either via the autosave functionality or manually calling [FoundationLayout.getLayout()](./foundation-layout.foundationlayout.getlayout.md)<!-- -->, all contained components will be requested to provide state if they wish.
18
-
19
- Any state which is provided will be saved as part of the layout config and will be passed back to the component when the layout is reloaded. Before an item is appended onto the layout DOM, the state will be applied to the component via `applyState`<!-- -->. You will likely want to cache this and then use it later in the lifecycle of the component. The state is `null` when the instance is first created.
20
-
21
- See the written documentation for some error scenarios to consider about when implementing this interface.
22
-
23
- ## Example 1
24
-
25
-
26
- ```
27
- type ComponentState = {
28
- foo: string;
29
- }
30
- \@customElement({ name: 'my-component' })
31
- export class MyComponent extends FASTElement implements LayoutComponentWithState<ComponentState> {
32
- \@observable foo: string;
33
- private fooCache: ComponentState | null;
34
-
35
- getCurrentState(): ComponentState {
36
- if (!this.foo) return null;
37
- return {
38
- foo: this.foo;
39
- }
40
- }
41
-
42
- applyState(state: ComponentState | null) {
43
- this.fooCache = state;
44
- }
45
-
46
- connectedCallback() {
47
- // do other required setup
48
- if (this.fooCache) {
49
- this.foo = this.fooCache.foo;
50
- }
51
- }
52
- }
53
- ```
54
-
55
- ## Example 2
56
-
57
- If you are using the autosave functionality you should inform the layout system when you update the state of a component, otherwise the state will only be updated when the user performs an action such as resizing an item. Use the [LayoutReceiveEvents](./foundation-layout.layoutreceiveevents.md) `autosave` event.
58
-
59
- ```
60
- // Same component as above
61
- export class MyComponent extends FASTElement implements LayoutComponentWithState<ComponentState> {
62
- // can use xChanged pattern as `foo` was declared observable
63
- fooChanged() {
64
- this.$emit(LayoutReceiveEvents.autosave);
65
- }
66
- }
67
- ```
68
-
69
- ## Methods
70
-
71
- | Method | Description |
72
- | --- | --- |
73
- | [applyState(state)](./foundation-layout.layoutcomponentwithstate.applystate.md) | Handle any state that has been saved previously for this instance of this component. This will be called before the component is appended to the DOM. Due to the lifecycle events not running by this point, it is recommended you cache the state and then apply it in <code>connectedCallback</code>. |
74
- | [getCurrentState()](./foundation-layout.layoutcomponentwithstate.getcurrentstate.md) | Provide the state you wish to save. It is recommended if the component which implements this interface has not fully initialised at the point this is called that you return <code>null</code> as the state, following the pattern of <code>null</code> being set as the initial state. |
75
-