本文整理汇总了TypeScript中fast-copy.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: copy
_.each(overlaps, (overlappingItems) => {
if (overlappingItems.length <= 1) {
return;
}
const options: { [x: string]: DimItem }[] = [];
// For each item, replace all the others overlapping it with the next best thing
for (const item of overlappingItems) {
const option = copy(items);
const otherItems = overlappingItems.filter((i) => i !== item);
let optionValid = true;
for (const otherItem of otherItems) {
// Note: we could look for items that just don't have the *same* equippingLabel but
// that may fail if there are ever mutual-exclusion items beyond exotics.
const nonExotics = itemsByType[otherItem.type].filter((i) => !i.equippingLabel);
if (nonExotics.length) {
option[otherItem.type] = _.maxBy(nonExotics, bestItemFn)!;
} else {
// this option isn't usable because we couldn't swap this exotic for any non-exotic
optionValid = false;
}
}
if (optionValid) {
options.push(option);
}
}
// Pick the option where the optimizer function adds up to the biggest number, again favoring equipped stuff
if (options.length > 0) {
const bestOption = _.maxBy(options, (opt) => _.sumBy(Object.values(opt), bestItemFn))!;
items = bestOption;
}
});
开发者ID:w1cked,项目名称:DIM,代码行数:35,代码来源:loadout-utils.ts
示例2: filterLoadoutToEquipped
function filterLoadoutToEquipped(loadout: Loadout) {
const filteredLoadout = copy(loadout);
filteredLoadout.items = _.mapValues(filteredLoadout.items, (items) => {
return items.filter((i) => i.equipped);
});
return filteredLoadout;
}
开发者ID:w1cked,项目名称:DIM,代码行数:7,代码来源:loadout-builder.component.ts
示例3: copy
return _.flatMap(Object.values(_.groupBy(items, (t) => t.hash)), (items) => {
if (items[0].maxStackSize > 1) {
const item = copy(items[0]);
item.amount = _.sumBy(items, (i) => i.amount);
return [item];
} else {
return items;
}
});
开发者ID:w1cked,项目名称:DIM,代码行数:9,代码来源:auto-loadouts.ts
示例4: getAndCacheFromAdapters
async function getAndCacheFromAdapters(): Promise<DimData> {
try {
const value = await getFromAdapters();
cached = value || {};
return copy(cached);
} finally {
_getPromise = undefined;
}
}
开发者ID:w1cked,项目名称:DIM,代码行数:9,代码来源:sync.service.ts
示例5: copy
consolidateHashes.map((hash) => {
const ret = copy(
D1StoresService.getItemAcrossStores({
hash
})
);
if (ret) {
ret.amount = _.sumBy(D1StoresService.getStores(), (s) => s.amountOfItem(ret));
}
return ret;
})
开发者ID:w1cked,项目名称:DIM,代码行数:11,代码来源:farming.service.ts
示例6: copy
function hydratev3d0(loadoutPrimitive: DehydratedLoadout): Loadout {
const result: Loadout = {
id: loadoutPrimitive.id,
name: loadoutPrimitive.name,
platform: loadoutPrimitive.platform,
destinyVersion: loadoutPrimitive.destinyVersion,
classType: _.isUndefined(loadoutPrimitive.classType) ? -1 : loadoutPrimitive.classType,
items: {
unknown: []
}
};
for (const itemPrimitive of loadoutPrimitive.items) {
const item = copy(
getStoresService(result.destinyVersion).getItemAcrossStores({
id: itemPrimitive.id,
hash: itemPrimitive.hash
})
);
if (item) {
const discriminator = item.type.toLowerCase();
item.equipped = itemPrimitive.equipped;
item.amount = itemPrimitive.amount;
result.items[discriminator] = result.items[discriminator] || [];
result.items[discriminator].push(item);
} else {
const loadoutItem = {
id: itemPrimitive.id,
hash: itemPrimitive.hash,
amount: itemPrimitive.amount,
equipped: itemPrimitive.equipped
};
result.items.unknown.push(loadoutItem as DimItem);
}
}
return result;
}
开发者ID:w1cked,项目名称:DIM,代码行数:43,代码来源:loadout.service.ts
示例7: mergeVendors
function mergeVendors([firstVendor, ...otherVendors]: Vendor[]) {
const mergedVendor = copy(firstVendor);
otherVendors.forEach((vendor) => {
Object.assign(firstVendor.cacheKeys, vendor.cacheKeys);
vendor.categories.forEach((category) => {
const existingCategory = _.find(mergedVendor.categories, { title: category.title });
if (existingCategory) {
mergeCategory(existingCategory, category);
} else {
mergedVendor.categories.push(category);
}
});
});
mergedVendor.allItems = _.flatten(mergedVendor.categories.map((i) => i.saleItems));
return mergedVendor;
}
开发者ID:w1cked,项目名称:DIM,代码行数:20,代码来源:vendor.service.ts
示例8: applyLoadoutItems
const doLoadout = async () => {
if (allowUndo && !store.isVault) {
reduxStore.dispatch(
actions.savePreviousLoadout({
storeId: store.id,
loadoutId: loadout.id,
previousLoadout: store.loadoutFromCurrentlyEquipped(
t('Loadouts.Before', { name: loadout.name })
)
})
);
}
let items: DimItem[] = copy(_.flatten(Object.values(loadout.items)));
const loadoutItemIds = items.map((i) => {
return {
id: i.id,
hash: i.hash
};
});
// Only select stuff that needs to change state
let totalItems = items.length;
items = items.filter((pseudoItem) => {
const item = getLoadoutItem(pseudoItem, store);
// provide a more accurate count of total items
if (!item) {
totalItems--;
return true;
}
const notAlreadyThere =
item.owner !== store.id ||
item.location.inPostmaster ||
// Needs to be equipped. Stuff not marked "equip" doesn't
// necessarily mean to de-equip it.
(pseudoItem.equipped && !item.equipped) ||
pseudoItem.amount > 1;
return notAlreadyThere;
});
// only try to equip subclasses that are equippable, since we allow multiple in a loadout
items = items.filter((item) => {
const ok = item.type !== 'Class' || !item.equipped || item.canBeEquippedBy(store);
if (!ok) {
totalItems--;
}
return ok;
});
// vault can't equip
if (store.isVault) {
items.forEach((i) => {
i.equipped = false;
});
}
// We'll equip these all in one go!
let itemsToEquip = items.filter((i) => i.equipped);
if (itemsToEquip.length > 1) {
// we'll use the equipItems function
itemsToEquip.forEach((i) => {
i.equipped = false;
});
}
// Stuff that's equipped on another character. We can bulk-dequip these
const itemsToDequip = items.filter((pseudoItem) => {
const item = storeService.getItemAcrossStores(pseudoItem);
return item && item.owner !== store.id && item.equipped;
});
const scope = {
failed: 0,
total: totalItems,
successfulItems: [] as DimItem[]
};
if (itemsToDequip.length > 1) {
const realItemsToDequip = _.compact(
itemsToDequip.map((i) => storeService.getItemAcrossStores(i))
);
const dequips = _.map(
_.groupBy(realItemsToDequip, (i) => i.owner),
(dequipItems, owner) => {
const equipItems = _.compact(
dequipItems.map((i) => dimItemService.getSimilarItem(i, loadoutItemIds))
);
return dimItemService.equipItems(storeService.getStore(owner)!, equipItems);
}
);
await Promise.all(dequips);
}
await applyLoadoutItems(store, items, loadoutItemIds, scope);
let equippedItems: DimItem[];
if (itemsToEquip.length > 1) {
//.........这里部分代码省略.........
开发者ID:w1cked,项目名称:DIM,代码行数:101,代码来源:loadout.service.ts
示例9: updateItemModel
/**
* Update our item and store models after an item has been moved (or equipped/dequipped).
* @return the new or updated item (it may create a new item!)
*/
function updateItemModel(
item: DimItem,
source: DimStore,
target: DimStore,
equip: boolean,
amount: number = item.amount
) {
// Refresh all the items - they may have been reloaded!
const storeService = item.getStoresService();
source = storeService.getStore(source.id)!;
target = storeService.getStore(target.id)!;
// We really shouldn't do this!
item = storeService.getItemAcrossStores(item) || item;
// If we've moved to a new place
if (source.id !== target.id || item.location.inPostmaster) {
// We handle moving stackable and nonstackable items almost exactly the same!
const stackable = item.maxStackSize > 1;
// Items to be decremented
const sourceItems = stackable
? _.sortBy(
source.buckets[item.location.id].filter((i) => {
return i.hash === item.hash && i.id === item.id && !i.notransfer;
}),
(i) => i.amount
)
: [item];
// Items to be incremented. There's really only ever at most one of these, but
// it's easier to deal with as a list.
const targetItems = stackable
? _.sortBy(
target.buckets[item.bucket.id].filter((i) => {
return (
i.hash === item.hash &&
i.id === item.id &&
// Don't consider full stacks as targets
i.amount !== i.maxStackSize &&
!i.notransfer
);
}),
(i) => i.amount
)
: [];
// moveAmount could be more than maxStackSize if there is more than one stack on a character!
const moveAmount = amount || item.amount || 1;
let addAmount = moveAmount;
let removeAmount = moveAmount;
let removedSourceItem = false;
// Remove inventory from the source
while (removeAmount > 0) {
let sourceItem = sourceItems.shift();
if (!sourceItem) {
throw new Error(t('ItemService.TooMuch'));
}
const amountToRemove = Math.min(removeAmount, sourceItem.amount);
if (amountToRemove === sourceItem.amount) {
// Completely remove the source item
if (source.removeItem(sourceItem)) {
removedSourceItem = sourceItem.index === item.index;
}
} else {
// Perf hack: by replacing the item entirely with a cloned
// item that has an adjusted index, we force the ng-repeat
// to refresh its view of the item, updating the
// amount. This is because we've switched to bind-once for
// the amount since it rarely changes.
source.removeItem(sourceItem);
sourceItem = copy(sourceItem);
sourceItem.amount -= amountToRemove;
sourceItem.index = createItemIndex(sourceItem);
source.addItem(sourceItem);
}
removeAmount -= amountToRemove;
}
// Add inventory to the target (destination)
let targetItem: DimItem;
while (addAmount > 0) {
targetItem = targetItems.shift()!;
if (!targetItem) {
targetItem = item;
if (!removedSourceItem) {
targetItem = copy(item);
targetItem.index = createItemIndex(targetItem);
}
removedSourceItem = false; // only move without cloning once
targetItem.amount = 0; // We'll increment amount below
if (targetItem.location.inPostmaster) {
targetItem.location = targetItem.bucket;
}
target.addItem(targetItem);
}
//.........这里部分代码省略.........
开发者ID:w1cked,项目名称:DIM,代码行数:101,代码来源:dimItemService.factory.ts
示例10: step
getDefinitions().then((defs) => {
Object.assign(vm, {
active: 'titan',
i18nClassNames: _.zipObject(
['titan', 'hunter', 'warlock'],
_.sortBy(Object.values(defs.Class), (classDef) => classDef.classType).map(
(c: any) => c.className
)
),
i18nItemNames: _.zipObject(
['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) {
const classType = vm.activeCharacters[selectedIdx].class;
if (classType !== 'vault') {
vm.active = classType;
}
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
);
//.........这里部分代码省略.........
开发者ID:w1cked,项目名称:DIM,代码行数:101,代码来源:loadout-builder.component.ts
注:本文中的fast-copy.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论