Dart Documentationclean_dataDataReference

DataReference class

Observable object, which represents single primitive in Data.

class DataReference extends Object with ChangeNotificationsMixin, ChangeValueNotificationsMixin{

 /**
  * Encapsulated value
  */
 dynamic _value;

 StreamSubscription _onDataChangeListener, _onDataChangeSyncListener;

 /**
  * Return value of a primitive type.
  */
 get value => _value;

 /**
  * Change value of primitive type and notify listeners.
  */
 set value(newValue) {
   changeValue(newValue);
 }

 _silentChangeValue(newValue){
   assert(newValue is! DataReference);
   _value = newValue;

   if(_onDataChangeListener != null) {
     _onDataChangeListener.cancel();
     _onDataChangeListener = null;
   }
   if(_onDataChangeSyncListener != null) {
     _onDataChangeSyncListener.cancel();
     _onDataChangeSyncListener = null;
   }

   if(newValue is ChangeNotificationsMixin) {
     _onDataChangeSyncListener = newValue.onChangeSync.listen((changeEvent) {
       _onChangeSyncController.add(changeEvent);
     });
     _onDataChangeListener = newValue.onChange.listen((changeEvent) {
       // due to its lazy initialization, _onChangeController does not need to
       // exist; if not ignore the change, no one is listening!
       if (_onChangeController != null) {
         _onChangeController.add(changeEvent);
       }
     });
   }

 }

 changeValue(newValue, {author: null}) {
   _markChanged(this._value, newValue);
   _silentChangeValue(newValue);
   _notify(author: author);
 }

 /**
  * Creates new DataReference with [value]
  */
 DataReference(value) {
   _silentChangeValue(value);
   _clearChanges();
   _clearChangesSync();
 }

 void dispose() {
   _dispose();
   if (_onDataChangeListener != null) {
     _onDataChangeListener.cancel();
   }
   if (_onDataChangeSyncListener != null) {
     _onDataChangeSyncListener.cancel();
   }

 }

 String toString() => 'Ref(${_value.toString()})';
}

Mixins

ChangeNotificationsMixin, ChangeValueNotificationsMixin

Constructors

new DataReference(value) #

Creates new DataReference with value

DataReference(value) {
 _silentChangeValue(value);
 _clearChanges();
 _clearChangesSync();
}

Properties

final Stream<dynamic> onBeforeAdd #

Stream populated with DataMapView events before any data object is added.

Stream<dynamic> get onBeforeAdd {
 if(_onBeforeAddedController == null) {
   _onBeforeAddedController =
       new StreamController.broadcast(sync: true);
 }
 return _onBeforeAddedController.stream;
}

final Stream<dynamic> onBeforeRemove #

Stream populated with DataMapView events before any data object is removed.

Stream<dynamic> get onBeforeRemove {
 if(_onBeforeRemovedController == null) {
   _onBeforeRemovedController =
       new StreamController.broadcast(sync: true);
 }
 return _onBeforeRemovedController.stream;
}

final Stream<ChangeSet> onChange #

Stream populated with ChangeSet events whenever the collection or any of data object contained gets changed.

Stream<ChangeSet> get onChange {
 if(_onChangeController == null) {
   _onChangeController =
       new StreamController.broadcast();
 }
 return _onChangeController.stream;
}

final Stream<Map> onChangeSync #

Stream populated with {'change': ChangeSet, 'author': dynamic} events synchronously at the moment when the collection or any data object contained gets changed.

Stream<Map> get onChangeSync => _onChangeSyncController.stream;

dynamic get value #

Return value of a primitive type.

get value => _value;

dynamic set value(newValue) #

Change value of primitive type and notify listeners.

set value(newValue) {
 changeValue(newValue);
}

Methods

dynamic changeValue(newValue, {author: null}) #

changeValue(newValue, {author: null}) {
 _markChanged(this._value, newValue);
 _silentChangeValue(newValue);
 _notify(author: author);
}

void dispose() #

void dispose() {
 _dispose();
 if (_onDataChangeListener != null) {
   _onDataChangeListener.cancel();
 }
 if (_onDataChangeSyncListener != null) {
   _onDataChangeSyncListener.cancel();
 }

}

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString() => 'Ref(${_value.toString()})';