fix: actually load code from url
This commit is contained in:
parent
125eece223
commit
300a1bbfd5
1 changed files with 12 additions and 10 deletions
|
|
@ -15,22 +15,24 @@ import { persistentAtom } from '@nanostores/persistent';
|
||||||
import { DoughRepl } from './dough-repl.mjs';
|
import { DoughRepl } from './dough-repl.mjs';
|
||||||
|
|
||||||
let initialCode = '$: note("c a f e")';
|
let initialCode = '$: note("c a f e")';
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
try {
|
|
||||||
const codeParam = window.location.href.split('#')[1] || '';
|
|
||||||
if (codeParam) {
|
|
||||||
initialCode = hash2code(codeParam);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('could not init code from url');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const code = persistentAtom('vanilla-repl-code', initialCode, {
|
export const code = persistentAtom('vanilla-repl-code', initialCode, {
|
||||||
encode: JSON.stringify,
|
encode: JSON.stringify,
|
||||||
decode: JSON.parse,
|
decode: JSON.parse,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
try {
|
||||||
|
const codeParam = window.location.href.split('#')[1] || '';
|
||||||
|
if (codeParam) {
|
||||||
|
const codeFromHash = hash2code(codeParam);
|
||||||
|
code.set(codeFromHash);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('could not init code from url');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DoughMirror {
|
export class DoughMirror {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const { root, initialCode = code.get(), bgFill = true } = options;
|
const { root, initialCode = code.get(), bgFill = true } = options;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue