Title: Implement `watch()` method for live query subscriptions · Issue #83 · base44/javascript-sdk · GitHub
Open Graph Title: Implement `watch()` method for live query subscriptions · Issue #83 · base44/javascript-sdk
X Title: Implement `watch()` method for live query subscriptions · Issue #83 · base44/javascript-sdk
Description: Summary Implement a new watch() method on entity handlers to support live query subscriptions with filtering, sorting, and field selection. Background Currently, the SDK supports subscribe() for listening to all entity changes. We need t...
Open Graph Description: Summary Implement a new watch() method on entity handlers to support live query subscriptions with filtering, sorting, and field selection. Background Currently, the SDK supports subscribe() for li...
X Description: Summary Implement a new watch() method on entity handlers to support live query subscriptions with filtering, sorting, and field selection. Background Currently, the SDK supports subscribe() for li...
Opengraph URL: https://github.com/base44/javascript-sdk/issues/83
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement `watch()` method for live query subscriptions","articleBody":"## Summary\nImplement a new `watch()` method on entity handlers to support live query subscriptions with filtering, sorting, and field selection.\n\n## Background\nCurrently, the SDK supports `subscribe()` for listening to all entity changes. We need to add support for filtered/query-based subscriptions that return snapshots of matching data.\n\n## Proposed API\n\n```typescript\ninterface QueryOptions {\n filter?: Record\u003cstring, any\u003e; // MongoDB-compatible filter\n sort?: string; // Field name, prefix with '--' for descending\n fields?: string[]; // Field selection\n}\n\ninterface SnapshotData\u003cT\u003e {\n type: 'added' | 'modified' | 'removed';\n entities: T[];\n}\n\n// New method on EntityHandler\nwatch(options: QueryOptions, callback: (snapshot: SnapshotData) =\u003e void): Subscription;\n```\n\n## Usage Example\n\n```typescript\nbase44.entities.Tasks.watch({\n filter: { 'price': { '$gt': 10 } },\n sort: '--price',\n fields: ['id', 'price', 'name']\n}, (snapshot) =\u003e {\n console.log(`Snapshot changed, reason: ${snapshot.type}`);\n setTasks(snapshot.entities);\n});\n```\n\n## Implementation Details\n\n### Files to modify:\n- `src/modules/entities.ts` - Add `watch()` method to entity handler (similar pattern to existing `subscribe()` at line 166-188)\n- `src/modules/entities.types.ts` - Add `QueryOptions`, `SnapshotData`, and update `EntityHandler` interface\n- `src/utils/socket-utils.ts` - May need to extend room subscription to pass query options\n\n### Socket Integration:\n- Room naming convention: `entities:{appId}:{entityName}:watch` or similar\n- Need to emit query options when joining room\n- Handle `query_update` or similar event for snapshot updates\n\n### Key Considerations:\n- Initial fetch should happen immediately upon subscription\n- Return unsubscribe function (consistent with existing `subscribe()` pattern)\n- Handle reconnection with query re-subscription\n- JSON parse snapshot data from socket messages\n\n## Related\n- Depends on backend implementation of live query support\n- Design doc: Live Query Support implementation","author":{"url":"https://github.com/guyofeck","@type":"Person","name":"guyofeck"},"datePublished":"2026-01-22T19:48:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/83/javascript-sdk/issues/83"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0db7ae78-8c59-54f8-d4f6-927fc2179153 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB96:D84EF:88703:B1DD3:6A4C2157 |
| html-safe-nonce | 9981326bf5ce3c6412e601d848440cc2e6bbc773f3e6b2be140d740b95568d07 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjk2OkQ4NEVGOjg4NzAzOkIxREQzOjZBNEMyMTU3IiwidmlzaXRvcl9pZCI6IjMwMjM5MzMyMDQ2OTQwNDkxMTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 63de687a348767c510969cc69cd0aa6deacb63a6725b8287b89ed5c8af606814 |
| hovercard-subject-tag | issue:3844488991 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/base44/javascript-sdk/83/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fc2f1a3d0456adf7027035f03af1eee601146b2f2a2ae340d35ecb8866d0efb1/base44/javascript-sdk/issues/83 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fc2f1a3d0456adf7027035f03af1eee601146b2f2a2ae340d35ecb8866d0efb1/base44/javascript-sdk/issues/83 |
| og:image:alt | Summary Implement a new watch() method on entity handlers to support live query subscriptions with filtering, sorting, and field selection. Background Currently, the SDK supports subscribe() for li... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | guyofeck |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b6b16d04026f131a36d57e3b01d0f4d26a51800edf48bf5ed0256e0ac905511 |
| turbo-cache-control | no-preview |
| go-import | github.com/base44/javascript-sdk git https://github.com/base44/javascript-sdk.git |
| octolytics-dimension-user_id | 234699998 |
| octolytics-dimension-user_login | base44 |
| octolytics-dimension-repository_id | 939374418 |
| octolytics-dimension-repository_nwo | base44/javascript-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 939374418 |
| octolytics-dimension-repository_network_root_nwo | base44/javascript-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f95fb36c72adc940ff991c03531114b2245658d0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width