Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
148 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as resolve } from "./resolve.js"; | ||
export { default as set } from "./set.js"; | ||
export { default as transition } from "./transition.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import resolveTemplateValue from "../resolvers/value.js"; | ||
|
||
const promiseMap = new WeakMap(); | ||
export default function resolve(promise, placeholder, delay = 200) { | ||
return function fn(host, target) { | ||
const useLayout = fn.useLayout; | ||
let timeout; | ||
|
||
if (placeholder) { | ||
timeout = setTimeout(() => { | ||
timeout = undefined; | ||
resolveTemplateValue(host, target, placeholder, undefined, useLayout); | ||
}, delay); | ||
} | ||
|
||
promiseMap.set(target, promise); | ||
|
||
promise.then((value) => { | ||
if (timeout) clearTimeout(timeout); | ||
|
||
if (promiseMap.get(target) === promise) { | ||
resolveTemplateValue( | ||
host, | ||
target, | ||
value, | ||
placeholder && !timeout ? placeholder : undefined, | ||
useLayout, | ||
); | ||
promiseMap.set(target, null); | ||
} | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import global from "../../global.js"; | ||
import { deferred, stringifyElement } from "../../utils.js"; | ||
|
||
const isSupported = global.document.startViewTransition !== undefined; | ||
|
||
let instance; | ||
export default function transition(template) { | ||
// istanbul ignore next | ||
if (!isSupported) return template; | ||
|
||
return function fn(host, target) { | ||
if (instance) { | ||
console.warn( | ||
`${stringifyElement( | ||
host, | ||
)}: view transition already started in ${stringifyElement(instance)}`, | ||
); | ||
template(host, target); | ||
return; | ||
} | ||
|
||
template.useLayout = fn.useLayout; | ||
instance = host; | ||
|
||
global.document.startViewTransition(() => { | ||
template(host, target); | ||
|
||
return deferred.then(() => { | ||
instance = undefined; | ||
}); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters