@salesforcedevs/docs-components 1.3.300-async-fix-alpha3 → 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
|
@@ -23,19 +23,17 @@ export default class AmfTopic extends LightningElement {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
set model(value: TopicModel) {
|
|
26
|
-
const
|
|
26
|
+
const amfNeedsClone =
|
|
27
27
|
!this.amf ||
|
|
28
|
-
(value && this._model && value.amf !== this._model?.amf)
|
|
29
|
-
|
|
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
|
-
|
|
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,56 +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
|
-
worker.terminate();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
worker.onmessage = function (e) {
|
|
150
|
-
worker.terminate();
|
|
151
|
-
if (e.data.success) {
|
|
152
|
-
resolve(e.data.data);
|
|
153
|
-
} else {
|
|
154
|
-
reject(new Error(e.data.error));
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
worker.onerror = function (e) {
|
|
159
|
-
worker.terminate();
|
|
160
|
-
reject(new Error(e.message));
|
|
161
|
-
};
|
|
162
|
-
} else {
|
|
163
|
-
reject(new Error("Your browser doesn't support web workers."));
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|