Ability to delete from store
This commit is contained in:
parent
3267d5bc39
commit
15f6124173
2 changed files with 27 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue