当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.zip函数代码示例

本文整理汇总了TypeScript中underscore.zip函数的典型用法代码示例。如果您正苦于以下问题:TypeScript zip函数的具体用法?TypeScript zip怎么用?TypeScript zip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zip函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: convertJavaScriptToVariant

export function convertJavaScriptToVariant(
  argumentDefinition: ArgumentOptions[],
  values: any[]
): Variant[] {

    assert(argumentDefinition.length === values.length);
    assert(_.isArray(argumentDefinition));
    assert(_.isArray(values));

    return _.zip(values, argumentDefinition).map((pair: any) => {
        pair = pair as [VariantLike, Argument];
        const value = pair[0];
        const arg = pair[1];
        const variant = _.extend({}, arg);
        variant.value = value;
        return new Variant(variant);
    });
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:18,代码来源:argument_list.ts

示例2: loadProgress

async function loadProgress(account: DestinyAccount): Promise<ProgressProfile | undefined> {
  try {
    const defsPromise = getDefinitions();
    const profileInfo = await getProgression(account);
    const characterIds = Object.keys(profileInfo.characters.data);
    let vendors: DestinyVendorsResponse[] = [];
    try {
      vendors = await Promise.all(
        characterIds.map((characterId) => getVendors(account, characterId))
      );
    } catch (e) {
      console.error('Failed to load vendors', e);
    }

    const defs = await defsPromise;
    return {
      defs,
      profileInfo,
      vendors: _.object(_.zip(characterIds, vendors)) as ProgressProfile['vendors'],
      get lastPlayedDate() {
        return Object.values((this.profileInfo as DestinyProfileResponse).characters.data).reduce(
          (memo, character: DestinyCharacterComponent) => {
            const d1 = new Date(character.dateLastPlayed);
            return memo ? (d1 >= memo ? d1 : memo) : d1;
          },
          new Date(0)
        );
      }
    };
  } catch (e) {
    toaster.pop(bungieErrorToaster(e));
    console.error('Error loading progress', e);
    reportException('progressService', e);
    // It's important that we swallow all errors here - otherwise
    // our observable will fail on the first error. We could work
    // around that with some rxjs operators, but it's easier to
    // just make this never fail.
    return undefined;
  } finally {
    D2ManifestService.loaded = true;
  }
}
开发者ID:bhollis,项目名称:DIM,代码行数:42,代码来源:progress.service.ts

示例3: callback

        session.call(methodToCall, (err: Error | null, callResult?: CallMethodResult) => {

            // istanbul ignore next
            if (err) {
                return callback(err);
            }

            callResult = callResult!;

            if (callResult.statusCode !== StatusCodes.Good) {
                return callback(new Error("Error " + callResult.statusCode.toString()));
            }

            callResult.outputArguments = callResult.outputArguments || [];

            obj[name].outputArguments = obj[name].outputArguments || [];

            if (callResult.outputArguments.length !== obj[name].outputArguments.length) {
                return callback(new Error("Internal error callResult.outputArguments.length "
                  + callResult.outputArguments.length + " " +  obj[name].outputArguments.length));
            }

            const outputArgs: any = {};

            const outputArgsDef = obj[name].outputArguments;

            _.zip(outputArgsDef, callResult.outputArguments).forEach((pair: any) => {
                const arg = pair[0];
                const variant = pair[1];

                const propName = lowerFirstLetter(arg.name);
                outputArgs[propName] = variant.value;

            });
            callback(err, outputArgs);

        });
开发者ID:node-opcua,项目名称:node-opcua,代码行数:37,代码来源:object_explorer.ts

示例4: queuedAction

export const distribute = queuedAction((actionableItem: DimItem) => {
  // Sort vault to the end
  const stores = _.sortBy(actionableItem.getStoresService().getStores(), (s) => {
    return s.id === 'vault' ? 2 : 1;
  });

  let total = 0;
  const amounts = stores.map((store) => {
    const amount = store.amountOfItem(actionableItem);
    total += amount;
    return amount;
  });

  const numTargets = stores.length - 1; // exclude the vault
  let remainder = total % numTargets;
  const targets = stores.map((_store, index) => {
    if (index >= numTargets) {
      return 0; // don't want any in the vault
    }
    const result = remainder > 0 ? Math.ceil(total / numTargets) : Math.floor(total / numTargets);
    remainder--;
    return result;
  });
  const deltas = _.zip(amounts, targets).map((pair) => {
    return pair[1] - pair[0];
  });

  const vaultMoves: {
    source: DimStore;
    target: DimStore;
    amount: number;
  }[] = [];
  const targetMoves: {
    source: DimStore;
    target: DimStore;
    amount: number;
  }[] = [];
  const vaultIndex = stores.length - 1;
  const vault = stores[vaultIndex];

  deltas.forEach((delta, index) => {
    if (delta < 0 && index !== vaultIndex) {
      vaultMoves.push({
        source: stores[index],
        target: vault,
        amount: -delta
      });
    } else if (delta > 0) {
      targetMoves.push({
        source: vault,
        target: stores[index],
        amount: delta
      });
    }
  });

  // All moves to vault in parallel, then all moves to targets in parallel
  function applyMoves(moves) {
    return $q.all(
      moves.map((move) => {
        const item = move.source.items.find((i) => i.hash === actionableItem.hash);
        return dimItemService.moveTo(item, move.target, false, move.amount);
      })
    );
  }

  let promise: IPromise<any> = applyMoves(vaultMoves).then(() => {
    return applyMoves(targetMoves);
  });

  promise = promise
    .then(() => {
      toaster.pop('success', t('ItemMove.Distributed', { name: actionableItem.name }));
    })
    .catch((a) => {
      toaster.pop('error', actionableItem.name, a.message);
      console.log('error distributing', actionableItem, a);
    });

  loadingTracker.addPromise(promise);

  return promise;
});
开发者ID:bhollis,项目名称:DIM,代码行数:83,代码来源:dimItemMoveService.factory.ts

示例5: exploreDataTypeDefinition

export async function exploreDataTypeDefinition(
  session: IBasicSession,
  dataTypeDictionaryTypeNode: NodeId,
  typeDictionary: TypeDictionary,
  namespaces: string[]
) {

    const nodeToBrowse = {
        browseDirection: BrowseDirection.Forward,
        includeSubtypes: false,
        nodeClassMask: makeNodeClassMask("Variable"),
        nodeId: dataTypeDictionaryTypeNode,
        referenceTypeId: resolveNodeId("HasComponent"),
        resultMask: makeResultMask("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
    };
    const result = await session.browse(nodeToBrowse);
    const references = result.references || [];

    /* istanbul ignore next */
    if (references.length === 0) {
        return;
    }

    // request the Definition of each not
    const nodesToBrowse2 = references.map((ref: ReferenceDescription) => {
        return {
            browseDirection: BrowseDirection.Inverse,
            includeSubtypes: false,
            nodeClassMask: makeNodeClassMask("Object | Variable"),
            nodeId: ref.nodeId,
            referenceTypeId: resolveNodeId("HasDescription"),
            resultMask: makeResultMask("NodeId | ReferenceType | BrowseName | NodeClass | TypeDefinition")
        };
    });
    const results2 = await session.browse(nodesToBrowse2);

    const binaryEncodingNodeIds = results2.map((br: BrowseResult) => {
        const defaultBin =  br.references!.filter((r: ReferenceDescription) => r.browseName.toString() === "Default Binary");

        /* istanbul ignore next */
        if (defaultBin.length < 1) {
            return ExpandedNodeId;
        }
        return ExpandedNodeId.fromNodeId(defaultBin[0].nodeId, namespaces[defaultBin[0].nodeId.namespace]);
    });

    const tuples = _.zip(references, binaryEncodingNodeIds);

    for (const [ref, defaultBinary] of tuples) {
        const name = ref.browseName!.name!.toString();
        const constructor = getOrCreateConstructor(name, typeDictionary, defaultBinary);

        /* istanbul ignore next */
        if (doDebug) {
            try {
                const testObject = new constructor();
                debugLog(testObject.toString());
            } catch (err) {
                debugLog(err.message);
            }
        }
    }
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:63,代码来源:client_dynamic_extension_object.ts


注:本文中的underscore.zip函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。