Package arez.component.internal
Class ComponentKernel
java.lang.Object
arez.component.internal.ComponentKernel
- All Implemented Interfaces:
ComponentObservable
,Disposable
@OmitClinit
public final class ComponentKernel
extends Object
implements Disposable, ComponentObservable
The "kernel" of the components generated by the annotation processor.
This class exists so that code common across multiple components is not present in every
generated class but is instead in a single location. This results in smaller, faster code.
-
Constructor Summary
ConstructorDescriptionComponentKernel
(ArezContext context, String name, int id, Component component, SafeProcedure preDisposeCallback, SafeProcedure disposeCallback, SafeProcedure postDisposeCallback, boolean notifyOnDispose, boolean isComponentObservable, boolean disposeOnDeactivate) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOnDisposeListener
(Object key, SafeProcedure action) Add the listener to notify list under key.void
Transition component state fromCOMPONENT_INITIALIZED
toCOMPONENT_CONSTRUCTED
and then toCOMPONENT_READY
.void
Transition component state fromCOMPONENT_INITIALIZED
toCOMPONENT_CONSTRUCTED
.void
Transition component state fromCOMPONENT_CONSTRUCTED
toCOMPONENT_READY
.Describe component state.void
dispose()
Dispose the element.Return the native component associated with the component.Return the context in which this component was created.int
getId()
Return the synthetic id associated with the component.getName()
Return the name of the component.boolean
Return true if the component has been completed.boolean
Return true if the component has been constructed.boolean
Return true if the component has been initialized.boolean
isActive()
Return true if the component is active and can be interacted with.boolean
Return true if the component is in COMPONENT_COMPLETE state.boolean
Return true if the component is in COMPONENT_CONSTRUCTED state.boolean
Return true if dispose() has been called on object.boolean
Return true if the component is disposing.boolean
Return true if the component is NOT ready.boolean
isReady()
Return true if the component is ready.void
Notify an OnDispose listeners that have been added to the component.boolean
observe()
Return true if the component is "alive" a.k.a.void
Remove the listener with specified key from the notify list.void
safeSetObservable
(String name, SafeProcedure setter) Invoke the setter in a transaction.void
setObservable
(String name, Procedure setter) Invoke the setter in a transaction.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface arez.Disposable
isNotDisposed
-
Constructor Details
-
ComponentKernel
public ComponentKernel(@Nullable ArezContext context, @Nullable String name, int id, @Nullable Component component, @Nullable SafeProcedure preDisposeCallback, @Nullable SafeProcedure disposeCallback, @Nullable SafeProcedure postDisposeCallback, boolean notifyOnDispose, boolean isComponentObservable, boolean disposeOnDeactivate)
-
-
Method Details
-
observe
Description copied from interface:ComponentObservable
Return true if the component is "alive" a.k.a. not disposing or disposed. This method MUST be invoked within a non-DISPOSE transaction and will add the component as a dependency if the transaction is tracking, unless this component is disposing or disposed.- Specified by:
observe
in interfaceComponentObservable
- Returns:
- true if the component is "alive" a.k.a. not disposing or disposed.
-
dispose
Description copied from interface:Disposable
Dispose the element. SeeDisposable
for a description of the implications.- Specified by:
dispose
in interfaceDisposable
-
isDisposed
Description copied from interface:Disposable
Return true if dispose() has been called on object.- Specified by:
isDisposed
in interfaceDisposable
- Returns:
- true if dispose has been called.
-
notifyOnDisposeListeners
Notify an OnDispose listeners that have been added to the component. This method MUST only be called if the component has enabled onDisposeNotify feature. -
hasBeenInitialized
Return true if the component has been initialized.- Returns:
- true if the component has been initialized.
-
hasBeenConstructed
Return true if the component has been constructed.- Returns:
- true if the component has been constructed.
-
hasBeenCompleted
Return true if the component has been completed.- Returns:
- true if the component has been completed.
-
isConstructed
Return true if the component is in COMPONENT_CONSTRUCTED state.- Returns:
- true if the component is in COMPONENT_CONSTRUCTED state.
-
isComplete
Return true if the component is in COMPONENT_COMPLETE state.- Returns:
- true if the component is in COMPONENT_COMPLETE state.
-
isReady
Return true if the component is ready.- Returns:
- true if the component is ready.
-
isNotReady
Return true if the component is NOT ready.- Returns:
- true if the component is NOT ready.
-
isDisposing
Return true if the component is disposing.- Returns:
- true if the component is disposing.
-
isActive
Return true if the component is active and can be interacted with. This means that the component has been constructed and has not started to be disposed.- Returns:
- true if the component is active.
-
describeState
Describe component state. This is usually used to provide error messages.- Returns:
- a string description of the state.
-
componentConstructed
Transition component state fromCOMPONENT_INITIALIZED
toCOMPONENT_CONSTRUCTED
. -
componentComplete
Transition component state fromCOMPONENT_INITIALIZED
toCOMPONENT_CONSTRUCTED
and then toCOMPONENT_READY
. This should only be called if there is active elements that are part of the component that need to be scheduled, otherwise the component can transition directly to ready. -
componentReady
Transition component state fromCOMPONENT_CONSTRUCTED
toCOMPONENT_READY
. This should be invoked rather thancomponentComplete()
if there is no active elements of the component that need to be scheduled. -
getContext
Return the context in which this component was created.- Returns:
- the associated context.
-
safeSetObservable
Invoke the setter in a transaction. If a transaction is active then invoke the setter directly, otherwise wrap the setter in an action.- Parameters:
name
- the name of the action if it is needed.setter
- the setter action to invoke.
-
setObservable
Invoke the setter in a transaction. If a transaction is active then invoke the setter directly, otherwise wrap the setter in an action.- Parameters:
name
- the name of the action if it is needed.setter
- the setter action to invoke.- Throws:
Throwable
- if setter throws an exception.
-
getName
Return the name of the component. This method should NOT be invoked unlessArez.areNamesEnabled()
returns true and will throw an exception if invariant checking is enabled.- Returns:
- the name of the component.
-
getId
Return the synthetic id associated with the component. This method MUST NOT be invoked if a synthetic id is not present and will generate an invariant failure when invariants are enabled.- Returns:
- the synthetic id associated with the component.
-
getComponent
Return the native component associated with the component. This method MUST NOT be invoked if native components are disabled.- Returns:
- the native component associated with the component.
-
addOnDisposeListener
Add the listener to notify list under key. This method MUST NOT be invoked afterdispose()
has been invoked. This method should not be invoked if another listener has been added with the same key without being removed.If the key implements
Disposable
andDisposable.isDisposed()
returnstrue
when invoking the calback then the callback will be skipped. This rare situation only occurs when there is circular dependency in the object model usually involvingCascadeDispose
.- Parameters:
key
- the key to uniquely identify listener.action
- the listener callback.
-
removeOnDisposeListener
Remove the listener with specified key from the notify list. This method should only be invoked when a listener has been added for specific key usingaddOnDisposeListener(Object, SafeProcedure)
and has not been removed by another call to this method.- Parameters:
key
- the key under which the listener was previously added.
-
toString
-