<commit_before>import { app } from "../_app.module";

app.directive("keys", function(){
    //DDO = Directive Definition Object - read more https://docs.angularjs.org/api/ng/service/$compile
    var DDO = {
        restrict: "A",
        scope: {
            onEsc: "&"
        },
        controller: function($scope, $element, $attrs) {
            $element.on("keyup", onKeyUp);

            function onKeyUp(ev) {
                //console.log(ev);
                if (ev.which==27) //ESC 
                    $scope.$apply( $scope.onEsc({$event: ev}) );
            }

            $scope.$on("$destroy", function() { //LIFE-CYCLE $onDestroy
                $element.off("keyup", onKeyUp); //PREVENT MEMORY LEAK!!
            });
        }
    }
    return DDO;
})<commit_msg>1.3 TS refactor directive -> function():IDirective - controller -> class Ctrl + constructor + static $inject - Add :Types for intellisence + typecheck + define local _Scope/EventHandler<commit_after>import { app } from "../_app.module";

export function keysDir(): angular.IDirective {
    //DDO = Directive Definition Object - read more https://docs.angularjs.org/api/ng/service/$compile
    return {
        restrict: "A",
        scope: {
            onEsc: "&"
        },
        controller: keysCtrl
    }
}

type EventHandler<T> = (payload: {$event: T}) => any;
interface _Scope extends angular.IScope {
    onEsc: EventHandler<any>;
}

class keysCtrl {
    static $inject = ["$scope", "$element", "$attrs"];
    constructor($scope: _Scope, $element: angular.IAugmentedJQuery , $attrs: angular.IAttributes) {
        $element.on("keyup", onKeyUp);

        function onKeyUp(ev) {
            if (ev.which==27) //ESC 
                $scope.$apply( $scope.onEsc({$event: ev}) );
        }

        $scope.$on("$destroy", function() { //LIFE-CYCLE $onDestroy
            $element.off("keyup", onKeyUp); //PREVENT MEMORY LEAK!!
        });
    }
}



app.directive("keys", keysDir);
{'fraction_non_alphanumeric': 0.1614052953156823, 'fraction_numerical': 0.003054989816700611, 'mean_word_length': 2.2003257328990227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '2109340', 'n_tokens_mistral': 621, 'n_tokens_neox': 595, 'n_words': 131}