Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
bug: callAttached called only the first registered MdlComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Jul 21, 2015
1 parent 16d7acb commit f21c2e8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
13 changes: 10 additions & 3 deletions lib/src/components/MaterialTextfield.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -109,18 +109,25 @@ class MaterialTextfield extends MdlComponent {


/// Update text field value. /// Update text field value.
void change(final String value) { void change(final String value) {
if (value != null && value != _relaxedInput.value) {

int selStart = (_relaxedInput as dom.InputElement).selectionStart;
int selEnd = (_relaxedInput as dom.InputElement).selectionStart;


if (value != null) {
_relaxedInput.value = value; _relaxedInput.value = value;

(_relaxedInput as dom.InputElement).setSelectionRange(selStart,selEnd);
} }

_updateClasses(); _updateClasses();
} }


/// Returns text field value
String get value => _relaxedInput.value; String get value => _relaxedInput.value;


/// Update text field value
void set value(final String value) { void set value(final String value) {
_relaxedInput.value = value; change(value);
_updateClasses();
} }


//- private ----------------------------------------------------------------------------------- //- private -----------------------------------------------------------------------------------
Expand Down
27 changes: 14 additions & 13 deletions lib/src/core/utils.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
void _listNames(var jsElement) { void _listNames(var jsElement) {
final Logger _logger = new Logger('mdlcore.mdlComponent._listNames'); final Logger _logger = new Logger('mdlcore.mdlComponent._listNames');


final List<String> componentsForElement = (jsElement[_MDL_WIDGET_PROPERTY] as String).split(","); final List<String> componentsForElement = (jsElement[_MDL_COMPONENT_PROPERTY] as String).split(",");

_logger.info("Registered Component for $element:");
componentsForElement.forEach((final String name) { componentsForElement.forEach((final String name) {
_logger.warning("Registered Component $name for $element"); _logger.warning(" -> $name");
}); });
} }


Expand All @@ -58,8 +60,7 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
if(element.id != null && element.id.isNotEmpty) { if(element.id != null && element.id.isNotEmpty) {
id = element.id; id = element.id;
} }
throw "$element is not a MdlComponent!!! (ID: $id)"; throw "$element is not a MdlComponent!!! (ID: $id, ${element.classes}, ${element.dataset['upgraded']})";

} }


String typeAsString; String typeAsString;
Expand Down Expand Up @@ -92,7 +93,7 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
_listNames(jsElement); _listNames(jsElement);


throw "$element is not a ${typeAsString}-Component!!!\n(ID: ${element.id}, class: ${element.classes})\n" throw "$element is not a ${typeAsString}-Component!!!\n(ID: ${element.id}, class: ${element.classes})\n"
"These components are available: ${jsElement[_MDL_COMPONENT_PROPERTY] as String}"; "These components are available: ${jsElement[_MDL_COMPONENT_PROPERTY] as String}";
} }


/// Calls the MdlComponents attached-function for the given [element] and all it's childrens /// Calls the MdlComponents attached-function for the given [element] and all it's childrens
Expand All @@ -103,17 +104,17 @@ void callAttached(final dom.Element element) {


if(element is dom.HtmlElement) { if(element is dom.HtmlElement) {


try { var jsElement = new JsObject.fromBrowserObject(element);
final MdlComponent component = mdlComponent(element as dom.HtmlElement,null); if(jsElement.hasProperty(_MDL_COMPONENT_PROPERTY)) {
if(component != null) { final List<String> componentsForElement = (jsElement[_MDL_COMPONENT_PROPERTY] as String).split(",");
component.attached(); componentsForElement.forEach((final String componentName) {
}


// Ignore exception - it's OK here final MdlComponent component = jsElement[componentName] as MdlComponent;
} on String catch (e) { component.attached();


//_logger.info("$e"); });
} }

} }


// Iterate through all children // Iterate through all children
Expand Down
15 changes: 4 additions & 11 deletions lib/src/template/components/MaterialModel.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,27 +46,23 @@ class MaterialModel extends MdlComponent {


MaterialModel.fromElement(final dom.HtmlElement element,final di.Injector injector) MaterialModel.fromElement(final dom.HtmlElement element,final di.Injector injector)
: super(element,injector), _observerFactory = injector.get(ModelObserverFactory) { : super(element,injector), _observerFactory = injector.get(ModelObserverFactory) {
}


@override
void attached() {
_scope = new Scope(this, mdlParentScope(this)); _scope = new Scope(this, mdlParentScope(this));
_init(); _init();

} }


// Central Element - by default this is where mdl-model can be found (element) // Central Element - by default this is where mdl-model can be found (element)
// html.Element get hub => inputElement; // html.Element get hub => inputElement;


// - EventHandler -----------------------------------------------------------------------------

void handleButtonClick() {
_logger.info("Event: handleButtonClick");
}

//- private ----------------------------------------------------------------------------------- //- private -----------------------------------------------------------------------------------


void _init() { void _init() {
_logger.fine("MaterialModel - init"); _logger.fine("MaterialModel - init");


//_logger.info("ParentScope: ${_scope.parentContext}"); _logger.info("ParentScope: ${_scope.parentContext}");
final String fieldname = element.attributes[_MaterialModelConstant.WIDGET_SELECTOR].trim(); final String fieldname = element.attributes[_MaterialModelConstant.WIDGET_SELECTOR].trim();


_scope.context = _scope.parentContext; _scope.context = _scope.parentContext;
Expand All @@ -90,9 +86,6 @@ void registerMaterialModel() {
// By default it's used as a class name. (<div class="mdl-model"></div>) // By default it's used as a class name. (<div class="mdl-model"></div>)
config.selectorType = SelectorType.ATTRIBUTE; config.selectorType = SelectorType.ATTRIBUTE;


// Sets priority to 5 - means all Components get upgraded (priority 1) before this component
config.priority = 5;

componentHandler().register(config); componentHandler().register(config);
} }


2 changes: 1 addition & 1 deletion lib/src/template/components/MaterialProperty.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MaterialProperty extends MdlComponent implements ScopeAware {
//- private ----------------------------------------------------------------------------------- //- private -----------------------------------------------------------------------------------


void _init() { void _init() {
_logger.info("MaterialProperty - init"); _logger.fine("MaterialProperty - init");


/// Recommended - add SELECTOR as class /// Recommended - add SELECTOR as class
element.classes.add(_MaterialPropertyConstant.WIDGET_SELECTOR); element.classes.add(_MaterialPropertyConstant.WIDGET_SELECTOR);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/template/components/MaterialRepeat.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class MaterialRepeat extends MdlTemplateComponent {
_addBorderIfInDebugMode(child,"red"); _addBorderIfInDebugMode(child,"red");
_logger.fine("Child to remove: $child Element ID: ${element.id}"); _logger.fine("Child to remove: $child Element ID: ${element.id}");


componentHandler().downgradeElement(child);

new Timer(new Duration(milliseconds: 30), () { new Timer(new Duration(milliseconds: 30), () {
_items.remove(item); _items.remove(item);
child.remove(); child.remove();
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ModelObserverFactory {


} else { } else {


throw new ArgumentError("${element} cannot be observed. Probably not a MdlComponent!"); throw new ArgumentError("${element} cannot be observed. Probably not a MdlComponent! Type: ${type}");


} }
} }
Expand Down

0 comments on commit f21c2e8

Please sign in to comment.