com.raquo.airstream.ownership
Members list
Type members
Classlikes
DynamicOwner manages DynamicSubscription-s similarly to how Owner manages Subscription
s, except DynamicSubscription
can be activated and deactivated repeatedly.
DynamicOwner manages DynamicSubscription-s similarly to how Owner manages Subscription
s, except DynamicSubscription
can be activated and deactivated repeatedly.
Value parameters
- onAccessAfterKilled
-
Called if you attempt to use any Owner created by this DynamicOwner after that Owner was killed. It's intended to log and/or throw for reporting / debugging purposes.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Represents a subscription that can be turned on and off repeatedly. For example, in Laminar the elements can be mounted and unmounted repeatedly, and so their subscriptions are activated and deactivated respectively when those events happen.
Represents a subscription that can be turned on and off repeatedly. For example, in Laminar the elements can be mounted and unmounted repeatedly, and so their subscriptions are activated and deactivated respectively when those events happen.
In contrast, the only thing you can do to a non-dynamic Subscription is kill
it, and once that is done, it will remain dead forever.
Note that the dynamic subscription is NOT activated automatically upon creation.
The subscription created by activate
must not be killed externally, otherwise DynamicSubscription will throw when it tries to kill it and it's already killed.
Value parameters
- activate
-
- Note: Must not throw!
- prepend
-
- If true, dynamic owner will prepend subscription to the list instead of appending. This affects activation and deactivation order of subscriptions.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
DynamicSubscription.type
All this class does is expose the method to kill subscriptions. Just a small convenience for ad-hoc integrations
All this class does is expose the method to kill subscriptions. Just a small convenience for ad-hoc integrations
Please note that this is NOT a OneTimeOwner. If that's what you need, copy this code but extend OneTimeOwner instead of Owner.
Attributes
- Supertypes
Owner that can not be used after it was killed. Used in Laminar via DynamicOwner.
Owner that can not be used after it was killed. Used in Laminar via DynamicOwner.
Value parameters
- onAccessAfterKilled
-
Called if you attempt to use this owner after it was killed. It's intended to log and/or throw for reporting / debugging purposes.
Attributes
- Supertypes
Owner decides when to kill its subscriptions.
Owner decides when to kill its subscriptions.
- Ownership is defined at creation of the Subscription
- Ownership is non-transferable
- There is no way to unkill a Subscription
- In other words: Owner can only own a Subscription once, and a Subscription can only ever be owned by its initial owner
- Owner can still be used after calling killPossessions, but the canonical use case is for the Owner to kill its possessions when the owner itself is discarded (e.g. a UI component is unmounted).
If you need something more flexible, use DynamicOwner, or build your own custom logic on top of this in a similar manner.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class ManualOwnerclass OneTimeOwner
Represents a leaky resource that needs to be cleaned up.
Represents a leaky resource that needs to be cleaned up.
Subscription is linked for its life to a given owner. It can be killed by that owner, or externally using .kill().
See also: Ownership documentation, as well as Owner scaladoc
Value parameters
- cleanup
-
Note: Must not throw!
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
This subscription is hyper dynamic, allowing you to change DynamicOwner on the fly.
This subscription is hyper dynamic, allowing you to change DynamicOwner on the fly.
It works by creating DynamicSubscription-s under the hood with your provided owner and activate() and deactivate() methods, but it has a special semantic: when transferring this subscription from one active DynamicOwner to another active DynamicOwner, neither activate() nor deactivate() are called because continuity of active ownership is maintained.
So in effect, this subscription only cares whether it's owned or not, so it does not expose the owner to you: notice the activate
callback is not provided with an Owner.
An example of where this is useful is tracking mounting and unmounting of elements in Laminar. If an element is mounted, we want to call activate(), if unmounted, we want to call deactivate(), but if the element is MOVED from one mounted parent to another mounted parent, it just remains mounted, this transition is of no interest to us. If not for this subscription's special design, we would need to call deactivate() to "detach" the subscription from its old parent's owner and then immediately afterwards call activate() to "attach" the subscription to the new parent's owner, but that would deactivate and then immediately re-activate all subscriptions on the Laminar element being moved (and all of its descendants), which would be very wasteful. Well, you do need to know Laminar to understand this example.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any