48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
|
/**
|
||
|
* @license
|
||
|
* Copyright 2017 Google LLC
|
||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||
|
*/
|
||
|
export const PartType = {
|
||
|
ATTRIBUTE: 1,
|
||
|
CHILD: 2,
|
||
|
PROPERTY: 3,
|
||
|
BOOLEAN_ATTRIBUTE: 4,
|
||
|
EVENT: 5,
|
||
|
ELEMENT: 6,
|
||
|
};
|
||
|
/**
|
||
|
* Creates a user-facing directive function from a Directive class. This
|
||
|
* function has the same parameters as the directive's render() method.
|
||
|
*/
|
||
|
export const directive = (c) => (...values) => ({
|
||
|
// This property needs to remain unminified.
|
||
|
['_$litDirective$']: c,
|
||
|
values,
|
||
|
});
|
||
|
/**
|
||
|
* Base class for creating custom directives. Users should extend this class,
|
||
|
* implement `render` and/or `update`, and then pass their subclass to
|
||
|
* `directive`.
|
||
|
*/
|
||
|
export class Directive {
|
||
|
constructor(_partInfo) { }
|
||
|
// See comment in Disconnectable interface for why this is a getter
|
||
|
get _$isConnected() {
|
||
|
return this._$parent._$isConnected;
|
||
|
}
|
||
|
/** @internal */
|
||
|
_$initialize(part, parent, attributeIndex) {
|
||
|
this.__part = part;
|
||
|
this._$parent = parent;
|
||
|
this.__attributeIndex = attributeIndex;
|
||
|
}
|
||
|
/** @internal */
|
||
|
_$resolve(part, props) {
|
||
|
return this.update(part, props);
|
||
|
}
|
||
|
update(_part, props) {
|
||
|
return this.render(...props);
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=directive.js.map
|