Dart Documentationclean_data

clean_data library

Support for automatical data synchronization among collections.

Concepts

  • Changes: You can easily attach listeners to all objects to detect changes of their data. Changes are represented as ChangeSet or Change instances. Changes are available through asynchronous [onChange] [Stream], that does the work of grouping multiple changes that occured during execution to single ChangeSet fired in the next event loop.

  • DataMap: Data are stored using a Map compatible instances of class DataMap.

  • DataSet: Multiple data objects can be stored and manipulated using the instance of DataSet class. DataSet behave similarly to Set, each object can be contained at most once and no order is guaranteed.

  • Views: You can easily create various read-only views of your data using handy methods filter, map, union, except, intersect. Views gets automatically updated when the underlying data change to always reflect actual state.

Examples

Create simple data object and listen to its changes:

import 'package:clean_data/clean_data.dart';
void main() {
  var person = new DataMap.from({"name": "John"});
  person.onChange.listen((changeSet) => print("Person has changed!"));

  person['surname'] = 'Doe';
  person['age'] = 37;
}

The above code outputs:

Person has changed!

Notice that despite of two changes happened, we only one notification was fired.

Create simple set and listen to its changes:

import 'package:clean_data/clean_data.dart';
void main() {
  var colleagues = new DataSet();
  colleagues.onChange.listen((changeSet) => print("Team has changed!"));

  colleagues.add(new DataMap.from({"name": "John"}));
  colleagues.add(new DataMap.from({"name": "Peter"}));

}

The above code outputs:

Team has changed!

Similarly to previous example, only one notification was fired.

Our set also listens to changes in its underlying data objects:

import 'package:clean_data/clean_data.dart';
void main() {
  var john = new DataMap.from({"name": "John"});
  var peter = new DataMap.from({"name": "Peter"});

  var colleagues = new DataSet.from([john, peter]);
  colleagues.onChange.listen((changeSet) => print("Team has changed!"));

  john['surname'] = 'Doe';
  peter['surname'] = 'Pan';

}

The above code outputs:

Team has changed!

Again, only one notification was fired.

Properties

const undefined #

const undefined = const _Undefined('undefined')

const unset #

const unset = const _Undefined('unset')

Functions

ChangeNotificationsMixin clone(data) #

ChangeNotificationsMixin clone(data) {
 if (data is DataList || data is DataMap || data is DataSet) {
   return _clone(data);
 }
}

dynamic decleanify(data) #

dynamic decleanify(data) {
 if(data is DataList) {
   return new List.from(data.map((value) => decleanify(value)));
 }
 else if(data is DataMap) {
   return new Map.fromIterables(data.keys, data.values.map((value) => decleanify(value)));
 }
 else if(data is DataSet) {
   return new Set.from(data.map((value) => decleanify(value)));
 }
 else if(data is DataReference) {
   return data.value;
 }
 else {
   return data;
 }
}

dynamic cleanify(data) #

cleanify(data) {
 if (data is ChangeNotificationsMixin) {
   return data;
 }
 if(data is List) {
   return new DataList.from(data);
 }
 else if(data is Map) {
   return new DataMap.from(data);
 }
 else if(data is Set || data is Iterable || data is Iterator) {
   if(data is Iterator) data = new List(data);
   return new DataSet.from(data);
 }
 else {
   return data;
 }
}

Abstract Classes

Classes

Typedefs

Exceptions