@preact/signals 1.1.3 → 1.1.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @preact/signals
2
2
 
3
+ ## 1.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#373](https://github.com/preactjs/signals/pull/373) [`8c12a0d`](https://github.com/preactjs/signals/commit/8c12a0df74f00e9cab04e999fc443889b3528c04) Thanks [@rschristian](https://github.com/rschristian)! - Removes package.json#exports.umd, which had invalid paths if they were ever to be consumed
8
+
9
+ - Updated dependencies [[`8c12a0d`](https://github.com/preactjs/signals/commit/8c12a0df74f00e9cab04e999fc443889b3528c04), [`26f6526`](https://github.com/preactjs/signals/commit/26f6526875ef0968621c4113594ac95b93de5163)]:
10
+ - @preact/signals-core@1.3.1
11
+
3
12
  ## 1.1.3
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Signals
3
2
 
4
3
  Signals is a performant state management library with two primary goals:
@@ -15,15 +14,15 @@ npm install @preact/signals
15
14
  ```
16
15
 
17
16
  - [Guide / API](../../README.md#guide--api)
18
- - [`signal(initialValue)`](../../README.md#signalinitialvalue)
19
- - [`signal.peek()`](../../README.md#signalpeek)
20
- - [`computed(fn)`](../../README.md#computedfn)
21
- - [`effect(fn)`](../../README.md#effectfn)
22
- - [`batch(fn)`](../../README.md#batchfn)
17
+ - [`signal(initialValue)`](../../README.md#signalinitialvalue)
18
+ - [`signal.peek()`](../../README.md#signalpeek)
19
+ - [`computed(fn)`](../../README.md#computedfn)
20
+ - [`effect(fn)`](../../README.md#effectfn)
21
+ - [`batch(fn)`](../../README.md#batchfn)
23
22
  - [Preact Integration](#preact-integration)
24
- - [Hooks](#hooks)
25
- - [Rendering optimizations](#rendering-optimizations)
26
- - [Attribute optimization (experimental)](#attribute-optimization-experimental)
23
+ - [Hooks](#hooks)
24
+ - [Rendering optimizations](#rendering-optimizations)
25
+ - [Attribute optimization (experimental)](#attribute-optimization-experimental)
27
26
  - [License](#license)
28
27
 
29
28
  ## Preact Integration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preact/signals",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "license": "MIT",
5
5
  "description": "Manage state with style in Preact",
6
6
  "keywords": [],
@@ -28,14 +28,13 @@
28
28
  ".": {
29
29
  "types": "./dist/signals.d.ts",
30
30
  "browser": "./dist/signals.module.js",
31
- "umd": "./dist/signals.umd.js",
32
31
  "import": "./dist/signals.mjs",
33
32
  "require": "./dist/signals.js"
34
33
  }
35
34
  },
36
35
  "mangle": "../../mangle.json",
37
36
  "dependencies": {
38
- "@preact/signals-core": "^1.2.3"
37
+ "@preact/signals-core": "^1.3.1"
39
38
  },
40
39
  "peerDependencies": {
41
40
  "preact": "10.x"
@@ -189,6 +189,70 @@ describe("@preact/signals", () => {
189
189
  rerender();
190
190
  expect(spy).to.be.calledOnce;
191
191
  });
192
+
193
+ it("should not subscribe to computed signals only created and not used", () => {
194
+ const sig = signal(0);
195
+ const childSpy = sinon.spy();
196
+ const parentSpy = sinon.spy();
197
+
198
+ function Child({ num }: { num: Signal<number> }) {
199
+ childSpy();
200
+ return <p>{num.value}</p>;
201
+ }
202
+
203
+ function Parent({ num }: { num: Signal<number> }) {
204
+ parentSpy();
205
+ const sig2 = useComputed(() => num.value + 1);
206
+ return <Child num={sig2} />;
207
+ }
208
+
209
+ render(<Parent num={sig} />, scratch);
210
+ expect(scratch.innerHTML).to.equal("<p>1</p>");
211
+ expect(parentSpy).to.be.calledOnce;
212
+ expect(childSpy).to.be.calledOnce;
213
+
214
+ sig.value += 1;
215
+ rerender();
216
+ expect(scratch.innerHTML).to.equal("<p>2</p>");
217
+ expect(parentSpy).to.be.calledOnce;
218
+ expect(childSpy).to.be.calledTwice;
219
+ });
220
+
221
+ it("should properly subscribe and unsubscribe to conditionally rendered computed signals ", () => {
222
+ const computedDep = signal(0);
223
+ const renderComputed = signal(true);
224
+ const renderSpy = sinon.spy();
225
+ const computer = sinon.spy(() => computedDep.value + 1);
226
+
227
+ function App() {
228
+ renderSpy();
229
+ const computed = useComputed(computer);
230
+ return renderComputed.value ? <p>{computed.value}</p> : null;
231
+ }
232
+
233
+ render(<App />, scratch);
234
+ expect(scratch.innerHTML).to.equal("<p>1</p>");
235
+ expect(renderSpy).to.be.calledOnce;
236
+ expect(computer).to.be.calledOnce;
237
+
238
+ computedDep.value += 1;
239
+ rerender();
240
+ expect(scratch.innerHTML).to.equal("<p>2</p>");
241
+ expect(renderSpy).to.be.calledTwice;
242
+ expect(computer).to.be.calledTwice;
243
+
244
+ renderComputed.value = false;
245
+ rerender();
246
+ expect(scratch.innerHTML).to.equal("");
247
+ expect(renderSpy).to.be.calledThrice;
248
+ expect(computer).to.be.calledTwice;
249
+
250
+ computedDep.value += 1;
251
+ rerender();
252
+ expect(scratch.innerHTML).to.equal("");
253
+ expect(renderSpy).to.be.calledThrice; // Should not be called again
254
+ expect(computer).to.be.calledTwice; // Should not be called again
255
+ });
192
256
  });
193
257
 
194
258
  describe("prop bindings", () => {