Skip to content
This repository was archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
refactor(macAutocomplete): Reduced parsing when update items
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlee44 committed Jun 27, 2014
1 parent 977353d commit 2912136
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/directives/autocomplete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ angular.module("Mac").directive "macAutocomplete", [
require: "ngModel"

link: ($scope, element, attrs, ctrl, transclude) ->
labelKey = attrs.macAutocompleteLabel or "name"
queryKey = attrs.macAutocompleteQuery or "q"
labelKey = attrs.macAutocompleteLabel or "name"
labelGetter = $parse labelKey

queryKey = attrs.macAutocompleteQuery or "q"
delay = +(attrs.macAutocompleteDelay or 800)
inside = attrs.macAutocompleteInside?

Expand Down Expand Up @@ -133,8 +135,10 @@ angular.module("Mac").directive "macAutocomplete", [
timeoutId = $timeout ->
queryData value
, delay
else

else if isMenuAppended
queryData value

else
reset()

Expand Down Expand Up @@ -224,15 +228,15 @@ angular.module("Mac").directive "macAutocomplete", [
@param {Array} data Array of data
###
updateItem = (data = []) ->
$menuScope.items.length = 0

if data.length > 0
currentAutocomplete = data

$menuScope.items = data.map (item) ->
if angular.isObject item
itemGetter = $parse labelKey

item.value ?= itemGetter(item) or ""
item.label ?= itemGetter(item) or ""
item.value ?= labelGetter(item) or ""
item.label ?= labelGetter(item) or ""
item

else
Expand Down

0 comments on commit 2912136

Please sign in to comment.