<commit_before>const mod = angular.module('pa.animations.class', []),
    directiveName = 'paClass';

mod.directive(directiveName, ($animate) => {
    return {
        restrict: 'A',
        require: [],
        link(scope, element, attrs, controllers) {
            const selfController = controllers[0],
                routerController = controllers[1],
                animationName = attrs.paAnimationName || directiveName,
                className = attrs[directiveName] || directiveName,
                classNameStart = className + '--start',
                status = attrs.paStatus,
                undo = attrs.paUndo,

                setStatus = newStatus => {
                    if (status) {
                        scope[status] = newStatus;
                    }
                },
                setUp = () => {
                    setStatus('READY');
                    element.addClass(classNameStart);
                };

            if (routerController) {
                routerController.register(animationName, selfController);
            }

            setUp();

            scope.$watch(attrs.paActive, (newVal) => {
                if (newVal) {
                    setStatus('RUNNING');

                    $animate.removeClass(
                        element,
                        classNameStart
                    ).then(() => {
                        setStatus('FINISHED');
                        // Used to be necessary in angular 1.3. Tests fail
                        // when called, need to check on demo version.
                        // scope.$apply();
                    });
                } else if (undo) {
                    setUp();
                }

            });

        }
    };
});

export default mod;<commit_msg>Add paClass Controller APIs #7<commit_after>const mod = angular.module('pa.animations.class', []),
    directiveName = 'paClass';

mod.directive(directiveName, ($animate) => {
    return {
        restrict: 'A',
        require: [directiveName, '^?paRouter'],
        controller($q, $scope, $attrs, $element) {
            const className = $attrs[directiveName] || directiveName,
                classNameStart = className + '--start',
                statusScopeVar = $attrs.paStatus;

            let status = '',
                deferred,


                resolve = (...args) => {
                    return deferred && deferred.resolve(args);
                },

                setStatus = newStatus => {
                    if (statusScopeVar) {
                        $scope[statusScopeVar] = newStatus;
                    }
                    status = newStatus;
                },

                setUp = () => {
                    setStatus('READY');
                    $element.addClass(classNameStart);
                },

                clear = () => {
                    let clearDeferred = $q.defer();
                    clearDeferred.resolve();

                    if (status === 'RUNNING') {
                        //TODO we might want to reject this to handle this
                        //usecase, needs more cowbell
                        resolve();
                    }

                    setUp();

                    return clearDeferred.promise;
                },

                runAnimation = () => {
                    setStatus('RUNNING');

                    $animate.removeClass(
                        $element,
                        classNameStart
                    ).then(() => {
                        setStatus('FINISHED');
                        resolve();
                    });

                },
                play = () => {
                    if (status === 'READY') {
                        deferred = $q.defer();
                        runAnimation();
                    }
                    return deferred.promise;
                };

            //APIs used by linking function
            this.setUp = setUp;
            this.runAnimation = runAnimation;

            //Public APIs
            this.play = play;
            this.resolve = resolve;
            this.clear = clear;

        },
        link(scope, element, attrs, controllers) {
            const selfController = controllers[0],
                routerController = controllers[1],
                animationName = attrs.paAnimationName || directiveName;

            if (routerController) {
                routerController.register(animationName, selfController);
            }

            selfController.setUp();
            if (attrs.paActive) {
                scope.$watch(attrs.paActive, (newVal) => {
                    if (newVal) {
                        selfController.runAnimation();
                    } else if (attrs.paUndo) {
                        selfController.setUp();
                    }
                });
            }

        }
    };
});

export default mod;
{'fraction_non_alphanumeric': 0.10505994716521032, 'fraction_numerical': 0.001422475106685633, 'mean_word_length': 1.0313660751134957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7374525', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1056, 'n_words': 221}