Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 21, 2023
1 parent 29500e8 commit d017cbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@lezer/lr": "^1.0.0",
"@nextjournal/lezer-clojure": "1.0.0",
"squint-cljs": "0.4.57",
"@squint-cljs/macros": "0.1.0",
"w3c-keyname": "^2.2.4"
},
"comments": {
Expand All @@ -35,7 +34,7 @@
"build": "shadow-cljs -A:demo release demo livedoc",
"test": "shadow-cljs -A:dev release ci-test && node out/node-tests.js",
"watch2": "git ls-files | entr yarn test",
"vite:dev": "vite --open -l info --config vite.config.js public/squint",
"vite:dev": "vite --debug hmr --open -l info --config vite.config.js public/squint",
"vite:build": "yarn vite build --config vite.config.js public/squint"
},
"devDependencies": {
Expand All @@ -55,7 +54,8 @@
"react-dom": "^17.0.2",
"rollup-plugin-analyzer": "^4.0.0",
"shadow-cljs": "2.19.5",
"vite": "^4.4.9"
"vite": "^4.4.9",
"@squint-cljs/macros": "0.1.0"
},
"exports": {
".": "./dist/nextjournal/clojure_mode.mjs",
Expand Down
34 changes: 22 additions & 12 deletions public/squint/js/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ let evalCell = (opts) => {
console.log('evalopts', opts.state.doc.toString());
}

function JSONstringify(json) {
json = JSON.stringify(json, function(key, value) {
if (value && typeof value === 'object' && value.constructor != Object) {
return `#object[${value.constructor.name}]`;
} else {
return value;
}
});
return json;
}

let evalCode = async function (code) {
console.log('code', code);
let js = compileString(code, {repl: true,
context: 'return',
"elide-exports": true})
console.log('js', js);
let js = compileString(`(do ${code})`, {repl: true,
context: 'return',
"elide-exports": true})
let result;
try {
result = {value: await eval(`(async function() { ${js} })()`)};
Expand All @@ -45,7 +54,7 @@ let evalCode = async function (code) {
if (result.error) {
document.getElementById("result").innerText = result.ex;
} else {
document.getElementById("result").innerText = JSON.stringify(result.value, null, 2);
document.getElementById("result").innerText = '' + JSONstringify(result.value);
}
}

Expand All @@ -70,7 +79,7 @@ let extensions = [ theme, foldGutter(),
squintExtension({modifier: "Meta"})
];

let state = EditorState.create( {doc: `(comment
export let doc = `(comment
(fizz-buzz 1)
(fizz-buzz 3)
(fizz-buzz 5)
Expand All @@ -83,13 +92,14 @@ let state = EditorState.create( {doc: `(comment
15 "fizzbuzz"
3 "fizz"
5 "buzz"
n))`,
extensions: extensions });
n))` ;

console.log(state.doc.toString());
evalCode(state.doc.toString());
evalCode(doc);

let state = EditorState.create( {doc: doc,
extensions: extensions });

let editorElt = document.querySelector('#editor');
let editor = new EditorView({state: state,
parent: editorElt,
extensions: extensions });
extensions: extensions })

0 comments on commit d017cbf

Please sign in to comment.