pocketbase / dart-sdk

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

how to yield from subscription function #40

Closed tonyhart7 closed 1 year ago

tonyhart7 commented 1 year ago

image

I am using riverpod with StreamProvider and want to use yield when new record created but I cant do that because RecordSubscriptionEven output Void at the end

ganigeorgiev commented 1 year ago

I'm not sure that I understand your use case but I don't think you can yield to the parent context from within the subscribe callback even if the function was async*.

You can try to create your own stream and push data to it via the subscribe callback. Then inside the riverpod function you can use the await for (not .listen(...)) construct with your stream and yield within its block.

tonyhart7 commented 1 year ago

I'm not sure that I understand your use case but I don't think you can yield to the parent context from within the subscribe callback even if the function was async*.

You can try to create your own stream and push data to it via the subscribe callback. Then inside the riverpod function you can use the await for (not .listen(...)) construct with your stream and yield within its block.

image

Okay its works, but how to query old data tho ??

like I want to aquire existing data if there are some but as long as new data get inserted. it gets automatically added

ganigeorgiev commented 1 year ago

Okay its works, but how to query old data tho ??

PocketBase realtime events reacts only on changes (aka. create/update/delete of a record).

If you want to fetch the already inserted data you'll have to query it manually with the regular getList()/getFullList() methods.

ganigeorgiev commented 1 year ago

By the way, you can also check the StateProvider which might be better for your use case since you'll not need the extra stream.

In any case, I'll close the issue for now but feel free to comment if you stumble on something else.