Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/source/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import globalEnv from '../libs/global_env'
* @param appName app.name
* @param linkInfo linkInfo of current address
*/
function getExistParseCode (
function getExistParseCode(
appName: string,
prefix: string,
linkInfo: LinkSourceInfo,
Expand All @@ -45,7 +45,7 @@ function getExistParseCode (
}

// transfer the attributes on the link to convertStyle
function setConvertStyleAttr (convertStyle: HTMLStyleElement, attrs: AttrsType): void {
function setConvertStyleAttr(convertStyle: HTMLStyleElement, attrs: AttrsType): void {
attrs.forEach((value, key) => {
if (key === 'rel') return
if (key === 'href') key = 'data-origin-href'
Expand All @@ -61,7 +61,7 @@ function setConvertStyleAttr (convertStyle: HTMLStyleElement, attrs: AttrsType):
* @param microAppHead micro-app-head element
* @param isDynamic dynamic insert
*/
export function extractLinkFromHtml (
export function extractLinkFromHtml(
link: HTMLLinkElement,
parent: Node | null,
app: AppInterface,
Expand Down Expand Up @@ -121,7 +121,7 @@ export function extractLinkFromHtml (
* @param app app
* @param microAppHead micro-app-head
*/
export function fetchLinksFromHtml (
export function fetchLinksFromHtml(
wrapElement: HTMLElement,
app: AppInterface,
microAppHead: Element,
Expand All @@ -134,22 +134,27 @@ export function fetchLinksFromHtml (
})

const fiberLinkTasks: fiberTasks = fiberStyleResult ? [] : null

//Keep the execution order of link code consistent with their order in the DOM document.
const eachCallBacks: Array<CallableFunction> = []

promiseStream<string>(fetchLinkPromise, (res: { data: string, index: number }) => {
injectFiberTask(fiberLinkTasks, () => fetchLinkSuccess(
eachCallBacks[res.index] = () => injectFiberTask(fiberLinkTasks, () => fetchLinkSuccess(
styleList[res.index],
res.data,
microAppHead,
app,
))
}, (err: {error: Error, index: number}) => {
}, (err: { error: Error, index: number }) => {
logError(err, app.name)
}, () => {
/**
* 1. If fiberStyleResult exist, fiberLinkTasks must exist
* 2. Download link source while processing style
* 3. Process style first, and then process link
*/
eachCallBacks.forEach((callback) => callback())

if (fiberStyleResult) {
fiberStyleResult.then(() => {
fiberLinkTasks!.push(() => Promise.resolve(app.onLoad({ html: wrapElement })))
Expand All @@ -174,7 +179,7 @@ export function fetchLinksFromHtml (
* @param microAppHead micro-app-head
* @param app app instance
*/
export function fetchLinkSuccess (
export function fetchLinkSuccess(
address: string,
code: string,
microAppHead: Element,
Expand Down Expand Up @@ -229,7 +234,7 @@ export function fetchLinkSuccess (
* @param linkInfo linkInfo in sourceCenter
* @param attrs attrs of link
*/
export function handleConvertStyle (
export function handleConvertStyle(
app: AppInterface,
address: string,
convertStyle: HTMLStyleElement,
Expand Down Expand Up @@ -265,7 +270,7 @@ export function handleConvertStyle (
* @param linkInfo linkInfo
* @param originLink origin link element
*/
export function formatDynamicLink (
export function formatDynamicLink(
address: string,
app: AppInterface,
linkInfo: LinkSourceInfo,
Expand Down