Skip to content

Commit

Permalink
Merge pull request #49 from invopop/state_events
Browse files Browse the repository at this point in the history
fix loading initial data when its envelope
  • Loading branch information
beliolfa authored Sep 1, 2023
2 parents fbbc70b + af6e9ca commit 06ac04f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/GOBLBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@
$: {
try {
const editorValue = $editor ? hash(JSON.parse($editor)) : "";
if (editorValue !== initialEditorData) {
state = "modified";
} else {
state = $editor ? "loaded" : "empty";
}
setState(editorValue);
} catch (error) {
// Allow invalid json entered
state = "invalid";
Expand All @@ -75,16 +71,18 @@
if (data != "") {
parsedValue = JSON.parse(data);
}
if (data != "" && isEnvelope(parsedValue)) {
$envelope = parsedValue;
initialEditorData = hash(parsedValue.doc);
} else {
$envelope = newEnvelope(parsedValue);
initialEditorData = hash(parsedValue || "");
}
initialEditorData = parsedValue ? hash(parsedValue) : "";
state = $envelope?.sigs ? "signed" : "loaded";
} catch (e) {
console.error("invalid document data: ");
console.error("invalid document data: ", e);
$envelope = newEnvelope(null);
state = "empty";
}
Expand All @@ -104,6 +102,20 @@
}));
});
const setState = (editorValue: string) => {
if (!editorValue) {
state = "empty";
return;
}
if (editorValue !== initialEditorData) {
state = "modified";
return;
}
state = "loaded";
};
// Exposed functions to perform the actions from outside
export const build = async () => {
const result = await actions.build();
Expand Down

0 comments on commit 06ac04f

Please sign in to comment.