()
| 65 | // Add Click events to buttons. |
| 66 | // Adds two numbers by calling the `addNumbers` server-side function. |
| 67 | function addNumbers() { |
| 68 | const firstNumberValue = parseFloat(firstNumber.value); |
| 69 | const secondNumberValue = parseFloat(secondNumber.value); |
| 70 | addNumbersButton.disabled = true; |
| 71 | const sendNotification = httpsCallable(functions, 'addNumbers'); |
| 72 | sendNotification({ firstNumber: firstNumberValue, secondNumber: secondNumberValue }).then(function(result) { |
| 73 | console.log('Cloud Function called successfully.', result); |
| 74 | // Read results of the Cloud Function. |
| 75 | const data = result.data as { |
| 76 | firstNumber: number, |
| 77 | secondNumber: number, |
| 78 | operationResult: number, |
| 79 | operator: string |
| 80 | }; |
| 81 | const firstNumber = data.firstNumber; |
| 82 | const secondNumber = data.secondNumber; |
| 83 | const operationResult = data.operationResult; |
| 84 | const operator = data.operator; |
| 85 | window.alert('Here is the result of the formula: ' + firstNumber + ' ' |
| 86 | + operator + ' ' + secondNumber + ' = ' + operationResult); |
| 87 | addNumbersButton.disabled = false; |
| 88 | } |
| 89 | ).catch(function(error) { |
| 90 | // Getting the Error details. |
| 91 | const code = error.code; |
| 92 | const message = error.message; |
| 93 | const details = error.details; |
| 94 | console.error('There was an error when calling the Cloud Function', error); |
| 95 | window.alert('There was an error when calling the Cloud Function:\n\nError Code: ' |
| 96 | + code + '\nError Message:' + message + '\nError Details:' + details); |
| 97 | addNumbersButton.disabled = false; |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | // Adds a message to the Realtime Database by calling the `addMessage` server-side function. |
| 102 | function addMessage() { |
nothing calls this directly
no outgoing calls
no test coverage detected