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

Additional updates for “2.x” release. #213

Merged
merged 1 commit into from
Dec 5, 2024
Merged

Conversation

theengineear
Copy link
Collaborator

@theengineear theengineear commented Nov 19, 2024

Additional updates for “2.x” release.

Changes:

  • Deprecate unsafeHTML and usafeSVG.
  • Allow binding DocumentFragment as a value.
  • Tag every line in the “CHANGELOG.md” with an issue ticket.
  • Simplified formatting related to bindings in “TEMPLATES.md”.
  • Emit deprecation warnings for soon-to-be-gone interfaces.
  • Deprecate remaining updaters (e.g., “map”).
  • Ditch unecessary “weak maps”.†
  • Some performance improvements.

† The search set for the weak maps we’re using gets untenable since it’s
a flat list of pointers for all results. It feels like a reasonable
concession to hang data off of a unique symbol key. These are
non-enumerable (unless specifically trying to enumerate symbols),
which feels internal enough. Additionally, returning the values passed
in by the user doesn’t feel like much of a leaking abstraction.

| -- | -- | `el.removeAttribute('foo'); // if “bar” is nullish` |
| property | `<div .foo="${bar}"></div>` | `el.foo = bar;` |
| content | `<div>${foo}</div>` | `el.append(document.createTextNode(foo)) // if “bar” is text` |
| -- | -- | (see [content binding](#content-binding) for composition) |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made the table a bit more wide so that the emulation code is proximal to the template code.

@@ -564,7 +564,7 @@ describe('html updaters', () => {

it('unsafe html', () => {
const getTemplate = ({ content }) => {
return html`<div id="target">${unsafe(content, 'html')}</div>`;
return html`<div id="target">${unsafe(content)}</div>`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The unsafe updater gets much more simple.

@@ -1476,28 +1451,10 @@ describe('rendering errors', () => {


describe('unsafe', () => {
it('throws if used on an unexpected language', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don’t support unsafe svg for now. We may choose to add this back in the future in some backwards-compatible way.

@theengineear
Copy link
Collaborator Author

FYI — @klebba.

x-element.js Outdated
// the template “strings” before, we also have to generate html, parse it,
// and find out binding targets. Then, we commit the values by iterating over
// our targets. Finally, we actually attach our new DOM into our node.
static #inject(result, node, before) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@klebba — Did some refactoring / renaming here since you called it out as confusing when you were looking things over yesterday. Hope it helps!

x-element.js Outdated
TemplateEngine.#ready(result);
TemplateEngine.#commit(result);
TemplateEngine.#inject(result, node, { before: true });
TemplateEngine.#inject(result, node, true);
Copy link
Collaborator Author

@theengineear theengineear Nov 19, 2024

Choose a reason for hiding this comment

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

The ready + commit + inject methods are collapsed into a single inject method now.

x-element.js Outdated
state.result = result;
} else {
TemplateEngine.#assign(state.result, result);
TemplateEngine.#commit(state.result);
TemplateEngine.#update(state.result, result);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The assign + commit methods are collapsed into a single update method now.

@theengineear theengineear changed the title Restrict “unsafe” usage for initial “2.x” release. Additional updates for “2.x” release. Nov 20, 2024
@theengineear theengineear force-pushed the ready-2x-interface branch 4 times, most recently from 9b6a42a to f8bc37d Compare November 23, 2024 05:07
Changes:
* Deprecate `unsafeHTML` and `usafeSVG`.
* Allow binding `DocumentFragment` as a value.
* Tag every line in the “CHANGELOG.md” with an issue ticket.
* Simplified formatting related to bindings in “TEMPLATES.md”.
* Emit deprecation warnings for soon-to-be-gone interfaces.
* Deprecate remaining updaters (e.g., “map”).
* Ditch unecessary “weak maps”.†
* Some performance improvements.

† The search set for the weak maps we’re using gets untenable since it’s
  a flat list of pointers for _all_ results. It feels like a reasonable
  concession to hang data off of a unique symbol key. These are
  non-enumerable (unless specifically trying to enumerate symbols),
  which feels internal enough. Additionally, returning the values passed
  in by the user doesn’t feel like much of a leaking abstraction.
@theengineear theengineear merged commit f739937 into main Dec 5, 2024
1 check passed
@theengineear theengineear deleted the ready-2x-interface branch December 5, 2024 03:36
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.

1 participant