Skip to content

Commit

Permalink
fix store subscription for prop in store cases (#7071)
Browse files Browse the repository at this point in the history
track store modifications in `has()` cases
  • Loading branch information
revintec authored Nov 20, 2024
1 parent 7558018 commit 9259205
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-carrots-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

Fix: add subscription when doing `"prop" in store`
16 changes: 12 additions & 4 deletions packages/qwik/src/core/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,23 @@ export class ReadWriteProxyHandler implements ProxyHandler<TargetType> {
return true;
}

has(target: TargetType, property: string | symbol): boolean {
if (property === QOjectTargetSymbol) {
has(target: TargetType, prop: string | symbol): boolean {
if (prop === QOjectTargetSymbol) {
return true;
}
const invokeCtx = tryGetInvokeContext();
if (typeof prop === 'string' && invokeCtx) {
const subscriber = invokeCtx.$subscriber$;
if (subscriber) {
const isA = isArray(target);
this.$manager$.$addSub$(subscriber, isA ? undefined : prop);
}
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
if (hasOwnProperty.call(target, property)) {
if (hasOwnProperty.call(target, prop)) {
return true;
}
if (typeof property === 'string' && hasOwnProperty.call(target, _IMMUTABLE_PREFIX + property)) {
if (typeof prop === 'string' && hasOwnProperty.call(target, _IMMUTABLE_PREFIX + prop)) {
return true;
}
return false;
Expand Down

0 comments on commit 9259205

Please sign in to comment.