Permalink
Browse files

feature: MdlComponent and MaterialDialog share the same MdlEventListe…

…ner-Mixin to add eventStreams for downgrading the component
  • Loading branch information...
MikeMitterer committed Jan 20, 2016
1 parent c468342 commit 55f05b8855fe9c2cc9b8c7fa2814d7b080c2131c
@@ -69,12 +69,13 @@
height: $data-table-row-height;
border-left : $data-table-dividers;
border-right : $data-table-dividers;
border-left : $data-table-dividers;
border-right : $data-table-dividers;
border-bottom : $data-table-dividers;
&:not(:last-child) {
border-bottom: $data-table-dividers;
}
//&:not(:last-child) {
// border-bottom: $data-table-dividers;
//}
@include material-animation-default(0.28s);
transition-property: background-color;
View
@@ -38,9 +38,10 @@ part "src/core/interfaces.dart";
part "src/core/mock.dart";
part "src/core/utils.dart";
part "src/core/MdlComponent.dart";
part "src/core/MdlComponentHandler.dart";
part "src/core/MdlConfig.dart";
part "src/core/MdlComponent.dart";
part "src/core/MdlEventListener.dart";
abstract class MdlDataConsumer {
void consume(final data);
@@ -19,14 +19,9 @@
part of mdlcore;
abstract class MdlComponent {
abstract class MdlComponent extends Object with MdlEventListener {
final Logger _logger = new Logger('mdlcore.MdlComponent');
/// All the registered Events - helpful for automatically downgrading the element
/// Sample:
/// eventStreams.add(input.onFocus.listen( _onFocus));
final List<StreamSubscription> eventStreams = new List<StreamSubscription>();
/**
* If you want to you DI define your bindings like this:
* class StyleguideModule extends di.Module {
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2016, Michael Mitterer (office@mikemitterer.at),
* IT-Consulting and Development Limited.
*
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
part of mdlcore;
/// Mixin to cleanup StreamSubscriptions for [MdlComponent]s and
/// [MaterialDialog]s
///
/// abstract class MdlComponent extends Object with MdlEventListener {
/// ...
/// }
///
/// class MyComponent extends MdlComponent {
/// ...
/// void _init() {
/// ...
/// eventStreams.add(
/// myButton.onClick.listen((_) {
/// ...
/// });
/// }
/// }
abstract class addMdlEventListener {
/// All the registered Events - helpful for automatically downgrading the element
/// Sample:
/// eventStreams.add(input.onFocus.listen( _onFocus));
final List<StreamSubscription> eventStreams = new List<StreamSubscription>();
//- private -----------------------------------------------------------------------------------
}
@@ -87,7 +87,7 @@ class DialogConfig {
}
/// HTML-Part of MdlDialog.
abstract class MaterialDialog extends Object with TemplateComponent implements ScopeAware {
abstract class MaterialDialog extends Object with TemplateComponent, MdlEventListener implements ScopeAware {
final Logger _logger = new Logger('mdldialog.DialogElement');
static const _MaterialDialogCssClasses _cssClasses = const _MaterialDialogCssClasses();
@@ -116,6 +116,9 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S
Scope _scope;
/// Html-Representation of this dialog - will be set in show (after rendering)
dom.HtmlElement dialog = null;
MaterialDialog(this._config) {
Validate.notNull(_config);
_scope = new Scope(this,null);
@@ -150,7 +153,7 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S
// _autoIncrementID must be on top of this block! - will be used by _elementID
_autoIncrementID = idCounter;
final dom.HtmlElement dialog = _dialogContainer.children.last;
dialog = _dialogContainer.children.last;
dialog.id = _elementID;
// notification + snackbar is not _MaterialDialogComponent
@@ -190,6 +193,7 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S
}
Future close(final MdlDialogStatus status) {
_downgrade();
_removeEscListener();
void _resetTimer() {
@@ -369,6 +373,17 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S
}
}
/// Cancels all the registered streams
/// called from within close-function
void _downgrade() {
eventStreams.forEach((final StreamSubscription stream) {
if(stream != null) {
stream.cancel();
}
});
eventStreams.clear();
}
Renderer get _renderer {
final TemplateRenderer templateRenderer = componentFactory().injector.get(TemplateRenderer);
templateRenderer.appendNewNodes = _config.appendNewDialog;

0 comments on commit 55f05b8

Please sign in to comment.