Merge pull request #32075 from Zlatkovsky/CustomFunctionsAssociateOverload

Add dictionary-based overload for `CustomFunctions.associate`
This commit is contained in:
Daniel Rosenwasser 2019-01-14 12:56:15 -08:00 committed by GitHub
commit c747eccf6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,11 @@ function add10(n: number) {
CustomFunctions.associate('ADD10', add10);
CustomFunctions.associate({
ADD10: add10,
RANDOM: (n: number) => n * Math.random()
});
async function getStockValues(ticker: string): Promise<number> {
const response = await fetch(`myService.com/prices/${ticker}`);
return (await response.json())["price"];

View File

@ -16,9 +16,14 @@ Copyright (c) Microsoft Corporation
declare namespace CustomFunctions {
/**
* @beta
* Ties together the function's JavaScript name with the JSON id property
* Associates the JavaScript function to the name given by the "id" property in the metadata JSON file.
*/
function associate(id: string, functionObject: Function): void;
/**
* @beta
* Associates the JavaScript functions to the names given by the "id" properties in the metadata JSON file.
*/
function associate(mappings: { [key: string]: Function }): void;
/**
* A handler passed automatically as the last parameter
@ -28,7 +33,6 @@ declare namespace CustomFunctions {
* to handle what happens when the function stops streaming.
* @beta
*/
interface StreamingHandler<T> extends CancelableHandler {
/**
* Sets the returned result for a streaming custom function.
@ -36,6 +40,7 @@ declare namespace CustomFunctions {
*/
setResult: (value: T | Error) => void;
}
/**
* @beta
* CancelableHandler interface