scripting: use persistent store
This commit is contained in:
parent
3d22e5d614
commit
6441129dc1
|
@ -283,7 +283,7 @@ export class Environment {
|
|||
}
|
||||
return errors;
|
||||
}
|
||||
getLoadableState() {
|
||||
commitLoadableState() {
|
||||
// TODO: visit children?
|
||||
for (let [key, value] of Object.entries(this.obj)) {
|
||||
let loadable = <any>value as io.Loadable;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
import { coerceToArray } from "../../util";
|
||||
import * as io from "./io";
|
||||
|
||||
// sequence counter
|
||||
|
@ -173,3 +172,22 @@ export function toggle(name: string) {
|
|||
this.enabled = !this.enabled;
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
export class ScriptUIShortcut extends InteractionRecord implements ScriptUIType, Interactive {
|
||||
readonly uitype = 'shortcut';
|
||||
$$interact: InteractionRecord;
|
||||
|
||||
constructor(
|
||||
readonly key: string,
|
||||
callback: InteractCallback
|
||||
) {
|
||||
super(null, callback);
|
||||
this.$$interact = this;
|
||||
}
|
||||
}
|
||||
|
||||
export function key(key: string, callback: InteractCallback) {
|
||||
return new ScriptUIShortcut(key, callback);
|
||||
}
|
||||
|
|
|
@ -436,10 +436,23 @@ class UIButtonComponent extends Component<UIComponentProps> {
|
|||
}
|
||||
}
|
||||
|
||||
class UIShortcutComponent extends Component<UIComponentProps> {
|
||||
render(virtualDom, containerNode, replaceNode) {
|
||||
let shortcut = this.props.uiobject as scriptui.ScriptUIShortcut;
|
||||
// TODO: needs to fire on container node
|
||||
return h('div', {
|
||||
onKeyDown: (e: KeyboardEvent) => {
|
||||
sendInteraction(shortcut, 'key', e, { });
|
||||
},
|
||||
}, [ ])
|
||||
}
|
||||
}
|
||||
|
||||
const UI_COMPONENTS = {
|
||||
'slider': UISliderComponent,
|
||||
'select': UISelectComponent,
|
||||
'button': UIButtonComponent,
|
||||
'shortcut': UIShortcutComponent,
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { BuildStep, BuildStepResult, emglobal, store } from "../workermain";
|
||||
import { Environment, RunResult } from "../../common/script/env";
|
||||
import * as io from "../../common/script/lib/io";
|
||||
import { createNewPersistentStore } from "../../ide/project";
|
||||
|
||||
// cache environments
|
||||
var environments: { [path: string]: Environment } = {};
|
||||
|
@ -18,13 +19,23 @@ function getEnv(path: string): Environment {
|
|||
export async function runJavascript(step: BuildStep): Promise<BuildStepResult> {
|
||||
var env = getEnv(step.path);
|
||||
var code = store.getFileAsString(step.path);
|
||||
var lstore = createNewPersistentStore(step.platform + "//items");
|
||||
// load items from persistent storage (TODO)
|
||||
const itemskey = step.path;
|
||||
if (store.items == null) {
|
||||
store.items = (await lstore.getItem(itemskey)) || {}; // TODO
|
||||
console.log(store.items);
|
||||
}
|
||||
io.$$setupFS(store);
|
||||
io.$$loadData(store.items);
|
||||
try {
|
||||
io.$$setupFS(store);
|
||||
io.$$loadData(store.items); // TODO: load from file
|
||||
await env.run(code);
|
||||
let cells = env.render();
|
||||
let state = env.getLoadableState(); // TODO: doesn't work
|
||||
let state = env.commitLoadableState(); // TODO: doesn't work
|
||||
let output : RunResult = { cells, state };
|
||||
// save items to persistent storage (TODO)
|
||||
lstore.setItem(itemskey, state); // TODO
|
||||
store.items = state; // TODO: why????
|
||||
return { output: output };
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
|
@ -397,7 +397,7 @@ export interface BuildStep extends WorkerBuildStep {
|
|||
export class FileWorkingStore implements WorkingStore {
|
||||
workfs : {[path:string]:FileEntry} = {};
|
||||
workerseq : number = 0;
|
||||
items : {} = {};
|
||||
items : {};
|
||||
|
||||
constructor() {
|
||||
this.reset();
|
||||
|
|
Loading…
Reference in New Issue