Permalink
Browse files

bug: Solevs the double/int problem in ObservableProperty

  • Loading branch information...
MikeMitterer committed Nov 10, 2015
1 parent 79afaf6 commit 5f70ce8ac3214cdd477f2ad92092595f2b1c1de1
View
@@ -24,10 +24,9 @@ from the get-go.
Visit the [website](http://www.material-design-lite.pub) for a "Quick start" or check out the [Kitchen Sink](http://styleguide.material-design-lite.pub/)
## Examples
...
Check out the [samples](http://styleguide.material-design-lite.pub/#/samples)
## Features and bugs
## Features and bugs
Please file feature requests and bugs at the [issue tracker](https://github.com/MikeMitterer/dart-material-design-lite/issues).
## More links
@@ -211,11 +211,10 @@ class MaterialRipple extends MdlComponent {
throw "$event must bei either MouseEvent or TouchEvent!";
}
x = ((clientX - bound.left) as double).round();
y = ((clientY - bound.top) as double).round();
x = ((clientX - bound.left) as num).round();
y = ((clientY - bound.top) as num).round();
}
//_logger.info("X $x Y $y ${bound} ${event.target} T ${hasRipple}");
if(hasRipple) {
@@ -45,6 +45,7 @@ class ListChangedEvent<T> {
*/
@MdlComponentModel
class ObservableList<T> extends ListBase<T> {
//final Logger _logger = new Logger('mdlobservable.ObservableList');
final List<T> _innerList = new List();
@@ -35,6 +35,9 @@ class ObservableProperty<T> {
@MdlComponentModel
T _value;
/// Always convert to double
final bool _treatAsDouble;
Function _observe;
/// Default interval if no specified in CTOR
@@ -53,13 +56,23 @@ class ObservableProperty<T> {
* [interval] Check-Interval
* [name] is useful for debugging. If you set this name and if you set your loglevel to "info" it
* you should see a log output if this object fires a PropertyChangeEvent
*
* If you set [observeViaTimer] to false the PropertyChangeEvent is only triggered on "set value"
*
* Use [treatAsDouble] if you want to be sure that all your values are converted to double.
* This works around the problem that Dart does not recognize a double if compiled to JS
*
* Sample:
* time.observes(() => _getTime());
* final ObservableProperty<double> long = new ObservableProperty<double>(0.0,treatAsDouble: true);
*
* final ObservableProperty<String> time = new ObservableProperty<String>("", interval: new Duration(seconds: 1));
* Application() {
* time.observes(() => _getTime());
* }
*/
ObservableProperty(this._value,{ T observe(), final Duration interval,
final String name: ObservableProperty._DEFAULT_NAME, final bool observeViaTimer: true } ) : _name = name {
final String name: ObservableProperty._DEFAULT_NAME, final bool observeViaTimer: true,
final bool treatAsDouble: false } ) : _name = name, _treatAsDouble = treatAsDouble {
if(interval != null && observeViaTimer) {
_interval = interval;
@@ -85,18 +98,18 @@ class ObservableProperty<T> {
void set value(final val) {
final T old = _value;
if(_value.runtimeType == bool) {
if(_value.runtimeType == double || _treatAsDouble ) {
_value = ConvertValue.toDouble(val);
} else if(_value.runtimeType == bool) {
_value = ConvertValue.toBool(val) as T;
} else if(_value.runtimeType == int) {
_value = ConvertValue.toInt(val) as T;
} else if(_value.runtimeType == double) {
_value = ConvertValue.toDouble(val) as T;
} else {
_value = val;
}
@@ -53,8 +53,31 @@ class _MaterialRepeatConstant {
final String TEMPLATE = "template";
const _MaterialRepeatConstant();
}
}
/**
* Iterates through a [ObservableList]
* Sample:
* HTML:
* <div mdl-repeat="job in jobs">
* {{! ----- Turn off default mustache interpretation (sitegen) ---- }} {{= | | =}}
* <template>
* <div class="mdl-accordion mdl-js-accordion">
* <label class="mdl-accordion__label">{{job.ID}}
* <jobtoolbar job-id="{{job.ID}}" class="jobtoolbar--right"></jobtoolbar>
*
* <i class="material-icons indicator">chevron_right</i></label>
*
* <div class="mdl-accordion--content">
* <p class="mdl-accordion--body">
* <jobedit job-id="{{job.ID}}"></jobedit>
* </p>
* </div>
* </div>
* </template>
* |= {{ }} =| {{! ----- Turn on mustache ---- }}
* </div>
*/
@MdlComponentModel
class MaterialRepeat extends MdlTemplateComponent {
final Logger _logger = new Logger('mdltemplate.MaterialRepeat');
@@ -269,6 +292,7 @@ class MaterialRepeat extends MdlTemplateComponent {
"but was: $dataset!");
}
/// Splits up mdl-repeat="job in jobs" into listName and itemName
final String listName = dataset.split(" ").last;
final String itemName = dataset.split(" ").first;
@@ -313,17 +337,22 @@ class MaterialRepeat extends MdlTemplateComponent {
case ListChangeType.UPDATE:
final Map itemToRemove = _getItemFromInternalList(event.prevItem);
int index = _items.indexOf(itemToRemove);
try {
final Map itemToRemove = _getItemFromInternalList(event.prevItem);
int index = _items.indexOf(itemToRemove);
remove(itemToRemove).then((_) {
remove(itemToRemove).then((_) {
if(index < _items.length) {
insert(index, { itemName : event.item },scope: scope.context);
} else {
add( { itemName : event.item },scope: scope.context);
}
});
if(index < _items.length) {
insert(index, { itemName : event.item },scope: scope.context);
} else {
add( { itemName : event.item },scope: scope.context);
}
});
} on StateError catch (e,stacktrace) {
_logger.shout("_getItemFromInternalList(${event.prevItem}) produced '$e'",stacktrace);
}
break;

0 comments on commit 5f70ce8

Please sign in to comment.