avosignals 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +66 -1
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -82,11 +82,33 @@ dispose();
82
82
  // Logs: 'Cleaning up...'
83
83
  ```
84
84
 
85
+ 4. Manual Subscription
86
+
87
+ If you need to listen to changes without creating an automatic effect (for example, to integrate with a legacy API or one-off logic), you can subscribe directly to any `Signal` or `Computed`.
88
+
89
+ *Note: Unlike `effect`, manual subscriptions do not track dependencies automatically; they only fire when the specific signal you subscribed to changes.*
90
+
91
+ ```Typescript
92
+ import { Signal } from 'avosignals';
93
+
94
+ const theme = new Signal('light');
95
+
96
+ // Returns an unsubscribe function
97
+ const unsubscribe = theme.subscribe(() => {
98
+ console.log(`Theme changed to: ${theme.get()}`);
99
+ });
100
+
101
+ theme.set('dark'); // Logs: "Theme changed to: dark"
102
+
103
+ // Stop listening
104
+ unsubscribe();
105
+ ```
106
+
85
107
  # Usage with Lit
86
108
 
87
109
  `avosignals` was built with Lit in mind. The `SignalWatcher` class hooks into the Lit lifecycle to automatically track signals accessed during render. Its core design is to allow for production ready signals which can be easily replaced with Lit's official signals once **TC39 signals** becomes mainstream and production ready.
88
110
 
89
- # The `SignalWatcher` Controller
111
+ ## The `SignalWatcher` Controller
90
112
 
91
113
  You do not need to manually subscribe to signals. simply add the controller, and any signal read inside `render()` will trigger a component update when it changes.
92
114
 
@@ -116,6 +138,49 @@ export class MyCounter extends LitElement {
116
138
  }
117
139
  ```
118
140
 
141
+ # Usage with Vanilla Web Components
142
+
143
+ You can easily use `avosignals` with standard HTML Web Components. Since vanilla components don't have a built-in reactive render cycle, the best pattern is to use an `effect` inside `connectedCallback` to update the DOM, and clean it up in `disconnectedCallback`.
144
+
145
+ ```TypeScript
146
+ import { Signal, effect } from 'avosignals';
147
+
148
+ const count = new Signal(0);
149
+
150
+ class VanillaCounter extends HTMLElement {
151
+ private dispose?: () => void;
152
+ private label = document.createElement('span');
153
+ private button = document.createElement('button');
154
+
155
+ constructor() {
156
+ super();
157
+ this.attachShadow({ mode: 'open' });
158
+
159
+ this.button.textContent = 'Increment';
160
+ this.button.onclick = () => count.update(c => c + 1);
161
+
162
+ // Initial layout
163
+ this.shadowRoot?.append(this.label, this.button);
164
+ }
165
+
166
+ connectedCallback() {
167
+ // Use 'effect' to bind the signal state to the DOM text.
168
+ // This runs immediately and whenever 'count' changes.
169
+ this.dispose = effect(() => {
170
+ this.label.textContent = `Current count: ${count.get()} `;
171
+ });
172
+ }
173
+
174
+ disconnectedCallback() {
175
+ // ⚠️ Important: Always clean up effects when the element
176
+ // is removed from the DOM to prevent memory leaks.
177
+ if (this.dispose) this.dispose();
178
+ }
179
+ }
180
+
181
+ customElements.define('vanilla-counter', VanillaCounter);
182
+ ```
183
+
119
184
  # Advanced Architecture
120
185
 
121
186
  ### Memory Management (WeakRefs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avosignals",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight signaling library for web components and modern web applications with Lit integration.",
5
5
  "keywords": [
6
6
  "signals",
@@ -28,10 +28,12 @@
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "git+https://github.com/anatolipr/avos.git"
31
+ "url": "git+https://github.com/anatolipr/avos.git",
32
+ "directory": "packages/avosignals"
32
33
  },
33
34
  "bugs": {
34
35
  "url": "https://github.com/anatolipr/avos/issues"
35
36
  },
37
+ "homepage": "https://github.com/anatolipr/avos/tree/main/packages/avosignals#readme",
36
38
  "license": "MIT"
37
39
  }