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

Commit

Permalink
feature: MdlComponent and MaterialDialog share the same MdlEventListe…
Browse files Browse the repository at this point in the history
…ner-Mixin to add eventStreams for downgrading the component
  • Loading branch information
MikeMitterer committed Jan 20, 2016
1 parent c468342 commit 55f05b8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
11 changes: 6 additions & 5 deletions lib/assets/styles/data-table/_data-tableex.scss
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@


height: $data-table-row-height; height: $data-table-row-height;


border-left : $data-table-dividers; border-left : $data-table-dividers;
border-right : $data-table-dividers; border-right : $data-table-dividers;
border-bottom : $data-table-dividers;


&:not(:last-child) { //&:not(:last-child) {
border-bottom: $data-table-dividers; // border-bottom: $data-table-dividers;
} //}


@include material-animation-default(0.28s); @include material-animation-default(0.28s);
transition-property: background-color; transition-property: background-color;
Expand Down
3 changes: 2 additions & 1 deletion lib/mdlcore.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ part "src/core/interfaces.dart";
part "src/core/mock.dart"; part "src/core/mock.dart";
part "src/core/utils.dart"; part "src/core/utils.dart";


part "src/core/MdlComponent.dart";
part "src/core/MdlComponentHandler.dart"; part "src/core/MdlComponentHandler.dart";
part "src/core/MdlConfig.dart"; part "src/core/MdlConfig.dart";
part "src/core/MdlComponent.dart"; part "src/core/MdlEventListener.dart";


abstract class MdlDataConsumer { abstract class MdlDataConsumer {
void consume(final data); void consume(final data);
Expand Down
7 changes: 1 addition & 6 deletions lib/src/core/MdlComponent.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@


part of mdlcore; part of mdlcore;


abstract class MdlComponent { abstract class MdlComponent extends Object with MdlEventListener {
final Logger _logger = new Logger('mdlcore.MdlComponent'); 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: * If you want to you DI define your bindings like this:
* class StyleguideModule extends di.Module { * class StyleguideModule extends di.Module {
Expand Down
47 changes: 47 additions & 0 deletions lib/src/core/MdlEventListener.dart
Original file line number Original file line Diff line number Diff line change
@@ -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 -----------------------------------------------------------------------------------
}
19 changes: 17 additions & 2 deletions lib/src/dialog/MaterialDialog.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DialogConfig {
} }


/// HTML-Part of MdlDialog. /// 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'); final Logger _logger = new Logger('mdldialog.DialogElement');


static const _MaterialDialogCssClasses _cssClasses = const _MaterialDialogCssClasses(); static const _MaterialDialogCssClasses _cssClasses = const _MaterialDialogCssClasses();
Expand Down Expand Up @@ -116,6 +116,9 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S


Scope _scope; Scope _scope;


/// Html-Representation of this dialog - will be set in show (after rendering)
dom.HtmlElement dialog = null;

MaterialDialog(this._config) { MaterialDialog(this._config) {
Validate.notNull(_config); Validate.notNull(_config);
_scope = new Scope(this,null); _scope = new Scope(this,null);
Expand Down Expand Up @@ -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 must be on top of this block! - will be used by _elementID
_autoIncrementID = idCounter; _autoIncrementID = idCounter;


final dom.HtmlElement dialog = _dialogContainer.children.last; dialog = _dialogContainer.children.last;
dialog.id = _elementID; dialog.id = _elementID;


// notification + snackbar is not _MaterialDialogComponent // notification + snackbar is not _MaterialDialogComponent
Expand Down Expand Up @@ -190,6 +193,7 @@ abstract class MaterialDialog extends Object with TemplateComponent implements S
} }


Future close(final MdlDialogStatus status) { Future close(final MdlDialogStatus status) {
_downgrade();
_removeEscListener(); _removeEscListener();


void _resetTimer() { void _resetTimer() {
Expand Down Expand Up @@ -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 { Renderer get _renderer {
final TemplateRenderer templateRenderer = componentFactory().injector.get(TemplateRenderer); final TemplateRenderer templateRenderer = componentFactory().injector.get(TemplateRenderer);
templateRenderer.appendNewNodes = _config.appendNewDialog; templateRenderer.appendNewNodes = _config.appendNewDialog;
Expand Down

0 comments on commit 55f05b8

Please sign in to comment.