diff --git a/README.md b/README.md index 5fb6d1b..ca861e5 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ A dead simple starting point for custom elements. It provides the following functionality: -- Efficient element generation and data binding via an integrated templating engine -- ...or use another engine (e.g., [lit-html](https://lit.dev)) +- Efficient DOM generation and data binding using your preferred [templating engine](./doc/TEMPLATES.md) - Automatic `.property` to `[attribute]` reflection (opt-in) - Automatic `[attribute]` to `.property` synchronization (one-directional, on connected) - Simple and efficient property observation and computation @@ -54,4 +53,4 @@ npm install && npm start Then... * http://localhost:8080 -See [SPEC.md](./SPEC.md) for all the deets. +See [SPEC.md](./doc/SPEC.md) for all the deets. diff --git a/PUBLISHING.md b/doc/PUBLISHING.md similarity index 53% rename from PUBLISHING.md rename to doc/PUBLISHING.md index b8d0458..ab6dcaf 100644 --- a/PUBLISHING.md +++ b/doc/PUBLISHING.md @@ -8,23 +8,21 @@ procedure feels more comfortable. By publishing, the “Publish” GitHub Action workflow will be triggered and if all the tests pass, it’ll publish to all the registries we care about. -Before you start — make sure your on the `main` branch and up to date. E.g., by -running `git checkout main && git pull origin main`. +Before you start — make sure you are on the `main` branch and up to date. +E.g., by running `git checkout main && git pull origin main`. ## Publishing with Manual Prepublish -1. Edit `package.json`, `package-lock.json`, and `deno.json` files to - set the new version. Don’t forget that `package-lock.json` should be edited - in multiple places to account for the self-package’s version (i.e., `""`). - For example, set the `"version"` key to a value of `"1.0.0-rc.57"`. -2. Add / commit those files. By convention, set the message to the new version - (e.g., `git commit --message="1.0.0-rc.57"`). -3. Tag the commit using an annotated tag. By convention, set the name to the new - version _prefixed with a “v”_ and set the message to the new version - (e.g., `git tag --annotate "v1.0.0-rc.57" --message="1.0.0-rc.57"`). -4. Push the new commit / tags by running `git push origin main --follow-tags`. -5. Find [the tag you just pushed](https://github.com/Netflix/x-element/tags) in - the GitHub UI and click the “Create release” option. Add any additional +1. Edit `package.json` and `deno.json` files to set the new version. +2. Run `npm install` to derive `package-lock.json` using the new version. +3. Commit the changed files. Follow the convention for the commit message. + Example: `git commit --message="1.0.0-rc.57"` +4. Tag the commit using an annotated tag. Follow the convention with + version _prefixed with a “v”_ and set the message to the new version. + Example: `git tag --annotate "v1.0.0-rc.57" --message="1.0.0-rc.57"` +5. Push changes and tags using `git push origin main --follow-tags`. +6. Find [the tag you just pushed](https://github.com/Netflix/x-element/tags) + in the GitHub UI and click the “Create release” option. Add any additional release information (including to check the box if it’s a “pre-release”). ## Publishing with Assisted Prepublish (`bump`) @@ -33,6 +31,6 @@ running `git checkout main && git pull origin main`. and provide the version to bump to (e.g., `npm run bump 1.0.0-rc.57`). Note, keywords like `major`, `minor`, `patch`, etc. _are_ supported. 2. Push the new commit / tags by running `git push origin main --follow-tags`. -3. Find [the tag you just pushed](https://github.com/Netflix/x-element/tags) in - the GitHub UI and click the “Create release” option. Add any additional +3. Find [the tag you just pushed](https://github.com/Netflix/x-element/tags) + in the GitHub UI and click the “Create release” option. Add any additional release information (including to check the box if it’s a “pre-release”). diff --git a/SPEC.md b/doc/SPEC.md similarity index 96% rename from SPEC.md rename to doc/SPEC.md index 81ced85..a5f77c4 100644 --- a/SPEC.md +++ b/doc/SPEC.md @@ -34,9 +34,9 @@ And use it in your markup: ## Rendering -XElement has a built-in templating engine to efficiently turn interpolated html markup into DOM nodes. +XElement has a built-in templating engine to efficiently manage DOM generation and data binding using native [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). -It is also possible to integrate third party rendering engines. Here is an example using [lit-html]: [demo/lit-html/base-element.js](./demo/lit-html/base-element.js) +It is also possible to use third party rendering engines. Check out the (template guide)[./doc/TEMPLATES.md] to learn more. ## Properties diff --git a/doc/TEMPLATES.md b/doc/TEMPLATES.md new file mode 100644 index 0000000..5128c41 --- /dev/null +++ b/doc/TEMPLATES.md @@ -0,0 +1,149 @@ +# Templates & DOM + +Because `x-element` has zero dependencies it also ships with an integrated template engine. However + +## Customizing your base class + +Developers can choose to override the default template engine that ships with `x-element` according to their preference. +Following is a working example using [lit-html](https://lit.dev): + +``` +// base-element.js +import XElement from 'https://deno.land/x/element/x-element.js'; +import { html, render as litRender, svg } from 'https://unpkg.com/lit-html@3.1.2/lit-html.js'; +import { repeat } from 'https://unpkg.com/lit-html@3.1.2/directives/repeat.js'; + +export default class BaseElement extends XElement { + static get templateEngine() { + const render = (container, template) => litRender(template, container); + return { render, html, repeat }; + } +} +``` + +Use it in your elements like this: + +``` +// my-custom-element.js +import BaseElement from './base-element.js'; + +class MyCustomElement extends BaseElement { + static get properties() { + return { + items: { + type: Array, + }, + }; + } + + static template(html, { repeat }) { + return ({ items }) => { + return html` +