Skip to content

Keep presets and callbacks in separate plugin parameters - #109

Open
jodeleeuw wants to merge 1 commit into
mainfrom
fix/callback-params
Open

jodeleeuw wants to merge 1 commit into
mainfrom
fix/callback-params

Conversation

@jodeleeuw

Copy link
Copy Markdown
Member

The role plugin's strategy and the reference game's scoring and prompt each took either a string or a function, and were declared ParameterType.FUNCTION so jsPsych wouldn't call a callback before the trial. As a result, jsPsych warned "A non-function value was provided for the function parameter" whenever a string was passed, including the defaults. The fix separates presets from callbacks, so neither parameter mixes the two.

Changes

role

  • strategy is a STRING: "join_order", "random", or "rotate".
  • A custom (snapshot, ctx) => roleMap moves to the new assign_roles (FUNCTION), which still requires ready.
  • An unknown preset throws an error that points to assign_roles.

reference-game

  • scoring is a STRING: "per_slot" or "all_or_nothing". A custom (assignment, targets) => number moves to the new score_function (FUNCTION).
  • prompt is COMPLEX: an HTML string or { director, matcher }. The role is known before the trial, so a per-role object covers what (role) => html did, and a dynamic () => … still works.

This breaks code that passes a function to strategy, scoring, or prompt. Each plugin has a minor changeset, and the Upgrading guide lists the changes.

Docs and examples

Both READMEs, the role package's docs page, both site reference pages, and the examples' prompt usages are updated.

Testing

  • 827 tests pass. New tests cover the assign_roles guard, the preset check, score_function, and the per-role prompt.
  • The role plugin's test that asserted jsPsych's warning now asserts it's gone.
  • npm run build and the docs build are clean.
  • The reference-game, reference-game-match, and ultimatum examples run in the jsdom smoke harness with no warnings or errors.

🤖 Generated with Claude Code

The role plugin's strategy and the reference game's scoring and prompt
were FUNCTION parameters so jsPsych wouldn't call a callback before the
trial, which made jsPsych warn whenever a string was passed.

- role: strategy takes a preset; a custom rule moves to assign_roles
- reference-game: scoring takes a preset; a custom function moves to
  score_function; prompt takes HTML or { director, matcher }

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant