Skip to content

Commit

Permalink
[lit-next] Minify private lit-element properties, and rename lit-html…
Browse files Browse the repository at this point in the history
… private props to one underscore (lit#1334)

- Mangle all lit-element properties starting with `_`
- Change private lit-html property prefixes from `__` to `_` for consistency with lit-element
  - Includes exclusions for `_value`, `_setValue`, `_$litType$`, and `_$litDirective$`
- Pre-seed the terser name cache with random names for `_createElement`, `_endNode`, and `_startNode` since those will be needed by Steve in lit#1315. We can use this pattern to ensure that any private properties we need to access *across packages* will be consistent, including across versions.

Also some small typing improvements I noticed:
- Add a cast to `UpdatingElement` prototype in lit-element
- Replace an `any` cast in lit-html with a `NodePartInternal` cast
  • Loading branch information
aomarks authored Sep 30, 2020
1 parent 1288289 commit d9ac661
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 138 deletions.
4 changes: 2 additions & 2 deletions packages/lit-element/src/lib/updating-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ export abstract class UpdatingElement extends HTMLElement {
}
this[finalized] = true;
// finalize any superclasses
const superProto = Object.getPrototypeOf(this);
const superProto = Object.getPrototypeOf(this) as typeof UpdatingElement;
superProto.finalize();
this._classProperties = new Map(superProto._classProperties);
this._classProperties = new Map(superProto._classProperties!);
// initialize Map populated in observedAttributes
this._attributeToPropertyMap = new Map();
// make any properties
Expand Down
6 changes: 3 additions & 3 deletions packages/lit-html/src/directives/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RepeatDirective extends Directive {
}
}

__getValuesAndKeys<T>(
private _getValuesAndKeys<T>(
items: Iterable<T>,
keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,
template?: ItemTemplate<T>
Expand Down Expand Up @@ -101,7 +101,7 @@ class RepeatDirective extends Directive {
keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,
template?: ItemTemplate<T>
) {
return this.__getValuesAndKeys(items, keyFnOrTemplate, template).values;
return this._getValuesAndKeys(items, keyFnOrTemplate, template).values;
}

update<T>(
Expand All @@ -115,7 +115,7 @@ class RepeatDirective extends Directive {
// Old part & key lists are retrieved from the last update
// TODO: deal with directive being swapped out?
const oldParts = getPartValue(containerPart) as Array<NodePart | null>;
const {values: newValues, keys: newKeys} = this.__getValuesAndKeys(
const {values: newValues, keys: newKeys} = this._getValuesAndKeys(
items,
keyFnOrTemplate,
template
Expand Down
6 changes: 3 additions & 3 deletions packages/lit-html/src/directives/template-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../lit-html.js';

class TemplateContent extends Directive {
private __previousTemplate?: HTMLTemplateElement;
private _previousTemplate?: HTMLTemplateElement;

constructor(part: PartInfo) {
super();
Expand All @@ -31,10 +31,10 @@ class TemplateContent extends Directive {
}

render(template: HTMLTemplateElement) {
if (this.__previousTemplate === template) {
if (this._previousTemplate === template) {
return noChange;
}
this.__previousTemplate = template;
this._previousTemplate = template;
return document.importNode(template.content, true);
}
}
Expand Down
Loading

0 comments on commit d9ac661

Please sign in to comment.