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

New syntax and main module #398

Merged
merged 7 commits into from
Jul 19, 2018
Merged

New syntax and main module #398

merged 7 commits into from
Jul 19, 2018

Conversation

justinfagnani
Copy link
Collaborator

@justinfagnani justinfagnani commented Jul 11, 2018

This PR adds a new syntax that's like lit-extended, but defaults to setting attributes and requires opting-in to setting properties.

Properties are set with a . prefix:

html`<input .value=${value}>`

The new syntax is the main module of the package now. The unopinionated core has been moved to core.js and the new syntax is in lit-html.js

lit-extended is deprecated and will be removed before 1.0.

Fixes #399

@nicolasparada
Copy link

nicolasparada commented Jul 11, 2018

I still think lit-html should try to set properties falling back to attributes without any special syntax. Same behavior as preact.

html`<div className="foo"></div>`

That sets the property.

html`<div class="foo"></div>`

And this sets the attribute.

@Westbrook
Copy link
Contributor

With this change, do you see any issues with adoption when properties are prefixed:

html`<input .value=${value}>`

But the boolean attribute syntax is postfixed:

html`<input checked?=${checked}>`

The new property syntax seems to make sense, but mixed positional syntax seems like it would be harder to coach into other people's workflow.

Looking forward to implementing this in my team's growing collection of lit-element based components.

@justinfagnani
Copy link
Collaborator Author

Let's keep discussion of the options to #399

```

The path to use depends on where you've installed lit-html to. Browsers only support importing other modules by path, not by package name, so without other tools involved, you'll have to use paths.

If you use some tool than can convert package names into paths, then you can import by path:
If you use a tool than converts package names into paths, then you can import by path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: tha{n => t}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -3,7 +3,6 @@

<html>
<head>
<title>Getting Started</title>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the titles are gone, is that on purpose? (I honestly don't know how the documentation works, this just caught my eye)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It's a problem with the generator

Copy link
Member

@sorvell sorvell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits and a general point: the separation of core and lit-html feels a bit arbitrary and duplicative. Why is there an html tag function in core for example? If we really think it's important to maintain this basic "unopinionated" version it should probably still be mentioned in the documentation; however, I'd suggest not bothering with this distinction and removing the extra module and (admittedly small) duplication.

* Property bindings: Any type of value
* Event handler bindings: Event handler functions only
* Text content bindings: TemplateResults, Nodes. Other types converted to strings.
Expressions can occur text content or in attribute value positions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expressions can occur in text content

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lit-html.ts Outdated
* To update a container with new values, reevaluate the template literal and
* call `render` with the new result.
* Attribute names in lit-html templates preserve case, so properties are case
* sensitive. If an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lit-html.ts Outdated
*
* "\0-\x1F\x7F-\x9F" are Unicode control characters
* Event handlers are sset by prefixing an attribute name with `on-`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: sset => set

Change on- to @ right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lit-html.ts Outdated

/**
* A placeholder for a dynamic expression in an HTML template.
* html`<button on-click=${(e)=> this.onClickHandler(e)}>Buy Now</button>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on- to @

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lit-html.ts Outdated
* There are two built-in part types: AttributePart and NodePart. NodeParts
* always represent a single dynamic expression, while AttributeParts may
* represent as many expressions are contained in the attribute.
* Boolean attributes are set by appending `?` to an attribute name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change appending to prepending

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lit-html.ts Outdated
* TODO(justinfagnani): That requirement is a little fragile. A
* TemplateInstance could instead be more careful about which values it gives
* to Part.update().
* html`<input type="checkbox" checked?=${value}>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked? to ?checked

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@justinfagnani
Copy link
Collaborator Author

@sorvell regarding the separation / duplication of core and lit-html: I'm open to merging core back into lit-html (and possibly vending a simple.ts module that just contains a PartCallback implementing an opinionated syntax, mostly for reference). I was intending to document core.ts soon. Can we make the call after this PR?

@justinfagnani
Copy link
Collaborator Author

@sorvell PTAL

Copy link
Member

@sorvell sorvell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geraldfullam
Copy link

Why did you remove so much documentation from the README.md? (See deletions from Lines 61–427).

neuronetio pushed a commit to neuronetio/lit-html that referenced this pull request Dec 2, 2019
* Rename lit-html.ts to core.ts
* Add new lit-html.ts with lit-extended like syntax.
* Update README
* Update docs
* Deprecate lit-extended
* Change event handlers to a @-prefix and boolean attributes to a ?-prefix.
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.

Change attribute/property binding syntax to require opt-in to properties.
6 participants