Skip to content
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

Multi-spread #1289

Merged
merged 16 commits into from
Apr 1, 2018
Merged

Multi-spread #1289

merged 16 commits into from
Apr 1, 2018

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Mar 30, 2018

Very incomplete, but I think this is a solid direction to go in. It solves #195 in a way that aligns with people's expectations from React (multiple spread properties can exist on an element or component, interspersed with named attributes/properties) but preserves Svelte's mechanism for avoiding unnecessary work even when dealing with grubby mutable data, and it doesn't break the bank in terms of generated code.

TODO:

  • SSR
  • component properties (is just elements for now)
  • lots some more tests
  • optimisations — e.g. no need to recreate { "data-foo": "static" } in the update block when we can just reuse the previous object, like div_spread_levels[1]. We could also possibly optimise the case where there is just one spread prop, or one spread prop followed by a bunch of static props. Doesn't have to be in this PR though

Something else we might want to consider is whether to set properties instead of attributes where applicable (e.g. button.disabled = false will work; button.setAttribute("disabled", "false") will not). I think it can be done just by testing for the existence of the property on the element...

if (name in node) node[name] = value;
else node.setAttribute(name, value);

...though would have to test that. (I think we're ok viz class -> className etc; I believe all the attributes that fall into that category are string attributes, so they should be ok. Again, need to test/check.) Also, things like option.__value might warrant special treatment.

Will finish this PR off soon when I get time.

@codecov-io
Copy link

codecov-io commented Mar 31, 2018

Codecov Report

Merging #1289 into master will decrease coverage by 0.01%.
The diff coverage is 91.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1289      +/-   ##
==========================================
- Coverage   91.65%   91.64%   -0.02%     
==========================================
  Files         122      124       +2     
  Lines        4328     4752     +424     
  Branches     1364     1557     +193     
==========================================
+ Hits         3967     4355     +388     
- Misses        148      166      +18     
- Partials      213      231      +18
Impacted Files Coverage Δ
src/generators/nodes/index.ts 100% <ø> (ø) ⬆️
src/generators/nodes/Attribute.ts 84.74% <100%> (ø) ⬆️
src/parse/state/tag.ts 96.29% <100%> (+0.16%) ⬆️
src/utils/quoteIfNecessary.ts 100% <100%> (ø)
src/generators/server-side-rendering/index.ts 93.93% <100%> (+0.09%) ⬆️
src/generators/Generator.ts 94.33% <100%> (+0.4%) ⬆️
src/validate/html/a11y.ts 91.95% <100%> (+0.09%) ⬆️
...nerators/server-side-rendering/visitors/Element.ts 76% <67.85%> (-14.91%) ⬇️
src/generators/nodes/Element.ts 94.13% <88.46%> (-1.03%) ⬇️
src/generators/nodes/shared/mungeAttribute.ts 92.3% <92.3%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78f506a...7c47cc1. Read the comment docs.

@Rich-Harris Rich-Harris changed the title [WIP] Multi-spread Multi-spread Mar 31, 2018
@Rich-Harris
Copy link
Member Author

Taking the WIP off this, if anyone wants to take a look. Rather than anticipating all the possible failure modes, my inclination is to get this into people's hands soon so that we can mop up any bugs.

The above-mentioned optimisations can go into a follow-up PR

@Rich-Harris
Copy link
Member Author

(Worth a mention: the codebase badly needs to be refactored, particularly all the stuff around contextualise; in its current state, adding this feature was more trouble than it should have been. Soon...)

@Rich-Harris Rich-Harris merged commit f27b29d into master Apr 1, 2018
@Rich-Harris Rich-Harris deleted the gh-195 branch April 1, 2018 20:41
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.

3 participants