we have reactivity
This commit is contained in:
parent
accf1fd1dd
commit
84ef946281
5 changed files with 113 additions and 19 deletions
21
src/main.ts
21
src/main.ts
|
|
@ -5,6 +5,9 @@ import { Parser } from './parser'
|
|||
import { runApp } from './runtime';
|
||||
import { builtins } from './builtins';
|
||||
import { CGError } from './error';
|
||||
import { createStore, startTracking, stopTracking, buildDependents } from './store';
|
||||
// import type { Store } from './store'
|
||||
|
||||
|
||||
import stdlibCode from './stdlib.cg?raw';
|
||||
import designTokensCode from './design-tokens.cg?raw';
|
||||
|
|
@ -26,17 +29,27 @@ try {
|
|||
const tokens = tokenize(cgCode);
|
||||
const parser = new Parser(tokens, cgCode);
|
||||
const definitions = parser.parse();
|
||||
// console.log(ast);
|
||||
|
||||
const env: Env = new Map(Object.entries(builtins));
|
||||
const store = createStore();
|
||||
|
||||
for (const def of definitions) {
|
||||
const deps = startTracking(def.name);
|
||||
const value = evaluate(def.body, env, cgCode);
|
||||
stopTracking();
|
||||
|
||||
env.set(def.name, value);
|
||||
|
||||
store.set(def.name, {
|
||||
value,
|
||||
body: def.body,
|
||||
dependencies: deps
|
||||
});
|
||||
}
|
||||
|
||||
const dependents = buildDependents(store);
|
||||
|
||||
const appRecord = env.get('os');
|
||||
console.log("appRecord", appRecord);
|
||||
|
||||
if (!appRecord || appRecord.kind !== 'record')
|
||||
throw new Error('Expected record');
|
||||
|
|
@ -45,10 +58,8 @@ try {
|
|||
const update = appRecord.fields.update;
|
||||
const view = appRecord.fields.view;
|
||||
|
||||
runApp({ init, update, view }, canvas, cgCode, env);
|
||||
runApp({ init, update, view }, canvas, cgCode, env, store, dependents);
|
||||
} catch(error) {
|
||||
console.log('CAUGHT ERROR:', error);
|
||||
console.log('Is CGError??', error instanceof CGError);
|
||||
if (error instanceof CGError) {
|
||||
console.error(error.format());
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue