No longer saving to localStorage. ignoring cg files so vite doesn't reload the page every time i save state
This commit is contained in:
parent
e0cd7f2bae
commit
0bab0b88f3
4 changed files with 7 additions and 38 deletions
|
|
@ -2,7 +2,7 @@ import { compileAndRun } from './compiler'
|
|||
import { tokenize } from './lexer'
|
||||
import { Parser } from './parser'
|
||||
import { runAppCompiled } from './runtime-compiled'
|
||||
import { _rt, store, loadDefinitions, saveDefinitions } from './runtime-js'
|
||||
import { _rt, store } from './runtime-js'
|
||||
|
||||
const modules = import.meta.glob('./cg/*.cg', { query: 'raw', import: 'default', eager: true });
|
||||
const cgCode = Object.keys(modules)
|
||||
|
|
@ -24,13 +24,11 @@ try {
|
|||
const tokens = tokenize(cgCode);
|
||||
const parser = new Parser(tokens, cgCode);
|
||||
const { definitions: defs, typeDefinitions: typeDefs, classDefinitions: classDefs, instanceDeclarations: instances } = parser.parse();
|
||||
loadDefinitions();
|
||||
|
||||
// TODO remove once we're booting from store, files are backup
|
||||
if (!store.paletteHistory) store.paletteHistory = [];
|
||||
|
||||
compileAndRun(defs, typeDefs, classDefs, instances);
|
||||
saveDefinitions();
|
||||
|
||||
runAppCompiled(canvas, store);
|
||||
} catch(error) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { render, hitTest, scrollHitTest } from './ui';
|
||||
import { syncToAst, saveDefinitions } from './runtime-js';
|
||||
import { syncToAst } from './runtime-js';
|
||||
import { definitions } from './compiler';
|
||||
|
||||
type UIValue = any;
|
||||
|
|
@ -225,7 +225,6 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) {
|
|||
if (path.length === 1) {
|
||||
delete store[name];
|
||||
definitions.delete(name);
|
||||
saveDefinitions();
|
||||
} else {
|
||||
let obj = store[name];
|
||||
for (let i = 1; i < path.length - 1; i++) {
|
||||
|
|
|
|||
|
|
@ -221,7 +221,6 @@ export const _rt = {
|
|||
definitions.delete(name);
|
||||
dependencies.delete(name);
|
||||
dependents.delete(name);
|
||||
saveDefinitions();
|
||||
return { _tag: 'Ok' };
|
||||
},
|
||||
|
||||
|
|
@ -269,7 +268,6 @@ export const _rt = {
|
|||
definitions.set(def.name, def);
|
||||
const source = prettyPrint(def);
|
||||
appendChangeLog(def.name, source);
|
||||
saveDefinitions();
|
||||
syncToFilesystem(def.name);
|
||||
return { _tag: 'Defined', _0: def.name };
|
||||
}
|
||||
|
|
@ -310,36 +308,6 @@ export const _rt = {
|
|||
}
|
||||
}
|
||||
|
||||
export function saveDefinitions() {
|
||||
const saved: Record<string, string> = {};
|
||||
for (const [name, def] of definitions) {
|
||||
const source = prettyPrint(def);
|
||||
saved[name] = source;
|
||||
}
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(saved));
|
||||
|
||||
}
|
||||
|
||||
export function loadDefinitions() {
|
||||
const data = localStorage.getItem(STORAGE_KEY);
|
||||
if (!data) return;
|
||||
|
||||
try {
|
||||
const saved = JSON.parse(data);
|
||||
for (const [_, source] of Object.entries(saved)) {
|
||||
const tokens = tokenize(source as string);
|
||||
const parser = new Parser(tokens, source as string);
|
||||
const { definitions: defs } = parser.parse();
|
||||
if (defs.length > 0) {
|
||||
recompile(defs[0].name, defs[0].body!);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load definitions:', e);
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
|
||||
function valueToAst(value: any): AST {
|
||||
// Numbers
|
||||
if (typeof value === 'number') {
|
||||
|
|
@ -420,7 +388,6 @@ export function syncToAst(name: string) {
|
|||
// const source = prettyPrint({ kind: 'definition', name, body: definitions.get(name)! });
|
||||
const source = prettyPrint(definitions.get(name)!);
|
||||
appendChangeLog(name, source);
|
||||
saveDefinitions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@ import fs from 'fs'
|
|||
import path from 'path'
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
watch: {
|
||||
ignored: ['**/src/cg/**']
|
||||
}
|
||||
},
|
||||
plugins: [{
|
||||
name: 'cg-save',
|
||||
configureServer(server) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue