ivoleitao / stash

Key-value store abstraction with plain and cache driven semantics and a pluggable backend architecture.
MIT License
86 stars 16 forks source link

How to retrieve a stream of values #32

Closed Prn-Ice closed 2 years ago

Prn-Ice commented 2 years ago

This is a question.

How do I retrieve a stream of cached values that can be used in a reactive user interface. Hive itself offers an implementation of this.

ivoleitao commented 2 years ago

Hi,

You just need to use the on method on the vault or on the cache, snippet bellow for a vault and the memory store:

  // Creates a store
  final store = await newMemoryVaultStore();

  // Creates a vault from the previously created store
  final vault = await store.vault<Task>(name: 'vault'):

  // Returns a stream of created entries. You may subscribe to all the events instead
  final stream = vault.on<VaultEntryCreatedEvent<Task>>();

You can find additional documentation on the Events section of the stash documentation

Prn-Ice commented 2 years ago

Awesome, thanks