@reactive-web-components/rwc 2.61.10 → 2.63.7
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/README.md +52 -1
- package/package.json +5 -5
- package/{reactive-web-component.f_B19_fm.js → reactive-web-component.BmjLtNib.js} +391 -396
- package/reactive-web-component.Bx_Hbzlr.umd.cjs +2 -0
- package/shared/types/element.d.ts +1 -0
- package/shared/utils/signal/signal.d.ts +1 -1
- package/shared/utils/signal/utils.d.ts +6 -0
- package/reactive-web-component.rx6nheib.umd.cjs +0 -2
package/README.md
CHANGED
|
@@ -243,7 +243,32 @@ city.set('SPB'); // userData immediately updates to ['Jane', 30, 'SPB']
|
|
|
243
243
|
- **`forkJoin`** — waits for all signals to update before emitting a new value. Useful when you need all values to be updated together.
|
|
244
244
|
- **`combineLatest`** — emits a new value immediately when any signal changes. Useful for real-time updates and reactive computations.
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
#### firstUpdate
|
|
247
|
+
|
|
248
|
+
Executes a callback after the first update of a reactive signal. Useful for performing one-time actions when a signal receives its first non-initial value.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { firstUpdate, signal } from '@shared/utils';
|
|
252
|
+
|
|
253
|
+
const userSignal = signal(null);
|
|
254
|
+
|
|
255
|
+
// This callback will be called only once when userSignal is first updated
|
|
256
|
+
firstUpdate(userSignal, (user) => {
|
|
257
|
+
console.log('User loaded for the first time:', user);
|
|
258
|
+
// Perform initialization logic
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Later, when userSignal is updated:
|
|
262
|
+
userSignal.set({ name: 'John', age: 30 }); // Callback executes
|
|
263
|
+
userSignal.set({ name: 'Jane', age: 25 }); // Callback does NOT execute again
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Application:**
|
|
267
|
+
- Performing one-time initialization when data first arrives
|
|
268
|
+
- Triggering side effects only on the first update
|
|
269
|
+
- Handling initial data loading scenarios
|
|
270
|
+
|
|
271
|
+
### Function as Child Content (recommended style for dynamic lists and conditional render)
|
|
247
272
|
|
|
248
273
|
Functions passed as child content to `el` or `customEl` are automatically converted to reactive content. This allows convenient creation of dynamic content that will update when dependent signals change. The content function receives context (a reference to its component) as the first argument.
|
|
249
274
|
|
|
@@ -536,6 +561,7 @@ To set properties, attributes, classes, events, and effects for elements and com
|
|
|
536
561
|
```typescript
|
|
537
562
|
export type ComponentInitConfig<T extends ExtraHTMLElement> = Partial<{
|
|
538
563
|
classList: ConfigClassList;
|
|
564
|
+
ref: ReactiveSignal<ComponentConfig<T>>;
|
|
539
565
|
style: ConfigStyle;
|
|
540
566
|
attributes: ConfigAttribute<T>;
|
|
541
567
|
customAttributes: ConfigCustomAttribute;
|
|
@@ -558,6 +584,7 @@ export type ComponentInitConfig<T extends ExtraHTMLElement> = Partial<{
|
|
|
558
584
|
#### Main Features
|
|
559
585
|
|
|
560
586
|
- **classList** — array of classes (strings or functions/signals)
|
|
587
|
+
- **ref** — reactive signal to get a reference to the component instance
|
|
561
588
|
- **style** — CSS styles object; supports both regular properties and CSS Custom Properties (`--var`), values can be functions/signals
|
|
562
589
|
- **attributes** — object with HTML attributes
|
|
563
590
|
- **customAttributes** — object with custom attributes
|
|
@@ -663,6 +690,30 @@ div(
|
|
|
663
690
|
)
|
|
664
691
|
```
|
|
665
692
|
|
|
693
|
+
**7. Getting component reference with ref**
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
const buttonRef = signal<ComponentConfig<HTMLButtonElement>>(null);
|
|
697
|
+
|
|
698
|
+
// Later, use the reference
|
|
699
|
+
button({
|
|
700
|
+
ref: buttonRef,
|
|
701
|
+
listeners: {
|
|
702
|
+
click: () => console.log('Button clicked')
|
|
703
|
+
}
|
|
704
|
+
}, 'Click me');
|
|
705
|
+
|
|
706
|
+
// Access the component later
|
|
707
|
+
effect(() => {
|
|
708
|
+
const buttonComponent = buttonRef();
|
|
709
|
+
if (buttonComponent) {
|
|
710
|
+
console.log('Button component available:', buttonComponent);
|
|
711
|
+
// You can call component methods:
|
|
712
|
+
// buttonComponent.addClass('active');
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
```
|
|
716
|
+
|
|
666
717
|
---
|
|
667
718
|
|
|
668
719
|
**Best practice:**
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactive-web-components/rwc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.63.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./shared/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./shared/index.d.ts",
|
|
9
|
-
"import": "./reactive-web-component.
|
|
10
|
-
"require": "./reactive-web-component.
|
|
9
|
+
"import": "./reactive-web-component.BmjLtNib.js",
|
|
10
|
+
"require": "./reactive-web-component.Bx_Hbzlr.umd.cjs"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"author": "tamazyanarsen",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"ui",
|
|
35
35
|
"frontend"
|
|
36
36
|
],
|
|
37
|
-
"module": "./reactive-web-component.
|
|
38
|
-
"main": "./reactive-web-component.
|
|
37
|
+
"module": "./reactive-web-component.BmjLtNib.js",
|
|
38
|
+
"main": "./reactive-web-component.Bx_Hbzlr.umd.cjs"
|
|
39
39
|
}
|