@fluffjs/fluff 0.1.15 → 0.1.17
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/package.json +1 -1
- package/runtime/FluffBase.js +3 -0
- package/runtime/ForController.js +1 -0
- package/runtime/IfController.js +1 -0
- package/runtime/MarkerController.d.ts +1 -0
- package/runtime/MarkerController.js +12 -0
- package/runtime/SwitchController.js +1 -0
- package/runtime/tests/createPipeUnwrapChildComponent.d.ts +6 -0
- package/runtime/tests/createPipeUnwrapChildComponent.js +10 -0
- package/runtime/tests/createPipeUnwrapParentComponent.d.ts +12 -0
- package/runtime/tests/createPipeUnwrapParentComponent.js +24 -0
- package/runtime/tests/createPipeUnwrapTestComponent.d.ts +12 -0
- package/runtime/tests/createPipeUnwrapTestComponent.js +32 -0
package/package.json
CHANGED
package/runtime/FluffBase.js
CHANGED
|
@@ -76,6 +76,9 @@ export class FluffBase extends HTMLElement {
|
|
|
76
76
|
}
|
|
77
77
|
__applyPipes(value, pipes, locals) {
|
|
78
78
|
let result = value;
|
|
79
|
+
if (result instanceof Property) {
|
|
80
|
+
result = result.getValue();
|
|
81
|
+
}
|
|
79
82
|
for (const pipe of pipes) {
|
|
80
83
|
result = this.__applyPipe(pipe.n, result, pipe.a, locals);
|
|
81
84
|
}
|
package/runtime/ForController.js
CHANGED
package/runtime/IfController.js
CHANGED
|
@@ -38,6 +38,7 @@ export class IfController extends MarkerController {
|
|
|
38
38
|
if (matchedIndex >= 0 && matchedIndex < this.templates.length) {
|
|
39
39
|
this.cloneAndInsertTemplate(this.templates[matchedIndex], this.loopContext, undefined, this.bindingsSubscriptions);
|
|
40
40
|
}
|
|
41
|
+
this.refreshParentBindings();
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
44
|
this.subscribeTo(allDeps, update);
|
|
@@ -37,6 +37,7 @@ export declare abstract class MarkerController {
|
|
|
37
37
|
protected createChildScope(locals: Record<string, unknown>): Scope;
|
|
38
38
|
protected clearContentBetweenMarkersWithCleanup(bindingsSubscriptions: Subscription[]): void;
|
|
39
39
|
protected insertBeforeEndMarker(node: Node): void;
|
|
40
|
+
protected refreshParentBindings(): void;
|
|
40
41
|
protected processBindingsOnElement(el: HTMLElement, scope: Scope): void;
|
|
41
42
|
protected processBindingsOnElementWithSubscriptions(el: HTMLElement, scope: Scope, subscriptions: Subscription[]): void;
|
|
42
43
|
private __getFluffElementHost;
|
|
@@ -227,6 +227,18 @@ export class MarkerController {
|
|
|
227
227
|
return;
|
|
228
228
|
parent.insertBefore(node, this.endMarker);
|
|
229
229
|
}
|
|
230
|
+
refreshParentBindings() {
|
|
231
|
+
const parent = this.startMarker.parentNode;
|
|
232
|
+
if (!(parent instanceof HTMLElement))
|
|
233
|
+
return;
|
|
234
|
+
if (!parent.hasAttribute('data-lid'))
|
|
235
|
+
return;
|
|
236
|
+
const fluffHost = this.__getFluffElementHost();
|
|
237
|
+
if (!fluffHost)
|
|
238
|
+
return;
|
|
239
|
+
const scope = this.getScope();
|
|
240
|
+
fluffHost.__processBindingsOnElementPublic(parent, scope);
|
|
241
|
+
}
|
|
230
242
|
processBindingsOnElement(el, scope) {
|
|
231
243
|
const fluffHost = this.__getFluffElementHost();
|
|
232
244
|
if (!fluffHost)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
2
|
+
export interface PipeUnwrapChildComponentInstance extends FluffElement {
|
|
3
|
+
value: unknown;
|
|
4
|
+
}
|
|
5
|
+
export type PipeUnwrapChildComponentConstructor = new () => PipeUnwrapChildComponentInstance;
|
|
6
|
+
export declare function createPipeUnwrapChildComponent(): PipeUnwrapChildComponentConstructor;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
2
|
+
export function createPipeUnwrapChildComponent() {
|
|
3
|
+
class ChildComponent extends FluffElement {
|
|
4
|
+
value = null;
|
|
5
|
+
__render() {
|
|
6
|
+
this.__getShadowRoot().innerHTML = '<span>child</span>';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return ChildComponent;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
export interface PipeUnwrapTestState {
|
|
4
|
+
receivedValue: unknown;
|
|
5
|
+
receivedValueType: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PipeUnwrapParentComponentInstance extends FluffElement {
|
|
8
|
+
testProp: number;
|
|
9
|
+
__testProp: Property<number>;
|
|
10
|
+
}
|
|
11
|
+
export type PipeUnwrapParentComponentConstructor = new () => PipeUnwrapParentComponentInstance;
|
|
12
|
+
export declare function createPipeUnwrapParentComponent(state: PipeUnwrapTestState, childTag: string): PipeUnwrapParentComponentConstructor;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
export function createPipeUnwrapParentComponent(state, childTag) {
|
|
4
|
+
class ParentComponent extends FluffElement {
|
|
5
|
+
__testProp = new Property({ initialValue: 99, propertyName: 'testProp' });
|
|
6
|
+
get testProp() {
|
|
7
|
+
return this.__testProp.getValue() ?? 0;
|
|
8
|
+
}
|
|
9
|
+
set testProp(val) {
|
|
10
|
+
this.__testProp.setValue(val);
|
|
11
|
+
}
|
|
12
|
+
__pipes = {
|
|
13
|
+
capture: (value) => {
|
|
14
|
+
state.receivedValue = value;
|
|
15
|
+
state.receivedValueType = value instanceof Property ? 'Property' : typeof value;
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
__render() {
|
|
20
|
+
this.__getShadowRoot().innerHTML = `<${childTag} data-lid="l0"></${childTag}>`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ParentComponent;
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
export interface PipeUnwrapTestState {
|
|
4
|
+
receivedValue: unknown;
|
|
5
|
+
receivedValueType: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PipeUnwrapTestComponentInstance extends FluffElement {
|
|
8
|
+
testProp: number;
|
|
9
|
+
__testProp: Property<number>;
|
|
10
|
+
}
|
|
11
|
+
export type PipeUnwrapTestComponentConstructor = new () => PipeUnwrapTestComponentInstance;
|
|
12
|
+
export declare function createPipeUnwrapTestComponent(state: PipeUnwrapTestState): PipeUnwrapTestComponentConstructor;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
import { MarkerManager } from '../MarkerManager.js';
|
|
4
|
+
export function createPipeUnwrapTestComponent(state) {
|
|
5
|
+
class TestComponent extends FluffElement {
|
|
6
|
+
__testProp = new Property({ initialValue: 42, propertyName: 'testProp' });
|
|
7
|
+
get testProp() {
|
|
8
|
+
return this.__testProp.getValue() ?? 0;
|
|
9
|
+
}
|
|
10
|
+
set testProp(val) {
|
|
11
|
+
this.__testProp.setValue(val);
|
|
12
|
+
}
|
|
13
|
+
__pipes = {
|
|
14
|
+
capture: (value) => {
|
|
15
|
+
state.receivedValue = value;
|
|
16
|
+
state.receivedValueType = value instanceof Property ? 'Property' : typeof value;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
__render() {
|
|
21
|
+
this.__getShadowRoot().innerHTML = '<span><!--fluff:text:0--><!--/fluff:text:0--></span>';
|
|
22
|
+
this.__setMarkerConfigs(JSON.stringify([
|
|
23
|
+
[0, { type: 'text', exprId: 0, deps: ['testProp'], pipes: [{ name: 'capture', argExprIds: [] }] }]
|
|
24
|
+
]));
|
|
25
|
+
}
|
|
26
|
+
__setupBindings() {
|
|
27
|
+
this.__initializeMarkers(MarkerManager);
|
|
28
|
+
super.__setupBindings();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return TestComponent;
|
|
32
|
+
}
|