ValueChangeEvent<T> class
Represents a value change event.
@param <T> the value about to be changed
class ValueChangeEvent<T> extends DwtEvent { /** * The event type. */ static EventType<ValueChangeHandler> TYPE = new EventType<ValueChangeHandler>(); T _value; /** * Gets the value. * * @return the value */ T get value => _value; /** * Creates a value change event. * * @param value the value */ ValueChangeEvent(this._value); EventType<ValueChangeHandler> getAssociatedType() { return TYPE; } /** * Implemented by subclasses to to invoke their handlers in a type safe * manner. Intended to be called by [EventBus#fireEvent(Event)] or * [EventBus#fireEventFromSource(Event, Object)]. * * @param handler handler * @see EventBus#dispatchEvent(Event, Object) */ void dispatch(ValueChangeHandler handler) { handler.onValueChange(this); } /** * Fires an {@link AttachEvent} on all registered handlers in the handler * source. * * @param <S> The handler source type * @param source the source of the handlers * @param attached whether to announce an attach or detach */ static void fire(HasValueChangeHandlers source, Object value) { if (TYPE != null) { ValueChangeEvent event = new ValueChangeEvent(value); source.fireEvent(event); } } /** * Fires value change event if the old value is not equal to the new value. * Use this call rather than making the decision to short circuit yourself for * safe handling of null. * * @param <T> the old value type * @param source the source of the handlers * @param oldValue the oldValue, may be null * @param newValue the newValue, may be null */ static void fireIfNotEqual(HasValueChangeHandlers source, Object oldValue, Object newValue) { if (_shouldFire(source, oldValue, newValue)) { ValueChangeEvent event = new ValueChangeEvent(newValue); source.fireEvent(event); } } /** * Convenience method to allow subtypes to know when they should fire a value * change event in a null-safe manner. * * @param <T> value type * @param source the source * @param oldValue the old value * @param newValue the new value * @return whether the event should be fired */ static bool _shouldFire(HasValueChangeHandlers source, Object oldValue, Object newValue) { return TYPE != null && oldValue != newValue && (oldValue == null || oldValue != newValue); } /** * The toString() for abstract event is overridden to avoid accidently * including class literals in the the compiled output. Use [Event] * #toDebugString to get more information about the event. */ String toString() { return "ValueChangeEvent. Value: ${value}"; } }
Extends
IEvent<H> > DwtEvent > ValueChangeEvent<T>
Static Properties
EventType<ValueChangeHandler> TYPE #
The event type.
static EventType<ValueChangeHandler> TYPE = new EventType<ValueChangeHandler>()
Static Methods
void fire(HasValueChangeHandlers source, Object value) #
Fires an {@link AttachEvent} on all registered handlers in the handler source.
@param <S> The handler source type @param source the source of the handlers @param attached whether to announce an attach or detach
static void fire(HasValueChangeHandlers source, Object value) { if (TYPE != null) { ValueChangeEvent event = new ValueChangeEvent(value); source.fireEvent(event); } }
void fireIfNotEqual(HasValueChangeHandlers source, Object oldValue, Object newValue) #
Fires value change event if the old value is not equal to the new value. Use this call rather than making the decision to short circuit yourself for safe handling of null.
@param <T> the old value type @param source the source of the handlers @param oldValue the oldValue, may be null @param newValue the newValue, may be null
static void fireIfNotEqual(HasValueChangeHandlers source, Object oldValue, Object newValue) { if (_shouldFire(source, oldValue, newValue)) { ValueChangeEvent event = new ValueChangeEvent(newValue); source.fireEvent(event); } }
Constructors
Methods
void assertLive() #
Asserts that the event still should be accessed. All events are considered to be "dead" after their original handler manager finishes firing them. An event can be revived by calling {@link GwtEvent#revive()}.
void assertLive() { assert (!_dead) ; //: "This event has already finished being processed by its original handler manager, so you can no longer access it"; }
void dispatch(ValueChangeHandler handler) #
Implemented by subclasses to to invoke their handlers in a type safe
manner. Intended to be called by EventBus#fireEvent(Event)
or
EventBus#fireEventFromSource(Event, Object)
.
@param handler handler @see EventBus#dispatchEvent(Event, Object)
void dispatch(ValueChangeHandler handler) { handler.onValueChange(this); }
EventType<ValueChangeHandler> getAssociatedType() #
Object getSource() #
Returns the source for this event. The type and meaning of the source is
arbitrary, and is most useful as a secondary key for handler registration.
(See EventBus#addHandlerToSource
, which allows a handler to
register for events of a particular type, tied to a particular source.)
Note that the source is actually set at dispatch time, e.g. via
EventBus#fireEventFromSource(Event, Object)
.
@return object representing the source of this event
Object getSource() { assertLive(); return super.getSource(); }
bool isLive() #
Is the event current live?
@return whether the event is live
bool isLive() { return !_dead; }
void kill() #
Kill the event. After the event has been killed, users cannot really on its values or functions being available.
void kill() { _dead = true; setSource(null); }
void overrideSource(Object source) #
void overrideSource(Object source) { super.setSource(source); }
void revive() #
Revives the event. Used when recycling event instances.
void revive() { _dead = false; setSource(null); }
void setSource(source) #
Set the source that triggered this event. Intended to be called by the EventBus during dispatch.
@param source the source of this event. @see EventBus#fireEventFromSource(Event, Object) @see EventBus#setSourceOfEvent(Event, Object)
void setSource(dynamic source) { this._source = source; }
String toString() #
The toString() for abstract event is overridden to avoid accidently
including class literals in the the compiled output. Use Event
toDebugString to get more information about the event.
String toString() { return "ValueChangeEvent. Value: ${value}"; }