Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 82dd42d

Browse files
committed
Fixed some more issues
1 parent c1a2cc4 commit 82dd42d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

lib/directive/ng_model.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class NgModel extends NgControl implements AttachAware {
4343
Watch _watch;
4444
bool _watchCollection;
4545

46-
NgModel(this._scope, NgElement element, Injector injector, NodeAttrs attrs,
46+
NgModel(this._scope, NgElement element, Injector injector, NodeAttrs attrs,
4747
Animate animate)
48-
: super(element, injector, animate) {
48+
: super(element, injector, animate)
49+
{
4950
_expression = attrs["ng-model"];
5051
watchCollection = false;
5152

@@ -296,7 +297,8 @@ class InputCheckbox {
296297
final NgModelOptions ngModelOptions;
297298
final Scope scope;
298299

299-
InputCheckbox(dom.Element this.inputElement, this.ngModel, this.scope, this.ngTrueValue, this.ngFalseValue, this.ngModelOptions) {
300+
InputCheckbox(dom.Element this.inputElement, this.ngModel,
301+
this.scope, this.ngTrueValue, this.ngFalseValue, this.ngModelOptions) {
300302
ngModel.render = (value) {
301303
scope.rootScope.domWrite(() {
302304
inputElement.checked = ngTrueValue.isValue(value);

lib/directive/ng_model_options.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,46 @@ class NgModelOptions {
77
int _debounceChangeValue = null;
88
int _debounceInputValue = null;
99

10-
static const String _debounceDefaultKey = "default";
11-
static const String _debounceBlurKey = "blur";
12-
static const String _debounceChangeKey = "change";
13-
static const String _debounceInputKey = "input";
10+
static const String DEBOUNCE_DEFAULT_KEY = "default";
11+
static const String DEBOUNCE_BLUR_KEY = "blur";
12+
static const String DEBOUNCE_CHANGE_KEY = "change";
13+
static const String DEBOUNCE_INPUT_KEY = "input";
1414

1515
NgModelOptions(NodeAttrs attrs) {
16-
print("options: " + attrs["ng-model-options"].replaceFirst("debounce", "'debounce'").replaceAll("'", "\""));
1716
Map options = convert.JSON.decode(attrs["ng-model-options"].replaceFirst("debounce", "'debounce'").replaceAll("'", "\""));
1817

19-
if (options["debounce"].containsKey(_debounceDefaultKey)) _debounceDefaultValue = options["debounce"][_debounceDefaultKey];
20-
if (options["debounce"].containsKey(_debounceBlurKey)) _debounceBlurValue = options["debounce"][_debounceBlurKey];
21-
if (options["debounce"].containsKey(_debounceChangeKey)) _debounceChangeValue = options["debounce"][_debounceChangeKey];
22-
if (options["debounce"].containsKey(_debounceInputKey)) _debounceInputValue = options["debounce"][_debounceInputKey];
18+
if (options["debounce"].containsKey(DEBOUNCE_DEFAULT_KEY)) _debounceDefaultValue = options["debounce"][DEBOUNCE_DEFAULT_KEY];
19+
_debounceBlurValue = options["debounce"][DEBOUNCE_BLUR_KEY];
20+
_debounceChangeValue = options["debounce"][DEBOUNCE_CHANGE_KEY];
21+
_debounceInputValue = options["debounce"][DEBOUNCE_INPUT_KEY];
2322
}
2423

2524
async.Timer _blurTimer;
2625
void executeBlurFunc(func()) {
27-
if (_blurTimer != null && !_blurTimer.isActive) _blurTimer.cancel();
28-
2926
var delay = _debounceBlurValue == null ? _debounceDefaultValue : _debounceBlurValue;
30-
_runFuncDebounced(delay, func, (timer)=>_blurTimer = timer);
27+
_runFuncDebounced(delay, func, (timer)=>_blurTimer = timer,_blurTimer);
3128
}
3229

3330
async.Timer _changeTimer;
3431
void executeChangeFunc(func()) {
35-
if (_changeTimer != null && !_changeTimer.isActive) _changeTimer.cancel();
36-
3732
var delay = _debounceChangeValue == null ? _debounceDefaultValue : _debounceChangeValue;
38-
_runFuncDebounced(delay, func, (timer)=>_changeTimer = timer);
33+
_runFuncDebounced(delay, func, (timer)=>_changeTimer = timer, _changeTimer);
3934
}
4035

4136
async.Timer _inputTimer;
4237
void executeInputFunc(func()) {
43-
if (_inputTimer != null && _inputTimer.isActive) _inputTimer.cancel();
44-
4538
var delay = _debounceInputValue == null ? _debounceDefaultValue : _debounceInputValue;
46-
_runFuncDebounced(delay, func, (timer) => _inputTimer = timer);
39+
_runFuncDebounced(delay, func, (timer) => _inputTimer = timer, _inputTimer);
4740
}
4841

49-
void _runFuncDebounced(int delay, func(), setTimer(async.Timer timer)){
50-
if(delay == 0)
42+
void _runFuncDebounced(int delay, func(), setTimer(async.Timer timer), async.Timer timer){
43+
if (timer != null && timer.isActive) timer.cancel();
44+
45+
if(delay == 0){
5146
func();
52-
else
47+
}
48+
else{
5349
setTimer(new async.Timer(new Duration(milliseconds: delay), func));
50+
}
5451
}
5552
}

0 commit comments

Comments
 (0)