Skip to content

Commit 49e8142

Browse files
committed
BUG: Fix loss of reactivity caused by #682.
1 parent 09b7ca6 commit 49e8142

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

packages/catlog-wasm/src/model.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,12 @@ pub fn collect_product(ob: Ob) -> Result<Vec<Ob>, String> {
487487

488488
/// Elaborates a model defined by a notebook into a catlog model.
489489
#[wasm_bindgen(js_name = "elaborateModel")]
490-
pub fn elaborate_model(doc: &ModelDocumentContent, theory: &DblTheory) -> DblModel {
490+
pub fn elaborate_model(judgments: Vec<ModelJudgment>, theory: &DblTheory) -> DblModel {
491491
let mut model = DblModel::new(theory);
492-
493-
for cell in doc.notebook.cells() {
494-
if let Cell::Formal { id: _, content } = cell {
495-
match content {
496-
ModelJudgment::Object(decl) => model.add_ob(decl).unwrap(),
497-
ModelJudgment::Morphism(decl) => model.add_mor(decl).unwrap(),
498-
}
492+
for judgment in judgments {
493+
match judgment {
494+
ModelJudgment::Object(decl) => model.add_ob(&decl).unwrap(),
495+
ModelJudgment::Morphism(decl) => model.add_mor(&decl).unwrap(),
499496
}
500497
}
501498
model

packages/catlog-wasm/src/model_diagram.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,12 @@ pub struct ModelDiagramValidationResult(
206206

207207
/// Elaborates a diagram defined by a notebook into a catlog diagram.
208208
#[wasm_bindgen(js_name = "elaborateDiagram")]
209-
pub fn elaborate_diagram(doc: &DiagramDocumentContent, theory: &DblTheory) -> DblModelDiagram {
209+
pub fn elaborate_diagram(judgments: Vec<DiagramJudgment>, theory: &DblTheory) -> DblModelDiagram {
210210
let mut diagram = DblModelDiagram::new(theory);
211-
for cell in doc.notebook.cells() {
212-
if let Cell::Formal { id: _, content } = cell {
213-
match content {
214-
DiagramJudgment::Object(decl) => diagram.add_ob(decl).unwrap(),
215-
DiagramJudgment::Morphism(decl) => diagram.add_mor(decl).unwrap(),
216-
}
211+
for judgment in judgments {
212+
match judgment {
213+
DiagramJudgment::Object(decl) => diagram.add_ob(&decl).unwrap(),
214+
DiagramJudgment::Morphism(decl) => diagram.add_mor(&decl).unwrap(),
217215
}
218216
}
219217
diagram

packages/frontend/src/diagram/document.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Accessor, createMemo } from "solid-js";
2-
import { unwrap } from "solid-js/store";
32
import invariant from "tiny-invariant";
43

54
import type {
@@ -103,18 +102,14 @@ function enlivenDiagramDocument(
103102

104103
const validatedDiagram = createMemo<ValidatedDiagram | undefined>(
105104
() => {
106-
// NOTE: Reactively depend on formal judgments but, by `unwrap`-ing,
107-
// not anything else in the document.
108-
formalJudgments();
109-
110105
const th = liveModel.theory();
111106
const validatedModel = liveModel.validatedModel();
112107
if (!(th && validatedModel?.result.tag === "Ok")) {
113-
// Abort immediately if the model itself is invalid.
108+
// Abort immediately if the theory is undefined or the model is invalid.
114109
return undefined;
115110
}
116111
const { model } = validatedModel;
117-
const diagram = elaborateDiagram(unwrap(doc), th.theory);
112+
const diagram = elaborateDiagram(formalJudgments(), th.theory);
118113
diagram.inferMissingFrom(model);
119114
const result = diagram.validateIn(model);
120115
return { diagram, result };

packages/frontend/src/model/document.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Accessor, createMemo, createResource } from "solid-js";
2-
import { unwrap } from "solid-js/store";
32
import invariant from "tiny-invariant";
43

54
import {
@@ -107,13 +106,9 @@ function enlivenModelDocument(
107106

108107
const validatedModel = createMemo<ValidatedModel | undefined>(
109108
() => {
110-
// NOTE: Reactively depend on formal judgments but, by `unwrap`-ing,
111-
// not anything else in the document.
112-
formalJudgments();
113-
114109
const coreTheory = theory()?.theory;
115110
if (coreTheory) {
116-
const model = elaborateModel(unwrap(doc), coreTheory);
111+
const model = elaborateModel(formalJudgments(), coreTheory);
117112
const result = model.validate();
118113
return { model, result };
119114
}
@@ -170,14 +165,12 @@ export async function migrateModelDocument(
170165
targetTheoryId: string,
171166
theories: TheoryLibrary,
172167
) {
173-
const theory = await theories.get(liveDoc.doc.theory);
168+
const doc = liveDoc.doc;
169+
const theory = await theories.get(doc.theory);
174170
const targetTheory = await theories.get(targetTheoryId);
175171

176172
// Trivial migration.
177-
if (
178-
!NotebookUtils.hasFormalCells(liveDoc.doc.notebook) ||
179-
theory.inclusions.includes(targetTheoryId)
180-
) {
173+
if (!NotebookUtils.hasFormalCells(doc.notebook) || theory.inclusions.includes(targetTheoryId)) {
181174
liveDoc.changeDoc((doc) => {
182175
doc.theory = targetTheoryId;
183176
});
@@ -192,7 +185,7 @@ export async function migrateModelDocument(
192185
// TODO: We need a general method to propagate changes from catlog models to
193186
// notebooks. This stop-gap solution only works because pushforward
194187
// migration doesn't have to create/delete cells, only update types.
195-
let model = elaborateModel(liveDoc.doc, theory.theory);
188+
let model = elaborateModel(NotebookUtils.getFormalContent(doc.notebook), theory.theory);
196189
model = migration.migrate(model, targetTheory.theory);
197190
liveDoc.changeDoc((doc) => {
198191
doc.theory = targetTheoryId;

0 commit comments

Comments
 (0)