diff --git a/src/runtime-compiled.ts b/src/runtime-compiled.ts index a06a6bf..7426bb4 100644 --- a/src/runtime-compiled.ts +++ b/src/runtime-compiled.ts @@ -1,4 +1,6 @@ import { render, hitTest, scrollHitTest } from './ui'; +import { syncToAst, saveDefinitions } from './runtime-js'; +import { definitions } from './compiler'; type UIValue = any; @@ -217,6 +219,28 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) { return; } + if (event._tag === 'DeleteAt') { + const path = event._0; + const name = path[0]; + 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++) { + if (obj === undefined || obj === null) return; + obj = obj[path[i]]; + } + if (obj !== undefined && obj !== null) { + delete obj[path[path.length - 1]]; + } + } + syncToAst(name); + + return; + } + if (event._tag === 'Focus') { setFocus(event._0); return; diff --git a/src/runtime-js.ts b/src/runtime-js.ts index 2734775..ec3ce21 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -160,6 +160,9 @@ export const _rt = { return { _tag: 'Rebind', _0: name, _1: rest, _2: value }; }, + deleteAt: (path: any[]) => { + return { _tag: 'DeleteAt', _0: path }; + }, "undefine!": (name: string) => { delete store[name]; definitions.delete(name);