Skip to content

Commit 78a08bb

Browse files
committed
Sync alien-signals 0.3.0
1 parent ad591c3 commit 78a08bb

File tree

3 files changed

+238
-234
lines changed

3 files changed

+238
-234
lines changed

packages/reactivity/src/computed.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import {
99
type Link,
1010
activeSub,
1111
activeTrackId,
12+
checkDirty,
1213
endTrack,
1314
link,
1415
propagate,
15-
resolveMaybeDirty,
1616
startTrack,
1717
} from './effect'
18+
import { activeEffectScope } from './effectScope'
1819
import type { Ref } from './ref'
1920
import { warn } from './warning'
20-
import { activeEffectScope } from './effectScope'
2121

2222
declare const ComputedRefSymbol: unique symbol
2323
declare const WritableComputedRefSymbol: unique symbol
@@ -90,10 +90,14 @@ export class ComputedRefImpl<T = any> implements IComputed {
9090
get _dirty(): boolean {
9191
let dirtyLevel = this.dirtyLevel
9292
if (dirtyLevel === DirtyLevels.MaybeDirty) {
93-
resolveMaybeDirty(this)
94-
dirtyLevel = this.dirtyLevel
93+
if (checkDirty(this.deps!)) {
94+
return true
95+
} else {
96+
this.dirtyLevel = DirtyLevels.None
97+
return false
98+
}
9599
}
96-
return dirtyLevel >= DirtyLevels.Dirty
100+
return dirtyLevel === DirtyLevels.Dirty
97101
}
98102
set _dirty(v: boolean) {
99103
if (v) {
@@ -126,7 +130,12 @@ export class ComputedRefImpl<T = any> implements IComputed {
126130

127131
get value(): T {
128132
if (this._dirty) {
129-
this.update()
133+
if (this.update()) {
134+
const subs = this.subs
135+
if (subs !== undefined) {
136+
propagate(subs)
137+
}
138+
}
130139
}
131140
if (activeTrackId !== 0) {
132141
const subsTail = this.subsTail
@@ -154,7 +163,7 @@ export class ComputedRefImpl<T = any> implements IComputed {
154163
}
155164
}
156165

157-
update(): void {
166+
update(): boolean {
158167
const prevSub = startTrack(this)
159168
const oldValue = this._value
160169
let newValue: T
@@ -165,11 +174,9 @@ export class ComputedRefImpl<T = any> implements IComputed {
165174
}
166175
if (hasChanged(oldValue, newValue)) {
167176
this._value = newValue
168-
const subs = this.subs
169-
if (subs !== undefined) {
170-
propagate(subs)
171-
}
177+
return true
172178
}
179+
return false
173180
}
174181
}
175182

0 commit comments

Comments
 (0)