@salesforcedevs/docs-components
Advanced tools
Comparing version 1.3.300-async-fix-alpha3 to 1.3.300-async-fix-alpha4
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "1.3.300-async-fix-alpha3", | ||
"version": "1.3.300-async-fix-alpha4", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,15 +26,13 @@ import { LightningElement, api } from "lwc"; | ||
set model(value: TopicModel) { | ||
const amfClonePromise = | ||
const amfNeedsClone = | ||
!this.amf || | ||
(value && this._model && value.amf !== this._model?.amf) | ||
? clone(value.amf) | ||
: Promise.resolve(this.amf); | ||
const typeClonePromise = | ||
(value && this._model && value.amf !== this._model?.amf); | ||
const typeNeedsClone = | ||
!this.type || | ||
(value && this._model && value.type !== this._model?.type) | ||
? clone(value.type) | ||
: Promise.resolve(this.type); | ||
(value && this._model && value.type !== this._model?.type); | ||
Promise.all([amfClonePromise, typeClonePromise]) | ||
this.cloneData( | ||
amfNeedsClone ? value.amf : this.amf, | ||
typeNeedsClone ? value.type : this.type | ||
) | ||
.then(([clonedAmf, clonedType]) => { | ||
@@ -51,2 +49,21 @@ this.amf = clonedAmf; | ||
async cloneData( | ||
amf: Json | undefined, | ||
type: string | undefined | ||
): Promise<[Json, string]> { | ||
const clonedAmf = amf ? await this.clone(amf) : amf; | ||
const clonedType = type ? await this.clone(type) : type; | ||
return [clonedAmf, clonedType]; | ||
} | ||
async clone(value: any): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
resolve(JSON.parse(JSON.stringify(value))); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
update(): void { | ||
@@ -100,3 +117,2 @@ if (!this.model) { | ||
).matches; | ||
if (isTabletOrDesktop) { | ||
@@ -117,54 +133,1 @@ window.scrollTo(0, 0); | ||
} | ||
/** | ||
* The underlying web components we use from api-console mutate their models we pass in. | ||
* Since LWC makes them Read Only, we need to copy them before passing to the Web Component. | ||
* @param value JSON Serializable object to clone. | ||
* @returns A Promise that resolves with a copy of Value, serialized and parsed via JSON. | ||
*/ | ||
function clone(value: any): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (window.Worker) { | ||
const workerCode = ` | ||
onmessage = function(e) { | ||
try { | ||
const jsonObject = JSON.parse(e.data); | ||
postMessage({ success: true, data: jsonObject }); | ||
} catch (error) { | ||
postMessage({ success: false, error: error.message }); | ||
} | ||
}; | ||
`; | ||
const blob = new Blob([workerCode], { | ||
type: "application/javascript" | ||
}); | ||
const workerURL = URL.createObjectURL(blob); | ||
const worker = new Worker(workerURL); | ||
try { | ||
const jsonObj = JSON.stringify(value); | ||
worker.postMessage(jsonObj); | ||
} catch (err) { | ||
reject(err); | ||
worker.terminate(); | ||
} | ||
worker.onmessage = function (e) { | ||
worker.terminate(); | ||
if (e.data.success) { | ||
resolve(e.data.data); | ||
} else { | ||
reject(new Error(e.data.error)); | ||
} | ||
}; | ||
worker.onerror = function (e) { | ||
worker.terminate(); | ||
reject(new Error(e.message)); | ||
}; | ||
} else { | ||
reject(new Error("Your browser doesn't support web workers.")); | ||
} | ||
}); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254860
6541