<commit_before>/// <reference path="../../../lib/DefinitelyTyped/angularjs/angular.d.ts"/>

import AdhHttp = require("../Http/Http");
import AdhUser = require("../User/User");


export class Service {
    constructor(private adhHttp : AdhHttp.Service<any>, private adhUser : AdhUser.Service) {}

    /**
     * Set result of OPTIONS request to scope.key and keep it fresh.
     * Before sending async http requests, initialize scope.key with
     * all-falses in order to avoid exceptions when scope.key is
     * accessed in javascript code (rather than ng templates).
     */
    public bindScope(scope : ng.IScope, path : string, key = "options") : ng.IPromise<void> {
        var self : Service = this;

        scope[key] = AdhHttp.emptyOptions;

        var update = () => {
            return self.adhHttp.options(path).then((options : AdhHttp.IOptions) => {
                scope[key] = options;
            });
        };

        // FIXME: It would be better if adhUser would notify us on change
        scope.$watch(() => self.adhUser.userPath, update);

        return update();
    }
}


export var moduleName = "adhPermissions";

export var register = (angular) => {
    angular
        .module(moduleName, [
            AdhHttp.moduleName,
            AdhUser.moduleName
        ])
        .service("adhPermissions", ["adhHttp", "adhUser", Service]);
};
<commit_msg>adhPermissions.bindScope: path may be a function<commit_after>/// <reference path="../../../lib/DefinitelyTyped/angularjs/angular.d.ts"/>

import AdhHttp = require("../Http/Http");
import AdhUser = require("../User/User");


export class Service {
    constructor(private adhHttp : AdhHttp.Service<any>, private adhUser : AdhUser.Service) {}

    /**
     * Set result of OPTIONS request to scope.key and keep it fresh.
     * Before sending async http requests, initialize scope.key with
     * all-falses in order to avoid exceptions when scope.key is
     * accessed in javascript code (rather than ng templates).
     */
    public bindScope(scope : ng.IScope, path : Function, key?) : void;
    public bindScope(scope : ng.IScope, path : string, key?) : void;
    public bindScope(scope, path, key = "options") {
        var self : Service = this;

        var pathFn = typeof path === "string" ? () => path : path;
        var pathString : string;

        scope[key] = AdhHttp.emptyOptions;

        var update = () => {
            if (pathString) {
                return self.adhHttp.options(pathString).then((options : AdhHttp.IOptions) => {
                    scope[key] = options;
                });
            }
        };

        // FIXME: It would be better if adhUser would notify us on change
        scope.$watch(() => self.adhUser.userPath, update);
        scope.$watch(pathFn, (p : string) => {
            pathString = p;
            update();
        });
    }
}


export var moduleName = "adhPermissions";

export var register = (angular) => {
    angular
        .module(moduleName, [
            AdhHttp.moduleName,
            AdhUser.moduleName
        ])
        .service("adhPermissions", ["adhHttp", "adhUser", Service]);
};

{'fraction_non_alphanumeric': 0.13208147676639084, 'fraction_numerical': 0.0, 'mean_word_length': 2.3224101479915435, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, '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': '4906802', 'n_tokens_mistral': 907, 'n_tokens_neox': 878, 'n_words': 248}