-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: remove binding.expression
#12530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: b445acd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
binding.expressionbinding.expression and binding.mutation
|
Marked this ready for review. Right now it probably looks like a step backwards from a certain angle, but this is a first step towards making all this stuff a lot more flexible and robust — I anticipate that the |
binding.expression and binding.mutationbinding.expression
trueadm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
hal-fixing-lightbulb.gif
This started out with #12511. As mentioned in that PR, I'd like to move more of the each block optimisation to compile time, if possible. My first step was to get rid of
$.unwrap(i)in cases like this...{#each things as thing, i} <p>{i}: {thing.name}</p> {/each}$.each(node, 1, () => things, $.index, ($$anchor, thing, i) => { var p = root_1(); var text = $.child(p); $.reset(p); - $.template_effect(() => $.set_text(text, `${$.unwrap(i) ?? ""}: ${$.unwrap(thing).name ?? ""}`)); + $.template_effect(() => $.set_text(text, `${i}: ${$.unwrap(thing).name ?? ""}`)); $.append($$anchor, p); });...because it's a bit daft to call
$.unwrapwhen we know perfectly well thatiis a) not a signal, and b) defined, making the?? ""pointless. (Also,unwraprelies on brittle duck typing and should be removed.)But it wasn't that simple, because in some contexts the index might be wrapped in a source, and in others (i.e. the key function) not. Which made me happy because there's a part of our codebase that I've wanted to get rid of for a long time, and I finally have a good reason:
binding.expression.Essentially, we assign an
expressionto certain bindings when we have specific transformation requirements. But it's not really in keeping with how the rest of the compiler works — ideally, transformation would be pure, and all the mutatey stuff would happen during the analysis phase. (Imagine a world in which it's possible to generate server and client output from a single compiler run, rather than the current — wasteful — process of parsing and analysing from scratch before handing the result off to the transformation phase. While that's not a near term goal, reducing the number of places where mutation can happen in order to make code more understandable and robust is always a goal.)And we have a perfectly good mechanism already —
context.state. This PR adds agettersrecord toTransformStatethat allows nodes to create those ad hoc overrides without mutating the bindings themselves. This should make it much easier to fix theithing above, and no doubt other things too.Right now it only uses
gettersin one place, hence draft status.needs to have an equivalentwill do this in a follow-upsettersrecord to replacebinding.mutationBefore submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.Tests and linting
pnpm testand lint the project withpnpm lint