<commit_before>'use strict';

angular.module('typeahead.directives', []);

angular.module('typeahead.directives', []).directive('ngTypeahead', function ($parse) {
    return {
        restrict: 'A',
        scope: {
            filter: '&',
            ngModel: '=',
            selectedItem: '='
        },
        link: function (scope, element, attrs) {
            element.typeahead({
                valueKey: attrs.valueKey,
                remote: {
                    url: attrs.url,
                    cache: false,
                    filter: function (parsedResponse) {
                        if (attrs.filter) {
                            return scope.filter({ parsedResponse: parsedResponse });
                        }

                        return parsedResponse;
                    }
                },
            });

            scope.$watch('selectedItem', function (newValue) {
                if (newValue === '') {
                    element.typeahead('setQuery', '');
                }
            }, true);

            element.on('change', function (event) {
                if (attrs.ngModel) {
                    scope.ngModel = $(event.target).val();
                }

                scope.$apply();
            });

            element.on('typeahead:selected', function (event, datum, dataset) {
                scope.selectedItem = datum;

                if (attrs.ngModel) {
                    scope.ngModel = $(event.target).val();
                }

                scope.$apply();
            });

            element.on('typeahead:autocompleted', function (event, datum, dataset) {
                scope.selectedItem = datum;<commit_msg>added limit and rateLimitWait as optional construct elements.<commit_after>'use strict';

angular.module('typeahead.directives', []);

angular.module('typeahead.directives', []).directive('ngTypeahead', function ($parse) {
    return {
        restrict: 'A',
        scope: {
            filter: '&',
            ngModel: '=',
            selectedItem: '=',
            limit: '=',
            rateLimitWait: '='
        },
        link: function (scope, element, attrs) {
            var construct = {
                valueKey: attrs.valueKey,
                remote: {
                    url: attrs.url,
                    cache: false,
                    filter: function (parsedResponse) {
                        if (attrs.filter) {
                            return scope.filter({ parsedResponse: parsedResponse });
                        }

                        return parsedResponse;
                    }
                }
            };

            if (attrs.limit) {
                construct.limit = attrs.limit;
            }

            if (attrs.rateLimitWait) {
                construct.remote.rateLimitWait = attrs.rateLimitWait;
            }

            element.typeahead(construct);

            scope.$watch('selectedItem', function (newValue) {
                if (newValue === '') {
                    element.typeahead('setQuery', '');
                }
            }, true);

            element.on('change', function (event) {
                if (attrs.ngModel) {
                    scope.ngModel = $(event.target).val();
                }

                scope.$apply();
            });

            element.on('typeahead:selected', function (event, datum, dataset) {
                scope.selectedItem = datum;

                if (attrs.ngModel) {
                    scope.ngModel = $(event.target).val();
                }

                scope.$apply();
            });

            element.on('typeahead:autocompleted', function (event, datum, dataset) {
                scope.selectedItem = datum;
{'fraction_non_alphanumeric': 0.12185324049276915, 'fraction_numerical': 0.0, 'mean_word_length': 1.1931884908984145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6396195', 'n_tokens_mistral': 937, 'n_tokens_neox': 866, 'n_words': 162}