Sha256: e84188e1738c0ec8f2e76cafa46011772a5b47437676a1fadfa8694e265f9f0c
Contents?: true
Size: 1.46 KB
Versions: 14
Compression:
Stored size: 1.46 KB
Contents
class HotReload { static reloadMode = () => { const namespace = window.__SHOPIFY_CLI_ENV__; return namespace.mode; }; static isFullPageReloadMode = () => { return HotReload.reloadMode() === "full-page"; }; static isReloadModeActive = () => { return HotReload.reloadMode() !== "off"; }; static setHotReloadCookie = (files) => { const date = new Date(); // Hot reload cookie expires in 3 seconds date.setSeconds(date.getSeconds() + 3); const sections = files.join(","); const expires = date.toUTCString(); document.cookie = `hot_reload_files=${sections}; expires=${expires}; path=/`; }; static refreshPage = (files) => { HotReload.setHotReloadCookie(files); console.log("[HotReload] Refreshing entire page"); window.location.reload(); }; static isCSSFile = (filename) => { return filename.endsWith(".css"); }; static reloadCssFile = (filename) => { // Find a stylesheet link starting with /assets (locally-served only) containing the filename let links = document.querySelectorAll( `link[href^="/assets"][href*="${filename}"][rel="stylesheet"]` ); Array.from(links).forEach((link) => { if (!link) { console.log( `[HotReload] Could not find link for stylesheet ${filename}` ); } else { link.href = new URL(link.href).pathname + `?v=${Date.now()}`; console.log(`[HotReload] Reloaded stylesheet ${filename}`); } }); }; }
Version data entries
14 entries across 14 versions & 1 rubygems