UNPKG

1.29 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6export const PartType = {
7 ATTRIBUTE: 1,
8 CHILD: 2,
9 PROPERTY: 3,
10 BOOLEAN_ATTRIBUTE: 4,
11 EVENT: 5,
12 ELEMENT: 6,
13};
14/**
15 * Creates a user-facing directive function from a Directive class. This
16 * function has the same parameters as the directive's render() method.
17 */
18export const directive = (c) => (...values) => ({
19 // This property needs to remain unminified.
20 ['_$litDirective$']: c,
21 values,
22});
23/**
24 * Base class for creating custom directives. Users should extend this class,
25 * implement `render` and/or `update`, and then pass their subclass to
26 * `directive`.
27 */
28export class Directive {
29 constructor(_partInfo) { }
30 // See comment in Disconnectable interface for why this is a getter
31 get _$isConnected() {
32 return this._$parent._$isConnected;
33 }
34 /** @internal */
35 _$initialize(part, parent, attributeIndex) {
36 this.__part = part;
37 this._$parent = parent;
38 this.__attributeIndex = attributeIndex;
39 }
40 /** @internal */
41 _$resolve(part, props) {
42 return this.update(part, props);
43 }
44 update(_part, props) {
45 return this.render(...props);
46 }
47}
48//# sourceMappingURL=directive.js.map
\No newline at end of file