* origin/develop: Fix browserlist base branch build: update Browserslist db Move browserlist update to cron Update Browserslist Update snapshots Fix Preset Update Browserslist chore(deps): update all non-major dependencies chore(deps): update all non-major dependencies chore: Cleanup with eslint-unicorn Fix tests Fix tests Update loadSite.spec.ts Update snapshots.js Also changed 'graph' to 'flowchart' on state.ts Replacing "chart" with "flowchart"
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { initURLSubscription, loadState, updateCodeStore } from './state';
|
|
import { analytics, initAnalytics } from './stats';
|
|
import { loadDataFromUrl } from './fileLoaders/loader';
|
|
import { initLoading } from './loading';
|
|
import { applyMigrations } from './migrations';
|
|
|
|
export const loadStateFromURL = (): void => {
|
|
loadState(window.location.hash.slice(1));
|
|
};
|
|
|
|
export const syncDiagram = (): void => {
|
|
updateCodeStore({
|
|
updateDiagram: true
|
|
});
|
|
};
|
|
|
|
export const initHandler = async (): Promise<void> => {
|
|
applyMigrations();
|
|
loadStateFromURL();
|
|
await initLoading('Loading Gist...', loadDataFromUrl().catch(console.error));
|
|
syncDiagram();
|
|
initURLSubscription();
|
|
await initAnalytics();
|
|
await analytics?.page();
|
|
};
|
|
|
|
export const isMac = navigator.platform.toUpperCase().includes('MAC');
|
|
export const cmdKey = isMac ? 'Cmd' : 'Ctrl';
|
|
|
|
let count = 0;
|
|
export const errorDebug = (limit = 100) => {
|
|
count += 1;
|
|
if (count > limit) {
|
|
console.log(count, limit);
|
|
// eslint-disable-next-line no-debugger
|
|
debugger;
|
|
}
|
|
};
|
|
|
|
export const formatJSON = (data: unknown): string => JSON.stringify(data, undefined, 2);
|
|
export const fetchJSON = async <T>(url: string): Promise<T> => {
|
|
const res = await fetch(url);
|
|
return res.json() as T;
|
|
};
|
|
export const fetchText = async (url: string): Promise<string> => {
|
|
const res = await fetch(url);
|
|
return res.text();
|
|
};
|