This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
feat(ng-model-options) Added ng-model-options #974
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcfc248
Added ng-model-options support
jrote1 c1a2cc4
feat(ng-model-options) Added ng-model-options
jrote1 82dd42d
Fixed some more issues
jrote1 68e21a6
Fixed some more issues
jrote1 308d8dc
Fixed some formatting
jrote1 e706b93
Fixed some formatting
jrote1 ac37d3e
Merged
jrote1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
part of angular.directive; | ||
|
||
@Decorator(selector: 'input[ng-model-options]') | ||
class NgModelOptions { | ||
int _debounceDefaultValue = 0; | ||
int _debounceBlurValue; | ||
int _debounceChangeValue; | ||
int _debounceInputValue; | ||
|
||
async.Timer _blurTimer; | ||
async.Timer _changeTimer; | ||
async.Timer _inputTimer; | ||
|
||
static const String _DEBOUNCE_DEFAULT_KEY = "default"; | ||
static const String _DEBOUNCE_BLUR_KEY = "blur"; | ||
static const String _DEBOUNCE_CHANGE_KEY = "change"; | ||
static const String _DEBOUNCE_INPUT_KEY = "input"; | ||
|
||
NgModelOptions(NodeAttrs attrs) { | ||
var jsonFormattedOptions = attrs["ng-model-options"].replaceFirst("debounce", "'debounce'") | ||
.replaceAll("'", "\""); | ||
Map options = convert.JSON.decode(jsonFormattedOptions); | ||
|
||
if(options["debounce"] is int){ | ||
_debounceDefaultValue = options["debounce"]; | ||
}else{ | ||
if (options["debounce"].containsKey(_DEBOUNCE_DEFAULT_KEY)){ | ||
_debounceDefaultValue = options["debounce"][_DEBOUNCE_DEFAULT_KEY]; | ||
} | ||
_debounceBlurValue = options["debounce"][_DEBOUNCE_BLUR_KEY]; | ||
_debounceChangeValue = options["debounce"][_DEBOUNCE_CHANGE_KEY]; | ||
_debounceInputValue = options["debounce"][_DEBOUNCE_INPUT_KEY]; | ||
} | ||
} | ||
|
||
|
||
void executeBlurFunc(func()) { | ||
var delay = _debounceBlurValue == null ? _debounceDefaultValue : _debounceBlurValue; | ||
_blurTimer = _runFuncDebounced(delay, func, _blurTimer); | ||
} | ||
|
||
void executeChangeFunc(func()) { | ||
var delay = _debounceChangeValue == null ? _debounceDefaultValue : _debounceChangeValue; | ||
_changeTimer = _runFuncDebounced(delay, func, _changeTimer); | ||
} | ||
|
||
void executeInputFunc(func()) { | ||
var delay = _debounceInputValue == null ? _debounceDefaultValue : _debounceInputValue; | ||
_inputTimer = _runFuncDebounced(delay, func, _inputTimer); | ||
} | ||
|
||
async.Timer _runFuncDebounced(int delay, func(), async.Timer timer){ | ||
if (timer != null && timer.isActive) timer.cancel(); | ||
|
||
if(delay == 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
notice ws & formatting |
||
func(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add missing {} |
||
return null; | ||
} else { | ||
return new async.Timer(new Duration(milliseconds: delay), func); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some doc about the purpose of this class would be great!