ForgetfulRetainedValuesStore


The ForgetfulRetainedValuesStore is an implementation of RetainedValuesStore that is incapable of retaining any exited values. When installed as the LocalRetainedValuesStore, all invocations of retain will behave like a standard remember. RetainObserver callbacks are still dispatched instead of RememberObserver callbacks, meaning that this class will always immediately retire a value as soon as it exits composition.

A ForgetfulRetainedValuesStore can be installed arbitrarily in any number of compositions.

Summary

Public functions

open Any?
getExitedValueOrElse(key: Any, defaultValue: Any?)

If this store is currently retaining exited values and has a value previously created with the given key, its original record is returned and removed from the list of exited kept objects that this store is tracking.

Cmn
open Unit

Invoked to indicate that all content has finished entering the composition for the first time after the store is installed.

Cmn
open Unit

Invoked to indicate that the associated content is about to start leaving composition.

Cmn
open Unit
saveExitingValue(key: Any, value: Any?)

Invoked when a retained value is exiting composition while this store is retaining exited values.

Cmn

Public functions

getExitedValueOrElse

open fun getExitedValueOrElse(key: Any, defaultValue: Any?): Any?

If this store is currently retaining exited values and has a value previously created with the given key, its original record is returned and removed from the list of exited kept objects that this store is tracking.

This method is always called from the composition thread.

Parameters
key: Any

The keys to resolve a retained value that has left composition

defaultValue: Any?

A value to be returned if there are no retained values that have exited composition and are being held by this RetainedValuesStore for the given key.

Returns
Any?

A retained value for key if there is one and it hasn't already re-entered composition, otherwise defaultValue.

onContentEnteredComposition

open fun onContentEnteredComposition(): Unit

Invoked to indicate that all content has finished entering the composition for the first time after the store is installed. Any unconsumed retained values should be discarded at this time.

This function is called by the library when the store is installed with LocalRetainedValuesStoreProvider. It should not be invoked directly in production code. The default installation will always invoke this callback on the applier thread for the content's latest destination, which may differ when moved between compositions.

Implementors of this function MUST call RetainObserver.onRetired for all discarded values that implement RetainObserver following the threading guarantees specified in RetainObserver's documentation.

onContentExitComposition

open fun onContentExitComposition(): Unit

Invoked to indicate that the associated content is about to start leaving composition. The store should make any necessary preparations to start retaining values as they exit the composition.

This function is called by the library when the store is installed with LocalRetainedValuesStoreProvider. It should not be invoked directly in production code. The default installation will always invoke this callback on the applier thread that content entered composition on.

saveExitingValue

open fun saveExitingValue(key: Any, value: Any?): Unit

Invoked when a retained value is exiting composition while this store is retaining exited values. It is up to the implementation of this method to decide whether and how to store these values so that they can later be retrieved by getExitedValueOrElse.

The given key are not guaranteed to be unique. To handle duplicate keys, implementors should return retained values with the same keys from getExitedValueOrElse in the opposite order they are received by saveExitingValue.

If the implementation of this store does not accept this value into its kept exited object list, it MUST call RetainObserver.onRetired if value implements RetainObserver, following the threading guarantees specified in RetainObserver's documentation.

This method is always called from the applier thread.