API Reference 0.7.1rikulo_modelDataModel

DataModel class

A data model.

class DataModel implements StreamTarget<DataEvent> {
 DataEvents _on;
 final Map<String, List<DataEventListener>> _listeners = new HashMap();

 DataModel() {
   _on = new DataEvents._(this);
 }

 /** Returns [DataEvents] for adding or removing event listeners.
  */
 DataEvents get on => _on;
 /** Adds an event listener.
  * `addEventListener("select", listener)` is the same as
  * `on.select.add(listener)`.
  */
 void addEventListener(String type, DataEventListener listener) {
   if (listener == null)
     throw new ArgumentError("listener");

   bool first = false;
   _listeners.putIfAbsent(type, () {
     first = true;
     return [];
   }).add(listener);
 }
 /** Removes an event listener.
  * `removeEventListener("select", listener)` is the same as
  * `on.select.remove(listener)`.
  */
 void removeEventListener(String type, DataEventListener listener) {
   final list = _listeners[type];
   if (list != null)
     list.remove(listener);
 }
 /** Sends an event to this model.
  *
  * Example: `model.sendEvent(new ListDataEvent(model, "select"))</code>.
  */
 bool sendEvent(DataEvent event) {
   final bool
     b1 = _sendEvent(event, _listeners[event.type]),
     b2 = _sendEvent(event, _listeners['all']);
   return b1 || b2;
 }
 static bool _sendEvent(DataEvent event, List<DataEventListener> listeners) {
   bool dispatched = false;
   if (listeners != null) {
     //Note: we make a copy of listeners since listener might remove other listeners
     //It means the removing and adding of listeners won't take effect until next event
     for (final DataEventListener listener in new List.from(listeners)) {
       dispatched = true;
       listener(event);
     }
   }
   return dispatched;
 }
}

Subclasses

AbstractDataModel<T>, ListModel<T>, TreeModel<T>

Implements

StreamTarget<DataEvent>

Constructors

new DataModel() #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
DataModel() {
 _on = new DataEvents._(this);
}

Properties

final DataEvents on #

Returns DataEvents for adding or removing event listeners.

DataEvents get on => _on;

Methods

void addEventListener(String type, DataEventListener listener) #

Adds an event listener. addEventListener("select", listener) is the same as on.select.add(listener).

void addEventListener(String type, DataEventListener listener) {
 if (listener == null)
   throw new ArgumentError("listener");

 bool first = false;
 _listeners.putIfAbsent(type, () {
   first = true;
   return [];
 }).add(listener);
}

void removeEventListener(String type, DataEventListener listener) #

Removes an event listener. removeEventListener("select", listener) is the same as on.select.remove(listener).

void removeEventListener(String type, DataEventListener listener) {
 final list = _listeners[type];
 if (list != null)
   list.remove(listener);
}

bool sendEvent(DataEvent event) #

Sends an event to this model.

Example: `model.sendEvent(new ListDataEvent(model, "select"))</code>.

bool sendEvent(DataEvent event) {
 final bool
   b1 = _sendEvent(event, _listeners[event.type]),
   b2 = _sendEvent(event, _listeners['all']);
 return b1 || b2;
}