Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 25, 2023
1 parent 1e2db5b commit e888f58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
1 change: 1 addition & 0 deletions packages/reactivity/__tests__/deferredComputed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('deferred computed', () => {
expect(spy).toHaveBeenCalledTimes(1)

src.value = 3
src.value = 5
// should trigger because latest value changes
expect(spy).toHaveBeenCalledTimes(2)
})
Expand Down
61 changes: 27 additions & 34 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,21 @@ type RefBase<T> = {
export function trackRefValue(ref: RefBase<any>) {
if (shouldTrack && activeEffect) {
ref = toRaw(ref)
if (__DEV__) {
trackEffect(
activeEffect,
ref.dep ||
(ref.dep = createDep(
() => (ref.dep = undefined),
ref instanceof ComputedRefImpl ? ref : undefined
)),
{
target: ref,
type: TrackOpTypes.GET,
key: 'value'
}
)
} else {
trackEffect(
activeEffect,
ref.dep ||
(ref.dep = createDep(
() => (ref.dep = undefined),
ref instanceof ComputedRefImpl ? ref : undefined
))
)
}
trackEffect(
activeEffect,
ref.dep ||
(ref.dep = createDep(
() => (ref.dep = undefined),
ref instanceof ComputedRefImpl ? ref : undefined
)),
__DEV__
? {
target: ref,
type: TrackOpTypes.GET,
key: 'value'
}
: void 0
)
}
}

Expand All @@ -76,16 +67,18 @@ export function triggerRefValue(
ref = toRaw(ref)
const dep = ref.dep
if (dep) {
if (__DEV__) {
triggerEffects(dep, dirtyLevel, {
target: ref,
type: TriggerOpTypes.SET,
key: 'value',
newValue: newVal
})
} else {
triggerEffects(dep, dirtyLevel)
}
triggerEffects(
dep,
dirtyLevel,
__DEV__
? {
target: ref,
type: TriggerOpTypes.SET,
key: 'value',
newValue: newVal
}
: void 0
)
}
}

Expand Down
3 changes: 1 addition & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export default defineConfig({
},
test: {
globals: true,
// threads must be disabled because FinalizationRegistry.register is used in the code
// and multi-threading causes thread locks for some reasons
// threads must be disabled as FinalizationRegistry causes vitest zombie process somehow
threads: false,
setupFiles: 'scripts/setupVitest.ts',
environmentMatchGlobs: [
Expand Down

0 comments on commit e888f58

Please sign in to comment.