-
Notifications
You must be signed in to change notification settings - Fork 1
feat(entities): Implement watch() method for live query subscriptions #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This adds a watch() method to EntityHandler that allows subscribing to
filtered subsets of entities with real-time change notifications.
Features:
- watch(options, callback) method with filter, sort, fields, limit options
- WatchEvent with changeType ('added', 'modified', 'removed')
- subscribeQuery/unsubscribeQuery socket events for server communication
- Proper cleanup on unsubscribe
The watch() method differs from subscribe() in that:
- It supports filter, sort, fields, and limit options
- It returns changeType indicating how the change affects the filtered results
- It uses dedicated subscribe_query socket events
Example usage:
```typescript
const unsubscribe = base44.entities.Task.watch(
{ filter: { status: 'active' }, sort: '-created_date', limit: 10 },
(event) => {
if (event.changeType === 'added') {
console.log('New matching task:', event.data);
}
}
);
```
Fixes #83
Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
Claude finished @guyofeck's task —— View job Code Review for PR #86: feat(entities): Implement watch() method for live query subscriptionsI've thoroughly reviewed the implementation of the ✅ Code Quality and Best PracticesStrengths:
Minor Improvements:
✅ Potential Bugs or IssuesNo critical bugs found, but a few considerations:
|
|
@claude the callback should get the snapshot of all of the entities that returns from the query, and not a specific entity |
|
Claude finished @guyofeck's task —— View job Todo List:
Analysis of the watch() ImplementationI've reviewed the current implementation, and I understand the concern. Looking at the code and tests, the current Current Implementation BehaviorThe current implementation:
Architectural ImplicationsIf the callback should receive a snapshot of all entities matching the query (as you're suggesting), this would be a significant architectural change:
Potential Implementation ApproachesIf you want to implement snapshot-based updates, here are two approaches: Option 1: Full Snapshot on Every Change interface WatchSnapshot {
entities: any[]; // All entities matching the query
changeType: 'added' | 'modified' | 'removed';
changedEntityId: string; // Which entity triggered this update
timestamp: string;
}Option 2: Initial Snapshot + Individual Updates // Initial callback with full snapshot
callback({ type: 'snapshot', entities: [...] });
// Subsequent callbacks with individual changes
callback({ type: 'change', changeType: 'added', entity: {...} });Questions for Clarification
The current implementation follows a more traditional event-based pattern (similar to Firebase Realtime Database), while what you're describing sounds more like a reactive query pattern (similar to MongoDB Change Streams with full document). Would you like me to suggest specific implementation changes for the snapshot-based approach? |
Summary
watch(options, callback)method toEntityHandlerfor live query subscriptionsWatchEventtype withchangeType('added', 'modified', 'removed')WatchOptionstype for filter, sort, fields, limit configurationsubscribeQuery/unsubscribeQuerysocket events for server communicationUsage
Test plan
Depends on: Backend PRs #2894, #2895, #2896
Fixes #83
🤖 Generated with Claude Code