element-vir 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functional-element/directives/assign-with-clean-up.directive.d.ts +17 -0
- package/dist/functional-element/directives/assign-with-clean-up.directive.js +28 -0
- package/dist/functional-element/directives/assign.directive.d.ts +1 -9
- package/dist/functional-element/directives/assign.directive.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PartInfo } from 'lit/directive.js';
|
|
2
|
+
import { PropertyInitMapBase, StaticElementPropertyDescriptor } from '../element-properties';
|
|
3
|
+
import { FunctionalElementInstance } from '../functional-element';
|
|
4
|
+
/**
|
|
5
|
+
* The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
|
|
6
|
+
* the directive call is wrapped in this function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assignWithCleanup<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue'], cleanupCallback: CleanupCallback<typeof propertyDescriptor['initValue']>): import("lit-html/directive").DirectiveResult<{
|
|
9
|
+
new (partInfo: PartInfo): {
|
|
10
|
+
readonly element: FunctionalElementInstance<PropertyInitMapBase>;
|
|
11
|
+
lastValue: unknown;
|
|
12
|
+
render(propName: string, value: unknown, cleanupCallback: CleanupCallback<any>): symbol;
|
|
13
|
+
readonly _$isConnected: boolean;
|
|
14
|
+
update(_part: import("lit-html").Part, props: unknown[]): unknown;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export declare type CleanupCallback<T> = (oldValue: T) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { noChange } from 'lit';
|
|
2
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
3
|
+
import { extractFunctionalElement } from './directive-util';
|
|
4
|
+
/**
|
|
5
|
+
* The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
|
|
6
|
+
* the directive call is wrapped in this function.
|
|
7
|
+
*/
|
|
8
|
+
export function assignWithCleanup(propertyDescriptor, value, cleanupCallback) {
|
|
9
|
+
return assignWithCleanupDirective(propertyDescriptor.propName, value, cleanupCallback);
|
|
10
|
+
}
|
|
11
|
+
const assignWithCleanupDirective = directive(class extends Directive {
|
|
12
|
+
constructor(partInfo) {
|
|
13
|
+
super(partInfo);
|
|
14
|
+
this.element = extractFunctionalElement(partInfo, 'assign');
|
|
15
|
+
}
|
|
16
|
+
render(propName, value, cleanupCallback) {
|
|
17
|
+
if (!(propName in this.element.instanceProps)) {
|
|
18
|
+
throw new Error(`${this.element.tagName} element has no property of name "${propName}"`);
|
|
19
|
+
}
|
|
20
|
+
// reference equality check!
|
|
21
|
+
if (this.lastValue !== value) {
|
|
22
|
+
cleanupCallback(this.lastValue);
|
|
23
|
+
}
|
|
24
|
+
this.element.instanceProps[propName] = value;
|
|
25
|
+
this.lastValue = value;
|
|
26
|
+
return noChange;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { PartInfo } from 'lit/directive.js';
|
|
2
|
-
import { ElementEvent } from '../element-events';
|
|
3
2
|
import { PropertyInitMapBase, StaticElementPropertyDescriptor } from '../element-properties';
|
|
4
3
|
import { FunctionalElementInstance } from '../functional-element';
|
|
5
4
|
/**
|
|
6
|
-
* The directive generics (in
|
|
5
|
+
* The directive generics (in assignDirective) are not strong enough to maintain their values. Thus,
|
|
7
6
|
* the directive call is wrapped in this function.
|
|
8
7
|
*/
|
|
9
8
|
export declare function assign<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue']): import("lit-html/directive").DirectiveResult<{
|
|
10
9
|
new (partInfo: PartInfo): {
|
|
11
10
|
readonly element: FunctionalElementInstance<PropertyInitMapBase>;
|
|
12
|
-
lastListenerMetaData: ListenerMetaData<any> | undefined;
|
|
13
11
|
render(propName: string, value: unknown): symbol;
|
|
14
12
|
readonly _$isConnected: boolean;
|
|
15
13
|
update(_part: import("lit-html").Part, props: unknown[]): unknown;
|
|
16
14
|
};
|
|
17
15
|
}>;
|
|
18
|
-
declare type ListenerMetaData<EventDetail> = {
|
|
19
|
-
eventType: string;
|
|
20
|
-
callback: (event: ElementEvent<string, EventDetail>) => void;
|
|
21
|
-
listener: (event: any) => void;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
@@ -2,7 +2,7 @@ import { noChange } from 'lit';
|
|
|
2
2
|
import { directive, Directive } from 'lit/directive.js';
|
|
3
3
|
import { extractFunctionalElement } from './directive-util';
|
|
4
4
|
/**
|
|
5
|
-
* The directive generics (in
|
|
5
|
+
* The directive generics (in assignDirective) are not strong enough to maintain their values. Thus,
|
|
6
6
|
* the directive call is wrapped in this function.
|
|
7
7
|
*/
|
|
8
8
|
export function assign(propertyDescriptor, value) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './functional-element/define-functional-element';
|
|
2
|
+
export * from './functional-element/directives/assign-with-clean-up.directive';
|
|
2
3
|
export * from './functional-element/directives/assign.directive';
|
|
3
4
|
export * from './functional-element/directives/listen.directive';
|
|
4
5
|
export * from './functional-element/directives/on-dom-created.directive';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './functional-element/define-functional-element';
|
|
2
|
+
export * from './functional-element/directives/assign-with-clean-up.directive';
|
|
2
3
|
export * from './functional-element/directives/assign.directive';
|
|
3
4
|
export * from './functional-element/directives/listen.directive';
|
|
4
5
|
export * from './functional-element/directives/on-dom-created.directive';
|