@salesforcedevs/docs-components 1.3.300-async-fix-alpha2 → 1.3.300-async-fix-alpha4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.3.300-async-fix-alpha2",
3
+ "version": "1.3.300-async-fix-alpha4",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -17,8 +17,7 @@
17
17
  "lodash.orderby": "^4.6.0",
18
18
  "lodash.uniqby": "^4.7.0",
19
19
  "query-string": "^7.1.3",
20
- "sentence-case": "^3.0.4",
21
- "yieldable-json": "^2.0.1"
20
+ "sentence-case": "^3.0.4"
22
21
  },
23
22
  "devDependencies": {
24
23
  "@types/classnames": "^2.2.10",
@@ -23,19 +23,17 @@ export default class AmfTopic extends LightningElement {
23
23
  }
24
24
 
25
25
  set model(value: TopicModel) {
26
- const amfClonePromise =
26
+ const amfNeedsClone =
27
27
  !this.amf ||
28
- (value && this._model && value.amf !== this._model?.amf)
29
- ? clone(value.amf)
30
- : Promise.resolve(this.amf);
31
-
32
- const typeClonePromise =
28
+ (value && this._model && value.amf !== this._model?.amf);
29
+ const typeNeedsClone =
33
30
  !this.type ||
34
- (value && this._model && value.type !== this._model?.type)
35
- ? clone(value.type)
36
- : Promise.resolve(this.type);
31
+ (value && this._model && value.type !== this._model?.type);
37
32
 
38
- Promise.all([amfClonePromise, typeClonePromise])
33
+ this.cloneData(
34
+ amfNeedsClone ? value.amf : this.amf,
35
+ typeNeedsClone ? value.type : this.type
36
+ )
39
37
  .then(([clonedAmf, clonedType]) => {
40
38
  this.amf = clonedAmf;
41
39
  this.type = clonedType;
@@ -47,6 +45,25 @@ export default class AmfTopic extends LightningElement {
47
45
  });
48
46
  }
49
47
 
48
+ async cloneData(
49
+ amf: Json | undefined,
50
+ type: string | undefined
51
+ ): Promise<[Json, string]> {
52
+ const clonedAmf = amf ? await this.clone(amf) : amf;
53
+ const clonedType = type ? await this.clone(type) : type;
54
+ return [clonedAmf, clonedType];
55
+ }
56
+
57
+ async clone(value: any): Promise<any> {
58
+ return new Promise((resolve, reject) => {
59
+ try {
60
+ resolve(JSON.parse(JSON.stringify(value)));
61
+ } catch (error) {
62
+ reject(error);
63
+ }
64
+ });
65
+ }
66
+
50
67
  update(): void {
51
68
  if (!this.model) {
52
69
  throw new Error("Amf TopicModel undefined when trying to update");
@@ -95,7 +112,6 @@ export default class AmfTopic extends LightningElement {
95
112
  const isTabletOrDesktop = window.matchMedia(
96
113
  `(min-width: ${TABLE_SIZE_MATCH})`
97
114
  ).matches;
98
-
99
115
  if (isTabletOrDesktop) {
100
116
  window.scrollTo(0, 0);
101
117
  }
@@ -111,53 +127,3 @@ export default class AmfTopic extends LightningElement {
111
127
  }
112
128
  }
113
129
  }
114
-
115
- /**
116
- * The underlying web components we use from api-console mutate their models we pass in.
117
- * Since LWC makes them Read Only, we need to copy them before passing to the Web Component.
118
- * @param value JSON Serializable object to clone.
119
- * @returns A Promise that resolves with a copy of Value, serialized and parsed via JSON.
120
- */
121
- function clone(value: any): Promise<any> {
122
- return new Promise((resolve, reject) => {
123
- if (window.Worker) {
124
- const workerCode = `
125
- onmessage = function(e) {
126
- try {
127
- const jsonObject = JSON.parse(e.data);
128
- postMessage({ success: true, data: jsonObject });
129
- } catch (error) {
130
- postMessage({ success: false, error: error.message });
131
- }
132
- };
133
- `;
134
-
135
- const blob = new Blob([workerCode], {
136
- type: "application/javascript"
137
- });
138
- const workerURL = URL.createObjectURL(blob);
139
- const worker = new Worker(workerURL);
140
-
141
- try {
142
- const jsonObj = JSON.stringify(value);
143
- worker.postMessage(jsonObj);
144
- } catch (err) {
145
- reject(err);
146
- }
147
-
148
- worker.onmessage = function (e) {
149
- if (e.data.success) {
150
- resolve(e.data.data);
151
- } else {
152
- reject(new Error(e.data.error));
153
- }
154
- };
155
-
156
- worker.onerror = function (e) {
157
- reject(new Error(e.message));
158
- };
159
- } else {
160
- reject(new Error("Your browser doesn't support web workers."));
161
- }
162
- });
163
- }