You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
939 B
31 lines
939 B
import handleShapeUpdate from "src/ng-mock/wasm-land/handleShapeUpdate";
|
|
import type { Connection, Diff, Scope, Shape } from "../types";
|
|
import handleShapeRequest from "src/ng-mock/wasm-land/handleShapeRequest";
|
|
import { applyDiff } from "./applyDiff";
|
|
|
|
export async function createSignalObjectForShape(shape: Shape, scope?: Scope) {
|
|
const ret: {
|
|
state?: any;
|
|
connectionId?: Connection["id"];
|
|
update: (diff: Diff) => Promise<void>;
|
|
} = {
|
|
async update(diff) {
|
|
if (!ret.connectionId)
|
|
throw new Error("Connection not established yet for shape" + shape);
|
|
await handleShapeUpdate(ret.connectionId, diff);
|
|
},
|
|
};
|
|
|
|
const onDbUpdate = (diff: Diff) => {
|
|
ret.state = applyDiff(ret.state || {}, diff);
|
|
};
|
|
|
|
await handleShapeRequest(shape, onDbUpdate).then(
|
|
({ connectionId, shapeObject }) => {
|
|
ret.state = shapeObject;
|
|
ret.connectionId = connectionId;
|
|
}
|
|
);
|
|
|
|
return ret;
|
|
}
|
|
|