Permalink
Browse files

feature: ObservableProperty got call-operator

  • Loading branch information...
MikeMitterer committed Jan 31, 2017
1 parent a2bb60d commit f28fc4e9ec7bb60e6b20f3f0e6bf25187bb5efe6
Showing with 78 additions and 0 deletions.
  1. +7 −0 lib/src/observable/ObservableProperty.dart
  2. +71 −0 test/unit/observable/ObservableProperty_test.dart
@@ -98,6 +98,7 @@ class ObservableProperty<T> {
void set value(final val) {
final T old = _value;
// JS does not support double - so you have to specify treatAsDouble
if(_value.runtimeType == double || _treatAsDouble ) {
// Strange - but this avoids DA-Warning
@@ -122,6 +123,12 @@ class ObservableProperty<T> {
T get value => _value;
/// Mimics a function call
///
/// final ObservableProperty<String> nrOfItems = new ObservableProperty<String>("");
/// nrOfItems(10)
void call(final val) { value = val; }
/**
* Observe values in your app
* Sample:
@@ -0,0 +1,71 @@
import 'dart:async';
@TestOn("content-shell")
import 'package:test/test.dart';
// import 'package:logging/logging.dart';
import 'package:mdl/mdlobservable.dart';
import '../config.dart';
main() async {
// final Logger _logger = new Logger("test.ObservableProperty");
configLogging();
//await saveDefaultCredentials();
group('ObservableProperty', () {
setUp(() { });
test('> set value with setter', () async {
final ObservableProperty<bool> property = new ObservableProperty<bool>(false);
expect(property.value, false);
property.value = "true";
expect(property.value, true);
bool valueTester = false;
property.observes(() => valueTester);
await new Future.delayed(new Duration(milliseconds: 500),() => true);
expect(property.value, false);
valueTester = true;
await new Future.delayed(new Duration(milliseconds: 500),() => true);
expect(property.value, true);
}); // end of 'set value with setter' test
test('> set value with call operator', () async {
final ObservableProperty<bool> property = new ObservableProperty<bool>(false);
expect(property.value, false);
property("true");
expect(property.value, true);
property("false");
expect(property.value, false);
property(false);
expect(property.value, false);
property("1");
expect(property.value, true);
property("0");
expect(property.value, false);
property("yes");
expect(property.value, true);
property("no");
expect(property.value, false);
}); // end of 'set value with call operator' test
});
// End of 'ObservableProperty' group
}
// - Helper --------------------------------------------------------------------------------------

0 comments on commit f28fc4e

Please sign in to comment.