MCPcopy
hub / github.com/alibaba/lowcode-engine / applyUrl

Method applyUrl

packages/utils/src/asset.ts:139–169  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

137 }
138
139 applyUrl(url: string) {
140 if (this.lastUrl === url) {
141 return;
142 }
143 this.lastContent = undefined;
144 this.lastUrl = url;
145 const element = document.createElement('link');
146 element.onload = onload;
147 element.onerror = onload;
148
149 const i = createDefer();
150 function onload(e: any) {
151 element.onload = null;
152 element.onerror = null;
153 if (e.type === 'load') {
154 i.resolve();
155 } else {
156 i.reject();
157 }
158 }
159
160 element.href = url;
161 element.rel = 'stylesheet';
162 if (this.id) {
163 element.setAttribute('data-id', this.id);
164 }
165 document.head.insertBefore(element, this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null);
166 document.head.removeChild(this.placeholder);
167 this.placeholder = element;
168 return i.promise();
169 }
170}
171
172function parseAssetList(scripts: any, styles: any, assets: AssetList, level?: AssetLevel) {

Callers 1

loadStyleMethod · 0.80

Calls 5

createDeferFunction · 0.90
removeChildMethod · 0.80
promiseMethod · 0.80
insertBeforeMethod · 0.65
createElementMethod · 0.45

Tested by

no test coverage detected