本文整理汇总了TypeScript中lodash.assign函数的典型用法代码示例。如果您正苦于以下问题:TypeScript assign函数的具体用法?TypeScript assign怎么用?TypeScript assign使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assign函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: find
/**
* Find documents based on filter.
*
* @param {String} collection Collection name
* @param {Object} filter Key, value Object
* @param {Object} options options.limit, options.offset
* @return {Promise<any>} Promise for list of found documents.
*/
async find(collectionName: string, filter: any, options: any): Promise<any> {
if (_.isNil(collectionName) || !_.isString(collectionName) ||
_.isEmpty(collectionName)) {
throw new Error('invalid or missing collection argument');
}
let filterQuery: any = filter || {};
const opts = options || {};
let filterResult: any;
let bindVars: any;
let customFilter = '';
// checking if a custom query should be used
if (!_.isEmpty(opts.customQueries)) {
for (let queryName of opts.customQueries) {
if (!this.customQueries.has(queryName)) {
throw new Error(`custom query ${query} not found`);
}
const customQuery = this.customQueries.get(queryName);
if (customQuery.type == 'query') {
// standalone query
const result: ArrayCursor = await query(this.db, collectionName, customQuery.code, opts.customArguments || {}); // Cursor object
return result.all(); // TODO: paginate
} else {
// filter
customFilter += ` ${customQuery.code} `;
}
}
}
if (!_.isArray(filterQuery)) {
filterQuery = [filterQuery];
}
if (_.isEmpty(filterQuery[0])) {
filterQuery = true;
}
else {
filterResult = buildFilter(filterQuery);
filterQuery = filterResult.q;
}
let sortQuery = buildSorter(opts);
let limitQuery = buildLimiter(opts);
let returnResult = buildReturn(opts);
let returnQuery = returnResult.q;
// return complete node in case no specific fields are specified
if (_.isEmpty(returnQuery)) {
returnQuery = 'RETURN node';
}
let queryString = `FOR node in @@collection FILTER ${filterQuery}`;
if (!_.isEmpty(customFilter)) {
queryString += customFilter;
}
queryString += ` ${sortQuery}
${limitQuery} ${returnQuery}`;
let varArgs = {};
if (filterResult && filterResult.bindVarsMap) {
varArgs = filterResult.bindVarsMap;
}
let returnArgs = {};
if (returnResult && returnResult.bindVarsMap) {
returnArgs = returnResult.bindVarsMap;
}
let limitArgs;
if (_.isEmpty(limitQuery)) {
limitArgs = {};
} else {
if (!_.isNil(opts.limit)) {
limitArgs = { limit: opts.limit };
if (!_.isNil(opts.offset)) {
limitArgs = { offset: opts.offset, limit: opts.limit };
}
}
}
varArgs = _.assign(varArgs, limitArgs);
varArgs = _.assign(varArgs, returnArgs);
bindVars = _.assign({
'@collection': collectionName
}, varArgs);
if (!_.isEmpty(customFilter) && opts.customArguments) {
bindVars = _.assign(bindVars, opts.customArguments);
}
const res = await query(this.db, collectionName, queryString, bindVars);
const docs = await res.all(); // TODO: paginate
return _.map(docs, sanitizeOutputFields);
}
示例2:
update.extend('$assign', (spec, object) => _.assign({}, object, spec));
示例3:
return this.getLedgerVersion().then(ledgerVersion =>
_.assign({}, options, {ledgerVersion}))
示例4: assign
todo =>
todo.id === action.id
? assign({}, todo, { completed: !todo.completed })
: todo,
示例5:
M: MALE_COLOR,
POSITIVE: YES_COLOR,
NEGATIVE: NO_COLOR,
MISSENSE: MUT_COLOR_MISSENSE,
INFRAME: MUT_COLOR_INFRAME,
TRUNCATING: MUT_COLOR_TRUNC,
FUSION: MUT_COLOR_FUSION,
PROMOTER: MUT_COLOR_PROMOTER,
OTHER: MUT_COLOR_OTHER,
"WILD TYPE": DEFAULT_GREY,
AMPLIFICATION: CNA_COLOR_AMP,
GAIN: CNA_COLOR_GAIN,
DIPLOID: DEFAULT_GREY,
"SHALLOW DELETION": CNA_COLOR_HETLOSS,
"DEEP DELETION": CNA_COLOR_HOMDEL
},
na: "#CCCCCC",
mutatedGene: '#008000',
deletion: '#0000FF',
amplification: '#FF0000',
}
};
_.forEach(studyViewFrontEnd.colors.reservedValue, (color, key)=>{
// expand reservedValue entries to handle other case possibilities. eg expand TRUE to True and true
(studyViewFrontEnd.colors.reservedValue as any)[key.toLowerCase()] = color;
(studyViewFrontEnd.colors.reservedValue as any)[key[0] + key.slice(1).toLowerCase()] = color;
});
export const STUDY_VIEW_CONFIG: StudyViewConfig = _.assign(studyViewFrontEnd, AppConfig.serverConfig.study_view);
示例6:
return super.getNewInstance().then((newInstance) => _.assign(newInstance, {id: uuid.v4()}));
示例7: put
export function put(obj?: any): RequestInit {
return assign({}, { method: "PUT" }, convert(obj));
}
示例8: function
.add<UpdatePeripheral>("UPDATE_PERIPHERAL", function (s, a) {
let target = s.all[a.payload.index];
_.assign(target, a.payload.peripheral, { dirty: true });
return s;
});
示例9: optimize
/**
* This is the worker function that *optimizes* an existing variation (or original)
*
* Note that we assume that original files always stay in the protected
* folder and aren't moved on activation. If that changes, the optimization
* queue must also work with a copy of the original file to avoid file
* access conflicts.
*
* @param {Job} job
* @return {Promise<any>}
*/
public static async optimize(job: Job): Promise<any> {
let file: FileDocument;
// retrieve data from deserialized job
const data = job.data as JobData;
const srcPath = data.srcPath;
const destPath = data.destPath; // {filename}.{processor}._processing.{ext}
const requestState = data.requestState;
file = await state.models.File.findOne({ id: data.fileId }).exec();
if (!file) {
logger.warn(requestState, '[ProcessorWorker.optimize] [%s | #%s] skip: File "%s" has been removed from DB, ignoring.',
data.processor, job.id, data.fileId);
return null;
}
const processor = processorManager.getOptimizationProcessor(data.processor);
const variation = file.getVariation(data.destVariation);
try {
// create directory
if (!(await FileUtil.exists(dirname(destPath)))) {
await FileUtil.mkdirp(dirname(destPath));
}
logger.debug(requestState, '[ProcessorWorker.optimize] [%s | #%s] start: %s from %s to %s',
data.processor, job.id, file.toDetailedString(variation), FileUtil.log(srcPath), FileUtil.log(destPath));
// run processor
const createdFile = await processor.process(requestState, file, srcPath, destPath, variation);
if (isUndefined(createdFile)) {
throw new ApiError('Processor %s returned undefined but is supposed to return null or path to processed file.', processor.name);
}
// if a new file was created, update metadata and delete if necessary.
if (createdFile) {
// update metadata if some processing took place
const metadataReader = Metadata.getReader(file, variation);
const metadata = await metadataReader.getMetadata(requestState, file, createdFile, variation);
const fileData: any = {};
if (variation) {
fileData['variations.' + variation.name] = assign(metadataReader.serializeVariation(metadata), {
bytes: (await statAsync(destPath)).size,
mime_type: variation.mimeType,
});
} else {
fileData.metadata = await Metadata.readFrom(requestState, file, destPath);
fileData.bytes = (await statAsync(destPath)).size;
}
await state.models.File.findOneAndUpdate({ _id: file._id }, { $set: fileData }).exec();
// abort if deleted
if (await ProcessorWorker.isFileDeleted(file)) {
logger.debug(requestState, '[ProcessorWorker.optimize] Removing created file due to deletion %s', FileUtil.log(destPath));
await unlinkAsync(createdFile);
return null;
}
}
// rename
const newPath = await ProcessorWorker.isFileRenamed(requestState, file.getPath(requestState, variation), 'optimize');
const finalPath = newPath || file.getPath(requestState, variation);
if (createdFile) {
await renameAsync(createdFile, finalPath); // overwrites destination
}
logger.debug(requestState, '[ProcessorWorker.optimize] [%s | #%s] done: %s at %s', data.processor, job.id, file.toDetailedString(variation), FileUtil.log(finalPath));
return finalPath;
} catch (err) {
// nothing to return here because it's in the background.
if (err.isApiError) {
logger.error(requestState, err.print());
} else {
logger.error(requestState, '[ProcessorWorker.optimize] Error while processing %s with %s:\n\n%s\n\n', file ? file.toDetailedString(variation) : 'null', job.data.processor, ApiError.colorStackTrace(err));
}
// TODO log to raygun
}
}
示例10: makeWholeSpec
function makeWholeSpec(initFn) {
const initResult = initFn(browser);
memberName = initResult.member;
usersBrowser = _.assign(browser, pagesFor(browser));
memberIsAdmin = initResult.memberIsAdmin;
forum = buildSite().addLargeForum({
title: forumTitle,
members: ['alice', 'maria', 'michael'],
});
const who = (memberIsAdmin ? "admin " : (memberName ? "member " : "a stranger")) + (memberName || '');
describe(`Navigation as ${who}:`, () => {
it("import a site", () => {
idAddress = server.importSiteData(forum.siteData);
});
it("go to forum", () => {
usersBrowser.go(idAddress.origin);
usersBrowser.disableRateLimits();
});
if (memberName) {
it("login", () => {
member = forum.members[memberName];
usersBrowser.complex.loginWithPasswordViaTopbar(member);
});
}
it("Prepare tests: Add Maria's page to watchbar", () => {
// This makes all different 'describe...' below work, also if the first one is skipped.
usersBrowser.go('/' + forum.topics.byMariaCategoryA.slug);
});
// ------- Test the forum
// This tests navigation from all kinds of pages â user profile, search, topics â to the forum.
describe("Test navigation to forum", () => {
it("start at forum, to test forum", () => {
usersBrowser.go(idAddress.origin);
});
addForumTests("1: ");
it("start at topic, go to forum, test forum", () => {
usersBrowser.go('/' + forum.topics.byMariaCategoryA.slug);
usersBrowser.topbar.clickHome();
});
addForumTests("2: ");
it("remember / as last page", () => {
usersBrowser.go('/');
});
it("start at user profile, go back to last page = to the forum, test forum", () => {
usersBrowser.go('/-/users/maria');
usersBrowser.topbar.clickBack(); // goes back to the forum
});
addForumTests("3: ");
it("start at search page, go to forum, test forum", () => {
usersBrowser.goToSearchPage();
usersBrowser.topbar.clickHome();
});
addForumTests("4: ");
if (memberIsAdmin) {
it("start in admin area, go to forum via watchbar, test forum", () => {
usersBrowser.adminArea.goToLoginSettings();
usersBrowser.adminArea.waitAssertVisible();
usersBrowser.watchbar.openIfNeeded();
usersBrowser.watchbar.goToTopic(forumTitle, { isHome: true });
});
addForumTests("5: ");
}
});
// ------- Test a topic
describe("Test navigation to topic", () => {
it("start at forum, to test Maria's topic", () => {
usersBrowser.go(idAddress.origin);
});
it("... go to Maria's topic", () => {
usersBrowser.forumTopicList.goToTopic(forum.topics.byMariaCategoryA.title);
});
addMariasTopicTests();
it("start at another topic", () => {
usersBrowser.go('/' + forum.topics.byMariaCategoryANr2.slug);
});
it("... it looks ok", () => {
usersBrowser.topic.waitForPostNrVisible(c.BodyNr);
usersBrowser.topic.assertPostTextMatches(c.BodyNr, forum.topics.byMariaCategoryANr2.body);
});
it("go to Maria's topic, test it (topic to topic)", () => {
usersBrowser.watchbar.goToTopic(forum.topics.byMariaCategoryA.title);
});
//.........这里部分代码省略.........