pocketbase / dart-sdk

PocketBase Dart SDK
https://pub.dev/packages/pocketbase
MIT License
527 stars 52 forks source link

Update realtime docs or realtime function to avoid invalid types #65

Closed HadiHassan22 closed 6 hours ago

HadiHassan22 commented 7 hours ago

The documentation implies the subscribe function takes a listener that listens to events of type RecordSubscriptionEvent. But in reality the subscribe function takes a listener of type SseMessage.

So even the example in the pub documentation:

pb.collection('example').subscribe("*", (e) {
  print(e.action); // create, update, delete
  print(e.record); // the changed record
}, filter: "someField > 10");

leads to a linter type error: The getter 'action' isn't defined for the type 'SseMessage'.

I believe either the documentation should be updated to make use of SseMessage type or the function should take a listener of RecordSubscriptionEvent events.

ganigeorgiev commented 6 hours ago

No you are mistaken, or at least I'm not able to reproduce it (Dart 3.5.2).

RecordService.subscribe expects the callback to be of RecordSubscriptionFunc that correctly accept RecordSubscriptionEvent argument.

Feel free to provide a more complete code that could trigger the above linter error and I'll try to investigate it but it works correctly for me (you can also test the example in the example/example.dart).

ganigeorgiev commented 6 hours ago

Maybe you are confusing the collection specific subscribe method with the generic pb.realtime.subscribe?