@genesislcap/foundation-layout 14.77.1-alpha-7248576.0 → 14.77.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/README.md +62 -1
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -282,7 +282,7 @@ In the `@genesislcap/foundation-utils` package, there is a mix-in class `Lifecyc
282
282
 
283
283
  These can be used to gate certain functionality.
284
284
 
285
- For example, if there are parts of `disconnectedCallback` that you don't want to run when the item is being dragged around the layout, you can gate it behind a `(!this.shouldRunDisconnect) return;` early return. See [this example](#resource-intensive-component-resetting-in-layout).
285
+ For example, if there are parts of `disconnectedCallback` that you don't want to run when the item is being dragged around the layout, you can gate it behind a `(!this.shouldRunDisconnect) return;` early return. See [this example](#resource-intensive-component-resetting-in-layout) and [this example](#consuming-lifecycle-value-multiple-times).
286
286
 
287
287
  :::warning
288
288
  At the very least, you must run `super` calls to the lifecycle methods, or else your custom element will not work correctly.
@@ -1158,6 +1158,67 @@ The above is quite a comprehensive example, it doesn't necessarily have to be so
1158
1158
  The requirement to capture the parameter in the example above (e.g. `const shouldRunDisconnect = shouldRunDisconnect`) is to cache the information at the time of the lifecycle change, for use when the `DOM.queueUpdate` work is performed. This is not required if you run your lifecycle methods synchronously, but if you follow the above pattern you need to consider the `async` functionality being scheduled for after the layout considers the relevant lifecycle-gating functionality (such as dragging) to be over.
1159
1159
  :::
1160
1160
 
1161
+ ### Consuming lifecycle value multiple times
1162
+
1163
+ Consider the following example where you're gating multiple bits of functionality with `shouldRunConnect`:
1164
+ ```typescript
1165
+ @customElement({
1166
+ name: 'mock-connected',
1167
+ })
1168
+ export class MockConnected extends LifecycleMixin(FASTElement) {
1169
+ @observable resource = '';
1170
+
1171
+ async connectedCallback(): Promise<void> {
1172
+ super.connectedCallback();
1173
+ console.log("shouldRunConnect: " + this.shouldRunConnect)
1174
+ if (this.shouldRunConnect) {
1175
+ await this.init();
1176
+ }
1177
+ await otherSetup(this.shouldRunConnect);
1178
+ }
1179
+
1180
+ // Simulate doing work with an external service
1181
+ async init(): Promise<void> { }
1182
+ async otherSetup(connectToResource: boolean): Promise<void> {}
1183
+ // Similar setup in disconnectedCallback...
1184
+ }
1185
+ ```
1186
+
1187
+ In this example when you have this item inside of the layout, the functionality will not correctly be gated when you add or remove other items as intended.
1188
+
1189
+ This is because `shouldRunConnect` (and `shouldRunDisconnect`) perform a check to see whether the layout has performed an event which should gate functionality, and reading the value multiple times will incorrectly signal that there hasn't been another lifecycle event upon subsequent reads during the same cycle. The mental model you can use here is thinking of consuming the check when you read the variable.
1190
+
1191
+ Therefore, if you want to use the value multiple times in the `connectedCallback` and `disconnectedCallback` functions you should cache the variable.
1192
+
1193
+ ** You should only read the variables `this.shouldRunConnect` and `this.shouldRunDisconnect` once per `shouldRunConnect` and `shouldRunDisconnect` cycle respectively. **
1194
+
1195
+ ```typescript
1196
+ async connectedCallback(): Promise<void> {
1197
+ super.connectedCallback();
1198
+ if (this.shouldRunConnect) {
1199
+ console.log("shouldRunConnect: " + this.shouldRunConnect)
1200
+ await this.init();
1201
+ await otherSetup(true);
1202
+ } else {
1203
+ await otherSetup(false);
1204
+ }
1205
+ }
1206
+ // or....
1207
+ async connectedCallback(): Promise<void> {
1208
+ super.connectedCallback();
1209
+ const runFullConnect = this.shouldRunConnect;
1210
+ console.log("shouldRunConnect: " + runFullConnect)
1211
+ if (runFullConnect) {
1212
+ await this.init();
1213
+ }
1214
+ await otherSetup(runFullConnect);
1215
+ }
1216
+ ```
1217
+
1218
+ :::danger
1219
+ The same limitation applies if you're checking the variable multiple times due to having a hierarchy of extending classes. Again, you should cache the variable for checking in this case.
1220
+ :::
1221
+
1161
1222
  ## Supplementary information
1162
1223
 
1163
1224
  ### Custom components to handle bindings and event listeners
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-layout",
3
3
  "description": "Genesis Foundation UI App Layout",
4
- "version": "14.77.1-alpha-7248576.0",
4
+ "version": "14.77.1",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/foundation-layout.d.ts",
@@ -24,14 +24,14 @@
24
24
  "test:debug": "genx test --debug"
25
25
  },
26
26
  "devDependencies": {
27
- "@genesislcap/foundation-testing": "14.77.1-alpha-7248576.0",
28
- "@genesislcap/genx": "14.77.1-alpha-7248576.0",
27
+ "@genesislcap/foundation-testing": "14.77.1",
28
+ "@genesislcap/genx": "14.77.1",
29
29
  "rimraf": "^3.0.2"
30
30
  },
31
31
  "dependencies": {
32
- "@genesis-community/golden-layout": "^2.10.0",
33
- "@genesislcap/foundation-comms": "14.77.1-alpha-7248576.0",
34
- "@genesislcap/foundation-utils": "14.77.1-alpha-7248576.0",
32
+ "@genesis-community/golden-layout": "^2.10.1",
33
+ "@genesislcap/foundation-comms": "14.77.1",
34
+ "@genesislcap/foundation-utils": "14.77.1",
35
35
  "@microsoft/fast-components": "^2.21.3",
36
36
  "@microsoft/fast-element": "^1.7.0",
37
37
  "@microsoft/fast-foundation": "^2.33.2",
@@ -46,5 +46,5 @@
46
46
  "access": "public"
47
47
  },
48
48
  "customElements": "dist/custom-elements.json",
49
- "gitHead": "feff0c2dba8bff2b00afe0e4aa3bf1d5d649a7b0"
49
+ "gitHead": "3c3f770e8109ed802bc30409d3cd4d75bacac7bb"
50
50
  }