Skip to content

Commit

Permalink
sampling does not typically create variants (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored Dec 2, 2024
1 parent 049da57 commit 4c99980
Show file tree
Hide file tree
Showing 9 changed files with 4,955 additions and 12,298 deletions.
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export default class Core {

this.updateInfo.componentsToUpdateRenderers.clear();

// evalute itemCreditAchieved so that will be fresh
// evaluate itemCreditAchieved so that will be fresh
// and can detect changes when it is marked stale
await this.document.stateValues.itemCreditAchieved;

Expand Down
21 changes: 17 additions & 4 deletions packages/doenetml-worker/src/components/SamplePrimeNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default class SamplePrimeNumbers extends CompositeComponent {
};

attributes.variantDeterminesSeed = {
createComponentOfType: "boolean",
createPrimitiveOfType: "boolean",
createStateVariable: "variantDeterminesSeed",
defaultValue: false,
defaultPrimitiveValue: false,
public: true,
};

Expand Down Expand Up @@ -358,8 +358,21 @@ export default class SamplePrimeNumbers extends CompositeComponent {
);
}

static determineNumberOfUniqueVariants() {
return { success: false };
static determineNumberOfUniqueVariants({
serializedComponent,
componentInfoObjects,
}) {
let variantDeterminesSeed =
serializedComponent.attributes.variantDeterminesSeed.primitive;

if (variantDeterminesSeed) {
return { success: false };
} else {
return super.determineNumberOfUniqueVariants({
serializedComponent,
componentInfoObjects,
});
}
}

async resample({
Expand Down
16 changes: 13 additions & 3 deletions packages/doenetml-worker/src/components/SampleRandomNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export default class SampleRandomNumbers extends CompositeComponent {
}

attributes.variantDeterminesSeed = {
createComponentOfType: "boolean",
createPrimitiveOfType: "boolean",
createStateVariable: "variantDeterminesSeed",
defaultValue: false,
defaultPrimitiveValue: false,
public: true,
};

Expand Down Expand Up @@ -776,7 +776,17 @@ export default class SampleRandomNumbers extends CompositeComponent {
serializedComponent,
componentInfoObjects,
}) {
return { success: false };
let variantDeterminesSeed =
serializedComponent.attributes.variantDeterminesSeed.primitive;

if (variantDeterminesSeed) {
return { success: false };
} else {
return super.determineNumberOfUniqueVariants({
serializedComponent,
componentInfoObjects,
});
}
}

async resample({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export default class SelectRandomNumbers extends SampleRandomNumbers {
warnings,
};
}

static determineNumberOfUniqueVariants() {
return { success: false };
}
}

delete SelectRandomNumbers.stateVariableToEvaluateAfterReplacements;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { describe, expect, it, vi } from "vitest";
import { createTestCore, returnAllStateVariables } from "../utils/test-core";
import {
movePoint,
updateBooleanInputValue,
updateMathInputValue,
updateTextInputValue,
updateValue,
} from "../utils/actions";
import Core from "../../Core";
import { movePoint, updateMathInputValue } from "../utils/actions";

const Mock = vi.fn();
vi.stubGlobal("postMessage", Mock);
Expand Down
Loading

0 comments on commit 4c99980

Please sign in to comment.