Skip to content

Commit 9aa2c72

Browse files
authored
Move callable functions snippets (firebase#63)
1 parent 64323e3 commit 9aa2c72

File tree

11 files changed

+129
-0
lines changed

11 files changed

+129
-0
lines changed

firestore-next/emulator-suite.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
function onDocumentReady(firebaseApp) {
35
// [START fs_emulator_connect]
46
const { initializeFirestore } = require("firebase/firestore");

firestore-next/test.firestore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
const { expect } = require('chai');
35

46
// [START city_custom_object]

firestore-next/test.solution-aggregation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
// [START sample_doc]
35
const arinellDoc = {
46
name: 'Arinell Pizza',

firestore-next/test.solution-arrays.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
const postsWithArray = [
35
// [START post_with_array]
46
// Sample document in the 'posts' collection.

firestore-next/test.solution-counters.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
const { FirebaseFirestore } = require('firebase/firestore');
35

46
/** @type {FirebaseFirestore} */

firestore-next/test.solution-geoqueries.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
const { FirebaseFirestore } = require('firebase/firestore');
35

46
const geofire = require('geofire-common');

functions-next/callable.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// [SNIPPETS_REGISTRY disabled]
2+
// [SNIPPETS_SEPARATION enabled]
3+
4+
export function callAddMessage(firebaseApp) {
5+
const messageText = "Hello, World!";
6+
7+
// [START functions_call_add_message]
8+
const { getFunctions, httpsCallable } = require("firebase/functions");
9+
10+
const functions = getFunctions(firebaseApp);
11+
const addMessage = httpsCallable(functions, 'addMessage');
12+
addMessage({ text: messageText })
13+
.then((result) => {
14+
// Read result of the Cloud Function.
15+
const sanitizedMessage = result.data.text;
16+
});
17+
// [END functions_call_add_message]
18+
}
19+
20+
export function callAddMessageError(firebaseApp) {
21+
const messageText = "Hello, World!";
22+
23+
// [START functions_call_add_message_error]
24+
const { getFunctions, httpsCallable } = require("firebase/functions");
25+
26+
const functions = getFunctions(firebaseApp);
27+
const addMessage = httpsCallable(functions, 'addMessage');
28+
addMessage({ text: messageText })
29+
.then((result) => {
30+
// Read result of the Cloud Function.
31+
const sanitizedMessage = result.data.text;
32+
})
33+
.catch((error) => {
34+
// Getting the Error details.
35+
const code = error.code;
36+
const message = error.message;
37+
const details = error.details;
38+
// ...
39+
});
40+
// [END functions_call_add_message_error]
41+
}

functions-next/emulator-suite.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// [SNIPPETS_REGISTRY disabled]
12
// [SNIPPETS_SEPARATION enabled]
3+
24
import { initializeApp } from "firebase/app";
35

46
initializeApp({

functions/callable.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import firebase from "firebase/app";
2+
import "firebase/functions";
3+
4+
function callAddMessage() {
5+
const messageText = "Hello, World!";
6+
7+
// [START functions_call_add_message]
8+
var addMessage = firebase.functions().httpsCallable('addMessage');
9+
addMessage({ text: messageText })
10+
.then((result) => {
11+
// Read result of the Cloud Function.
12+
var sanitizedMessage = result.data.text;
13+
});
14+
// [END functions_call_add_message]
15+
}
16+
17+
function callAddMessageError() {
18+
const messageText = "Hello, World!";
19+
20+
// [START functions_call_add_message_error]
21+
var addMessage = firebase.functions().httpsCallable('addMessage');
22+
addMessage({ text: messageText })
23+
.then((result) => {
24+
// Read result of the Cloud Function.
25+
var sanitizedMessage = result.data.text;
26+
})
27+
.catch((error) => {
28+
// Getting the Error details.
29+
var code = error.code;
30+
var message = error.message;
31+
var details = error.details;
32+
// ...
33+
});
34+
// [END functions_call_add_message_error]
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./functions-next/callable.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START functions_call_add_message_modular]
7+
import { getFunctions, httpsCallable } from "firebase/functions";
8+
9+
const functions = getFunctions(firebaseApp);
10+
const addMessage = httpsCallable(functions, 'addMessage');
11+
addMessage({ text: messageText })
12+
.then((result) => {
13+
// Read result of the Cloud Function.
14+
const sanitizedMessage = result.data.text;
15+
});
16+
// [END functions_call_add_message_modular]

0 commit comments

Comments
 (0)