本文整理汇总了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 }));
}
示例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
)
);
}
示例3: mixin
['node', 'browser'].forEach(key => {
if (child[key]) {
if (config[key]) {
mixin(config[key], child[key]);
} else {
config[key] = child[key];
}
}
});
示例4: constructor
constructor(options: ServerOptions) {
mixin(
this,
{
basePath: '.',
runInSync: false
},
options
);
}
示例5: constructor
constructor(options?: TunnelOptions) {
super(
mixin(
{
auth: ''
},
options || {}
)
);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
});
}
}