當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Container.makeGlobal方法代碼示例

本文整理匯總了TypeScript中aurelia-dependency-injection.Container.makeGlobal方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Container.makeGlobal方法的具體用法?TypeScript Container.makeGlobal怎麽用?TypeScript Container.makeGlobal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aurelia-dependency-injection.Container的用法示例。


在下文中一共展示了Container.makeGlobal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

    it("should do things on things", () => {
        initialize();
        // type '1', '2', 'left', 'left', 'v' should result in '12'
        let inputElement = document.createElement("input");
        let container = new Container();
        container.makeGlobal();
        container.registerInstance(Element, inputElement);
        let engine = container.get(TemplatingEngine)
        let mask = "(999) 999-9999";
        let maskedInput = engine.createViewModelForUnitTest(MaskedInput, {
            "mask": mask
        });
        maskedInput.isFocused = () => true;
        maskedInput.isHidden = () => false;
        maskedInput.value = "";
        expect(maskedInput.mask).toBe(mask);
        expect(maskedInput.value).toBe("");
        expect(inputElement.value).toBe("");
        expect(maskedInput.element).toBe(inputElement);
        expect(maskedInput.getCaretPosition()).toBe(0);

        maskedInput.attached();
        expect(maskedInput.inputElement).toBe(inputElement);
        expect(inputElement.value).toBe("(___) ___-____");
        expect(maskedInput.caretPos).toBe(1);
        expect(maskedInput.getCaretPosition()).toBe(1);
        let focusEvent = null;
        let inputEvent = null;
        let keyupEvent = null;

        focusEvent = makeFocusEvent();
        maskedInput.onFocus(focusEvent);
        expect(getCursor(inputElement)).toBe(1);

        inputElement.value = "(1___) ___-____";
        setCursor(inputElement, 2);
        inputEvent = makeInputEvent();
        maskedInput.onInput(inputEvent);
        keyupEvent = makeKeyupEvent("1");
        maskedInput.onKeyUp(keyupEvent);
        expect(inputElement.value).toBe("(1__) ___-____");
        expect(maskedInput.value).toBe("1");
        expect(maskedInput.oldValue).toBe("(1__) ___-____");
        expect(maskedInput.oldValueUnmasked).toBe("1");
        expect(getCursor(inputElement)).toBe(2);

        inputElement.value = "(12__) ___-____";
        inputEvent = makeInputEvent();
        maskedInput.onInput(inputEvent);
        keyupEvent = makeKeyupEvent("2");
        maskedInput.onKeyUp(keyupEvent);
        expect(inputElement.value).toBe("(12_) ___-____");
        expect(maskedInput.value).toBe("12");
        expect(maskedInput.oldValue).toBe("(12_) ___-____");
        expect(maskedInput.oldValueUnmasked).toBe("12");
        expect(getCursor(inputElement)).toBe(3);

        setCursor(inputElement, 2);
        expect(inputElement.value).toBe("(12_) ___-____");
        inputEvent = makeInputEvent();
        maskedInput.onInput(inputEvent);
        keyupEvent = makeKeyupEvent(LEFT);
        maskedInput.onKeyUp(keyupEvent);
        expect(inputElement.value).toBe("(12_) ___-____");
        expect(maskedInput.value).toBe("12");
        expect(maskedInput.oldValue).toBe("(12_) ___-____");
        expect(maskedInput.oldValueUnmasked).toBe("12");
        expect(getCursor(inputElement)).toBe(2);

        setCursor(inputElement, 1);
        expect(inputElement.value).toBe("(12_) ___-____");
        maskedInput.onInput(inputEvent);
        maskedInput.onKeyUp(keyupEvent);
        expect(inputElement.value).toBe("(12_) ___-____");
        expect(maskedInput.value).toBe("12");
        expect(maskedInput.oldValue).toBe("(12_) ___-____");
        expect(maskedInput.oldValueUnmasked).toBe("12");
        expect(maskedInput.caretPos).toBe(1);
        expect(getCursor(inputElement)).toBe(1);

        inputElement.value = "(v12__) ___-____";
        setCursor(inputElement, 2);
        inputEvent = makeInputEvent();
        maskedInput.onInput(inputEvent);
        keyupEvent = makeKeyupEvent('v');
        maskedInput.onKeyUp(keyupEvent);
        expect(inputElement.value).toBe("(12_) ___-____");
        expect(maskedInput.value).toBe("12");
        expect(getCursor(inputElement)).toBe(2);
    });
開發者ID:tianyawy,項目名稱:aurelia-mask,代碼行數:90,代碼來源:masked-input.spec.ts

示例2: Container

import { Database } from './database/Database';
import * as errorHandlers from './middleware/errorHandlers';
import * as queryHandlers from './middleware/queryHandlers';
import * as requestHandlers from './middleware/requestHandlers';
import { ServiceManager } from './services/ServiceManager';
import './utils/ObjectExtensions'; // add object extension methods;

const env = process.env.NODE_ENV || 'dev';

const PUBLIC_DIRECTORY = 'www';
const PORT_KEY = 'port';
const DEFAULT_PORT = 443;

// set up the dependency injection container
const container: Container = new Container();
container.makeGlobal();

const appConfig: any = new AppConfig('./config.json');
container.registerInstance(AppConfig, appConfig);

/*******  set up logging   ********/
const logOptions = appConfig.logging;
logOptions.name = appConfig.name;

const log = new Logger(logOptions);

container.registerInstance(Logger, log);
/********* end set up logging   ********/

let options: DbOptions = appConfig.database;
開發者ID:weagle08,項目名稱:node-start,代碼行數:30,代碼來源:server.ts


注:本文中的aurelia-dependency-injection.Container.makeGlobal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。