|
|
|
|
@ -6,6 +6,7 @@ import type { AST } from './ast'
|
|
|
|
|
import { measure } from './ui';
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'cg-definitions';
|
|
|
|
|
const CHANGELOG_KEY = 'cg-changelog';
|
|
|
|
|
|
|
|
|
|
export const store: Record<string, any> = {};
|
|
|
|
|
|
|
|
|
|
@ -170,6 +171,8 @@ export const _rt = {
|
|
|
|
|
if (defs.length > 0) {
|
|
|
|
|
const def = defs[0];
|
|
|
|
|
recompile(def.name, def.body);
|
|
|
|
|
const source = prettyPrint({ kind: 'definition', name: def.name, body: def.body });
|
|
|
|
|
appendChangeLog(def.name, source);
|
|
|
|
|
saveDefinitions();
|
|
|
|
|
return { _tag: 'Defined', _0: def.name };
|
|
|
|
|
}
|
|
|
|
|
@ -306,6 +309,8 @@ function valueToAst(value: any): AST {
|
|
|
|
|
export function syncToAst(name: string) {
|
|
|
|
|
if (definitions.has(name)) {
|
|
|
|
|
definitions.set(name, valueToAst(store[name]));
|
|
|
|
|
const source = prettyPrint({ kind: 'definition', name, body: definitions.get(name)! });
|
|
|
|
|
appendChangeLog(name, source);
|
|
|
|
|
saveDefinitions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -323,3 +328,25 @@ function deepEqual(a: any, b: any): boolean {
|
|
|
|
|
if (keysA.length !== keysB.length) return false;
|
|
|
|
|
return keysA.every(k => deepEqual(a[k], b[k]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function appendChangeLog(name: string, source: string) {
|
|
|
|
|
try {
|
|
|
|
|
const data = localStorage.getItem(CHANGELOG_KEY);
|
|
|
|
|
const log: Array<{ name: string, source: string, timestamp: number }> = data
|
|
|
|
|
? JSON.parse(data)
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
if (log.length > 0 && log[log.length - 1].name === name) {
|
|
|
|
|
log[log.length - 1] = { name, source, timestamp: Date.now() };
|
|
|
|
|
} else {
|
|
|
|
|
log.push({ name, source, timestamp: Date.now() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (log.length > 200) {
|
|
|
|
|
log.splice(0, log.length - 200);
|
|
|
|
|
}
|
|
|
|
|
localStorage.setItem(CHANGELOG_KEY, JSON.stringify(log));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to append changelog:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|