Repository navigation
fix(site): keep an item's value when its type is switched and switched back - #34
Merged
Merged
Conversation
Mearman
force-pushed
the
fix/site-type-switch-keeps-value
branch
from
October 29, 2026 20:26
bc34457 to
d00cc15
Compare
… value Switching an item to another type started from the nearest value of the new type, so true became 1 and text was read as a number by loose parsing. Now only a value of the same type, the decimal text of a number, and exactly the texts true and false are carried; everything else starts the new type's default. Expression literals switched between text, number and true or false follow the same rule. The scalar helpers move into one module.
…d back The form replaced a node with one built from what the new type could carry, so switching a value or an expression to another type and back lost what it was. The editor now remembers, for the loaded model, what each item last held in each type, keyed by the item's path, and gives that back when the item is switched to that type again. This covers the type of a value, the kind of a predicate or expression, a fold's mode, a complex literal's form, a rule's form and a reference key made not to name a dimension. The memory is never part of the model or its JSON. A replaced model starts it empty, and an edit that moves, removes or renames items forgets what was remembered inside them.
…estores the node The chains run on the editor state without drawing the form, so many more are tried for the work one drawn chain costs; the drawn form keeps its cases that name a kind.
…e absent sameJson compares by content whatever the order of an object's keys. putIn replaces the value at a path, or removes or adds the entry of an object that is the last step, so an optional part can be put back as it was.
…kind Switching an item back to a kind it had been in gave the remembered part as it was left, so a child edited in between was lost, such as the first operand of all of edited as the first side of both. The children a kind has places for are now shared by position between its kinds. A child that differs from what the switch produced is an edit, and is put in every remembered kind that has a place for it, with what was remembered of its own items. A child that is only carried or defaulted does not displace what is remembered. Each vocabulary of variants (predicate and expression kinds, a fold's mode, a complex literal's form, a rule's statement) names where its children are, and has its own memory at a place.
The form-drawing tests and the generated switch sequences ran under vitest's default timeout, which a loaded machine exceeds while the work is unchanged. Each now takes its draws or steps times a named budget, as the library's budget tests do.
Mearman
force-pushed
the
fix/site-type-switch-keeps-value
branch
from
October 29, 2026 21:00
17e9cbb to
9721153
Compare
Mearman
marked this pull request as ready for review
October 29, 2026 21:15
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins. |
|
🎉 This PR is included in version 2.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switching a dimension value to a number and back to text lost the text:
linuxcame back as"0". Switching a rule's text literal to a number and back left the text box empty, so the model reported that the rule comparedoswith an empty text. The form built the new node from whatever the new type could carry and dropped the rest, and every other switch it offers did the same: the kind of a predicate or an expression, a fold's mode, a complex literal's form, a rule's form, and a reference key made not to name a dimension.The editor now remembers, for the loaded model, what each item last held in each type, keyed by the item's path, and gives that back when the item is switched to that type again. A switch to a type the item has not been in carries the value across only where nothing is lost: a number as its decimal text, canonical numeric text as the number, and
trueandfalseas text and back. Anything else starts the new type's default, which the old loose conversions (true to 1, any non-zero number to true, text read as a number by loose parsing) did not.The memory is not part of the model or its JSON. A replaced model (example, import, link, gist, saved model, a valid edit in the JSON view) starts it empty, and an edit that moves, removes or renames items forgets what was remembered inside them. An edit that adds at the end or types a value leaves it alone, and renaming a dimension forgets all of it because remembered nodes may name the old one.
The rule for what a switch gives is in the header comment of
site/src/typeMemory.ts. An item's own value (a scalar, an operator, a function name) comes back as it was last held in the variant being switched to. The children a kind has places for are shared by position between its kinds, so a child edited while the item was in another kind is put into every remembered kind that has a place for it, with what was remembered of its own items, and a child that is only carried across or defaulted does not displace what is remembered. Editing the first operand of anall ofas the first side ofbothand switching back gives the edited operand and the other two from memory, and a trip throughnot, which has room for one, still gives the third back.