@salesforcedevs/docs-components
Advanced tools
Comparing version 1.3.300-amf-fix-alpha to 1.3.300-async-fix-alpha2
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "1.3.300-amf-fix-alpha", | ||
"version": "1.3.300-async-fix-alpha2", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -20,3 +20,4 @@ "license": "MIT", | ||
"query-string": "^7.1.3", | ||
"sentence-case": "^3.0.4" | ||
"sentence-case": "^3.0.4", | ||
"yieldable-json": "^2.0.1" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
@@ -12,2 +12,3 @@ import { LightningElement, api } from "lwc"; | ||
import { Json } from "typings/custom"; | ||
const TABLE_SIZE_MATCH = "769px"; | ||
@@ -17,4 +18,4 @@ | ||
private _model: TopicModel | undefined; | ||
private amf: Json; | ||
private type: any; | ||
private amf: Json | undefined; | ||
private type: string | undefined; | ||
@@ -27,68 +28,26 @@ @api | ||
set model(value: TopicModel) { | ||
if ( | ||
const amfClonePromise = | ||
!this.amf || | ||
(value && this._model && value.amf !== this._model?.amf) | ||
) { | ||
this.amf = value && this.clone(value.amf); | ||
} | ||
if ( | ||
? clone(value.amf) | ||
: Promise.resolve(this.amf); | ||
const typeClonePromise = | ||
!this.type || | ||
(value && this._model && value.type !== this._model?.type) | ||
) { | ||
this.type = value && this.getTypeCloned(value.type); | ||
} | ||
? clone(value.type) | ||
: Promise.resolve(this.type); | ||
this._model = value; | ||
if (this._model) { | ||
this.update(); | ||
} | ||
// else { Remove child? No model, seems like no component should be shown. } | ||
Promise.all([amfClonePromise, typeClonePromise]) | ||
.then(([clonedAmf, clonedType]) => { | ||
this.amf = clonedAmf; | ||
this.type = clonedType; | ||
this._model = value; | ||
this.update(); | ||
}) | ||
.catch((error) => { | ||
console.error("Error cloning model:", error); | ||
}); | ||
} | ||
cloneWithWorker(value) { | ||
return new Promise((resolve, reject) => { | ||
const worker = new Worker("./cloneAmfObject.ts"); | ||
worker.onmessage = (event) => { | ||
resolve(event.data); | ||
worker.terminate(); | ||
}; | ||
worker.onerror = (error) => { | ||
reject(error); | ||
worker.terminate(); | ||
}; | ||
worker.postMessage(value); | ||
}); | ||
} | ||
/** | ||
* 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 copy of Value. One that has been serialized and parsed via JSON. (Functions, Regex, etc are not preserved.) | ||
*/ | ||
// function clone(value: any): any { | ||
// return JSON.parse(JSON.stringify(value)); | ||
// } | ||
async clone(value: any) { | ||
try { | ||
const clonedObject = await this.cloneWithWorker(value); | ||
return clonedObject; | ||
} catch (error) { | ||
console.error("Error cloning value:", error); | ||
return null; | ||
} | ||
} | ||
async getTypeCloned(value: any) { | ||
const typeObj = await this.clone(value.type); | ||
if (typeObj) { | ||
return typeObj; | ||
} | ||
return ""; | ||
} | ||
update(): void { | ||
@@ -149,8 +108,60 @@ if (!this.model) { | ||
renderedCallback(): void { | ||
try { | ||
this.update(); | ||
} catch (error) { | ||
console.error(error); | ||
if (this._model) { | ||
try { | ||
this.update(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* 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.onmessage = function (e) { | ||
if (e.data.success) { | ||
resolve(e.data.data); | ||
} else { | ||
reject(new Error(e.data.error)); | ||
} | ||
}; | ||
worker.onerror = function (e) { | ||
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
256123
6570
8
+ Addedyieldable-json@^2.0.1
+ Addedyieldable-json@2.0.1(transitive)