本文整理匯總了TypeScript中underscore.findIndex函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript findIndex函數的具體用法?TypeScript findIndex怎麽用?TypeScript findIndex使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了findIndex函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addAnchorTag
/** !ReferenceCollection/addAnchorTag
* ## Add Anchor Tag
* Add Anchor Tag to the appropriate subcollection by
* recursively skiming the collection and subcollections
* to place anchor in the correct place.
*/
public addAnchorTag(anchorTag: string[], fileName: string, lineNumber: number): void {
logger.debug("processing new anchorTag: " + JSON.stringify(anchorTag));
if (anchorTag.length === 1) {
logger.debug("Adding anchor tag:" + anchorTag[0]);
this.addAnchor({
id: anchorTag[0],
line: lineNumber,
file: fileName
});
return;
} else {
let collectionTag = anchorTag.shift();
let i = findIndex(this.subcollections, (item) => {
return item.id === collectionTag;
});
if (i > -1) {
logger.debug("Collection present:" + collectionTag);
return this.subcollections[i].addAnchorTag(anchorTag, fileName, lineNumber);
} else {
logger.debug("Collection not present:" + collectionTag);
let newSubCollection = new ReferenceCollection(collectionTag);
newSubCollection.addAnchorTag(anchorTag, fileName, lineNumber);
this.addSubcollection(newSubCollection);
return;
}
}
}
示例2: remove
vm.remove = function remove(item, $event) {
if (!vm.loadout) {
return;
}
const discriminator = item.type.toLowerCase();
const typeInventory = vm.loadout.items[discriminator] = (vm.loadout.items[discriminator] || []);
const index = _.findIndex(typeInventory, (i) => {
return i.hash === item.hash && i.id === item.id;
});
if (index >= 0) {
const decrement = $event.shiftKey ? 5 : 1;
item.amount -= decrement;
if (item.amount <= 0) {
typeInventory.splice(index, 1);
}
}
if (item.equipped && typeInventory.length > 0) {
typeInventory[0].equipped = true;
}
vm.recalculateStats();
};
示例3: HandleAsync
async HandleAsync(request: JoinIdeaRequest): Promise<JoinIdeaResponse> {
let businessRules = nconf.get("BusinessRules");
let idea = await this.GetIdea(request.ideaId);
if (idea.joinedList.length >= businessRules.MaxTeamSize) {
throw new Error(`This project already has ${businessRules.MaxTeamSize} team members. ` +
"Please select a different project.");
}
let ideas = await this.GetIdeasThatUserAlreadyJoined(request.user);
ideas.map(async (idea) => {
await this.UnJoinIdea(idea.id, request.user);
});
var index = _.findIndex(idea.joinedList, item => item.id === request.user.id);
if (index < 0) {
idea.joinedList.push({
id: request.user.id,
name: request.user.displayName,
login: request.user.username
});
}
await this.UpsertIdea(idea, request.user);
return new JoinIdeaResponse();
}
示例4:
.then(idea => {
var index = _.findIndex(idea.joinedList, item => item.id === user.id);
if (index > -1) {
idea.joinedList.splice(index, 1);
}
return idea;
}).then(idea => {
示例5:
.then((loadouts) => {
const index = _.findIndex(loadouts, { id: loadout.id });
if (index >= 0) {
loadouts.splice(index, 1);
}
return SyncService.remove(loadout.id!.toString()).then(() => loadouts) as IPromise<Loadout[]>;
})
示例6: uuidv4
.then((loadouts) => {
if (!_.has(loadout, 'id')) {
loadout.id = uuidv4();
}
// Handle overwriting an old loadout
const existingLoadoutIndex = _.findIndex(loadouts, { id: loadout.id });
if (existingLoadoutIndex > -1) {
loadouts[existingLoadoutIndex] = loadout;
} else {
loadouts.push(loadout);
}
return saveLoadouts(loadouts);
})
示例7: getBonus
_.map(itemDef.stats, (stat: any) => {
const def = statDefs.get(stat.statHash);
if (!def) {
return undefined;
}
const identifier = def.statIdentifier;
// Only include these hidden stats, in this order
const secondarySort = ['STAT_AIM_ASSISTANCE', 'STAT_EQUIP_SPEED'];
let secondaryIndex = -1;
let sort = _.findIndex(item.stats, { statHash: stat.statHash });
let itemStat;
if (sort < 0) {
secondaryIndex = secondarySort.indexOf(identifier);
sort = 50 + secondaryIndex;
} else {
itemStat = item.stats[sort];
// Always at the end
if (identifier === 'STAT_MAGAZINE_SIZE' || identifier === 'STAT_ATTACK_ENERGY') {
sort = 100;
}
}
if (!itemStat && secondaryIndex < 0) {
return undefined;
}
let maximumValue = 100;
if (itemStat && itemStat.maximumValue) {
maximumValue = itemStat.maximumValue;
}
const val: number = itemStat ? itemStat.value : stat.value;
let base = val;
let bonus = 0;
if (item.primaryStat && item.primaryStat.stat.statIdentifier === 'STAT_DEFENSE') {
if (
(identifier === 'STAT_INTELLECT' &&
_.find(armorNodes, { hash: 1034209669 /* Increase Intellect */ })) ||
(identifier === 'STAT_DISCIPLINE' &&
_.find(armorNodes, { hash: 1263323987 /* Increase Discipline */ })) ||
(identifier === 'STAT_STRENGTH' &&
_.find(armorNodes, { hash: 193091484 /* Increase Strength */ }))
) {
bonus = getBonus(item.primaryStat.value, type);
if (
activeArmorNode &&
((identifier === 'STAT_INTELLECT' && activeArmorNode.hash === 1034209669) ||
(identifier === 'STAT_DISCIPLINE' && activeArmorNode.hash === 1263323987) ||
(identifier === 'STAT_STRENGTH' && activeArmorNode.hash === 193091484))
) {
base = Math.max(0, val - bonus);
}
}
}
const dimStat: D1Stat = {
base,
bonus,
statHash: stat.statHash,
name: def.statName,
id: def.statIdentifier,
sort,
value: val,
maximumValue,
bar: identifier !== 'STAT_MAGAZINE_SIZE' && identifier !== 'STAT_ATTACK_ENERGY' // energy == magazine for swords
};
return dimStat;
})
示例8: getDefinitions
getDefinitions().then((defs) => {
extend(vm, {
active: 'titan',
i18nClassNames: _.object(
['titan', 'hunter', 'warlock'],
_.sortBy(Object.values(defs.Class), (classDef) => classDef.classType).map(
(c) => c.className
)
),
i18nItemNames: _.object(
['Helmet', 'Gauntlets', 'Chest', 'Leg', 'ClassItem', 'Artifact', 'Ghost'],
[45, 46, 47, 48, 49, 38, 39].map((key) => defs.ItemCategory.get(key).title)
),
activesets: '5/5/2',
type: 'Helmet',
scaleType: 'scaled',
progress: 0,
fullMode: false,
includeVendors: false,
showBlues: false,
showExotics: true,
showYear1: false,
allSetTiers: [],
hasSets: true,
highestsets: {},
activeHighestSets: [],
ranked: {},
activePerks: {},
excludeditems: [],
collapsedConfigs: [false, false, false, false, false, false, false, false, false, false],
lockeditems: {
Helmet: null,
Gauntlets: null,
Chest: null,
Leg: null,
ClassItem: null,
Artifact: null,
Ghost: null
},
lockedperks: {
Helmet: {},
Gauntlets: {},
Chest: {},
Leg: {},
ClassItem: {},
Artifact: {},
Ghost: {}
},
setOrderValues: ['-str_val', '-dis_val', '-int_val'],
lockedItemsValid(droppedId: string, droppedType: ArmorTypes) {
droppedId = getId(droppedId);
if (alreadyExists(vm.excludeditems, droppedId)) {
return false;
}
const item = getItemById(droppedId, droppedType)!;
const startCount: number = item.isExotic && item.type !== 'ClassItem' ? 1 : 0;
return (
startCount +
(droppedType !== 'Helmet' && vm.lockeditems.Helmet && vm.lockeditems.Helmet.isExotic
? 1
: 0) +
(droppedType !== 'Gauntlets' &&
vm.lockeditems.Gauntlets &&
vm.lockeditems.Gauntlets.isExotic
? 1
: 0) +
(droppedType !== 'Chest' && vm.lockeditems.Chest && vm.lockeditems.Chest.isExotic
? 1
: 0) +
(droppedType !== 'Leg' && vm.lockeditems.Leg && vm.lockeditems.Leg.isExotic ? 1 : 0) <
2
);
},
excludedItemsValid(droppedId: string, droppedType: ArmorTypes) {
const lockedItem = vm.lockeditems[droppedType];
return !(lockedItem && alreadyExists([lockedItem], droppedId));
},
onSelectedChange(prevIdx, selectedIdx) {
if (vm.activeCharacters[prevIdx].class !== vm.activeCharacters[selectedIdx].class) {
vm.active = vm.activeCharacters[selectedIdx].class;
vm.onCharacterChange();
vm.selectedCharacter = selectedIdx;
}
},
onCharacterChange() {
vm.ranked = getActiveBuckets(
buckets[vm.active],
vendorBuckets[vm.active],
vm.includeVendors
);
vm.activeCharacters = D1StoresService.getStores().filter((s) => !s.isVault);
const activeStore = D1StoresService.getActiveStore()!;
vm.selectedCharacter = _.findIndex(
vm.activeCharacters,
(char) => char.id === activeStore.id
);
vm.activePerks = getActiveBuckets(
perks[vm.active],
vendorPerks[vm.active],
//.........這裏部分代碼省略.........