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


TypeScript lang.mixin函數代碼示例

本文整理匯總了TypeScript中@dojo/core/lang.mixin函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mixin函數的具體用法?TypeScript mixin怎麽用?TypeScript mixin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: getConfig

export function getConfig(fileOrArgv?: string | string[], argv?: string[]) {
	let args: { [key: string]: any } = {};
	let file = typeof fileOrArgv === 'string' ? fileOrArgv : undefined;
	argv = Array.isArray(fileOrArgv) ? fileOrArgv : argv;
	const userArgs = (argv || process.argv).slice(2);

	if (process.env['INTERN_ARGS']) {
		mixin(args, parseArgs(parse(process.env['INTERN_ARGS'] || '')));
	}

	if (userArgs.length > 0) {
		mixin(args, parseArgs(userArgs));
	}

	if (file) {
		args.config = file;
	}

	let load: Task<{ [key: string]: any }>;

	if (args.config) {
		// If a config parameter was provided, load it and mix in any other
		// command line args.
		const { configFile, childConfig } = splitConfigPath(args.config, sep);
		file = resolve(configFile || 'intern.json');
		load = loadConfig(file, loadText, args, childConfig);
	} else {
		// If no config parameter was provided, try 'intern.json', or just
		// resolve to the original args
		file = resolve('intern.json');
		load = loadConfig(file, loadText, args, undefined).catch(
			(error: NodeJS.ErrnoException) => {
				if (error.code === 'ENOENT') {
					file = undefined;
					return args;
				}
				throw error;
			}
		);
	}

	return load
		.then(config => {
			// If a basePath wasn't set in the config or via a query arg, and we
			// have a config file path, use that.
			if (file) {
				config.basePath = getBasePath(
					file,
					config.basePath,
					isAbsolute,
					sep
				);
			}
			return config;
		})
		.then(config => ({ config, file }));
}
開發者ID:devpaul,項目名稱:intern,代碼行數:57,代碼來源:util.ts

示例2: mockPath

export function mockPath(
	properties: { [P in keyof typeof path]?: typeof path[P] } = {}
) {
	return createMock<typeof path>(
		mixin(
			{
				resolve(path: string) {
					// Normalize fake directory names by adding a trailing '/'
					if (!/\.\w+$/.test(path) && path[path.length - 1] !== '/') {
						return path + '/';
					}
					return path;
				},

				join(...args: any[]) {
					return path.join(...args);
				},

				basename(base: string, ...args: any[]) {
					return path.basename(base, ...args);
				},

				normalize(base: string, ...args: any[]) {
					return path.normalize(base, ...args);
				}
			},
			properties
		)
	);
}
開發者ID:devpaul,項目名稱:intern,代碼行數:30,代碼來源:nodeMocks.ts

示例3: mixin

						['node', 'browser'].forEach(key => {
							if (child[key]) {
								if (config[key]) {
									mixin(config[key], child[key]);
								} else {
									config[key] = child[key];
								}
							}
						});
開發者ID:jason0x43,項目名稱:intern,代碼行數:9,代碼來源:util.ts

示例4: constructor

	constructor(options: ServerOptions) {
		mixin(
			this,
			{
				basePath: '.',
				runInSync: false
			},
			options
		);
	}
開發者ID:jason0x43,項目名稱:intern,代碼行數:10,代碼來源:Server.ts

示例5: constructor

	constructor(options?: TunnelOptions) {
		super(
			mixin(
				{
					auth: ''
				},
				options || {}
			)
		);
	}
開發者ID:devpaul,項目名稱:digdug,代碼行數:10,代碼來源:NullTunnel.ts

示例6: createTest

export function createTest(properties?: { [P in keyof Test]?: Test[P] }) {
	let test = new Test({
		name: 'test',
		test() {}
	});
	if (properties) {
		test = Object.create(test);
		mixin(test, properties || {});
	}
	return test;
}
開發者ID:jason0x43,項目名稱:intern,代碼行數:11,代碼來源:factories.ts

示例7: createSuite

export function createSuite(properties?: { [P in keyof Suite]?: Suite[P] }) {
	let suite = new Suite({
		name: 'suite',
		executor: mockExecutor()
	});
	if (properties) {
		suite = Object.create(suite);
		mixin(suite, properties || {});
	}
	return suite;
}
開發者ID:jason0x43,項目名稱:intern,代碼行數:11,代碼來源:factories.ts

示例8: mockFs

export function mockFs(
	fileData: FileData = Object.create(null),
	properties: MockFsProperties = {}
) {
	function missingFile(path: string) {
		return assign(
			new Error(
				`Error: ENOENT: no such file or directory stat '${path}' errno -2`
			),
			{
				code: 'ENOENT',
				errno: -2,
				syscall: 'stat',
				path
			}
		);
	}

	const mock = createMock<MockFs>(
		mixin(
			{
				__fileData: fileData,

				stat(path: string, callback: StatCallback) {
					const entry = mock.__fileData[path];
					if (!entry) {
						callback(
							missingFile(path),
							new MockStats(path, undefined)
						);
					} else {
						callback(undefined, new MockStats(path, entry.type));
					}
				},

				readFile(
					path: string,
					_encoding: string,
					callback: FsCallback
				) {
					const entry = mock.__fileData[path];
					if (!entry) {
						callback(missingFile(path), undefined);
					} else {
						callback(undefined, entry.data);
					}
				}
			},
			properties
		)
	);
	return mock;
}
開發者ID:devpaul,項目名稱:intern,代碼行數:53,代碼來源:nodeMocks.ts

示例9: getConfig

export function getConfig(configFile?: string) {
	let args: { [key: string]: any } = {};

	if (process.env['INTERN_ARGS']) {
		mixin(args, parseArgs(parse(process.env['INTERN_ARGS'])));
	}

	if (process.argv.length > 2) {
		mixin(args, parseArgs(process.argv.slice(2)));
	}

	if (configFile) {
		args.config = configFile;
	}

	if (args.config) {
		// If a config parameter was provided, load it and mix in any other
		// command line args.
		const { configFile, childConfig } = splitConfigPath(args.config, sep);
		return loadConfig(
			configFile || 'intern.json',
			loadText,
			args,
			childConfig
		);
	} else {
		// If no config parameter was provided, try 'intern.json', or just
		// resolve to the original args
		return loadConfig(
			'intern.json',
			loadText,
			args
		).catch((error: NodeJS.ErrnoException) => {
			if (error.code === 'ENOENT') {
				return args;
			}
			throw error;
		});
	}
}
開發者ID:jason0x43,項目名稱:intern,代碼行數:40,代碼來源:util.ts


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