@@ -37,39 +37,39 @@ gcloud scheduler jobs create http firestore-sharded-counter-controller --schedul
37
37
38
38
1 . Use the Counter SDK library in your code to increment counters. The code snippet below is just an example, for more comprehensive API documentation, please refer to the [ source code] ( https://dev-partners.googlesource.com/samples/firebase/mods/+/master/firestore-sharded-counter/clients/web/src/index.ts ) :
39
39
40
- ``` html
41
- <html >
42
- <head >
43
- <script src =" https://www.gstatic.com/firebasejs/[version]/firebase-app.js" ></script >
44
- <script src =" https://www.gstatic.com/firebasejs/[version]/firebase-firestore.js" ></script >
45
- <script src =" sharded-counter.js" ></script >
46
- </head >
47
- <body >
48
- <script >
49
- // Initialize Firebase.
50
- var firebaseConfig = { projectId: " ${PROJECT_ID}" };
51
- firebase .initializeApp (firebaseConfig);
52
- var db = firebase .firestore ();
53
-
54
- // Initialize the sharded counter.
55
- var visits = new sharded.Counter (db .doc (" pages/hello-world" ), " stats.visits" );
56
-
57
- // Increment the field "stats.visits" of the document "pages/hello-world".
58
- visits .incrementBy (1 );
59
-
60
- // Listen to locally consistent values.
61
- visits .onSnapshot ((snap ) => {
62
- console .log (" Locally consistent view of visits: " + snap .data ());
63
- });
64
-
65
- // Alternatively, if you don't mind counter delays, you can listen to the document directly.
66
- db .doc (" pages/hello-world" ).onSnapshot ((snap ) => {
67
- console .log (" Eventually consistent view of visits: " + snap .get (" stats.visits" ));
68
- });
69
- </script >
70
- </body >
71
- </html >
72
- ```
40
+ ``` html
41
+ <html >
42
+ <head >
43
+ <script src =" https://www.gstatic.com/firebasejs/[version]/firebase-app.js" ></script >
44
+ <script src =" https://www.gstatic.com/firebasejs/[version]/firebase-firestore.js" ></script >
45
+ <script src =" sharded-counter.js" ></script >
46
+ </head >
47
+ <body >
48
+ <script >
49
+ // Initialize Firebase.
50
+ var firebaseConfig = { projectId: " ${PROJECT_ID}" };
51
+ firebase .initializeApp (firebaseConfig);
52
+ var db = firebase .firestore ();
53
+
54
+ // Initialize the sharded counter.
55
+ var visits = new sharded.Counter (db .doc (" pages/hello-world" ), " stats.visits" );
56
+
57
+ // Increment the field "stats.visits" of the document "pages/hello-world".
58
+ visits .incrementBy (1 );
59
+
60
+ // Listen to locally consistent values.
61
+ visits .onSnapshot ((snap ) => {
62
+ console .log (" Locally consistent view of visits: " + snap .data ());
63
+ });
64
+
65
+ // Alternatively, if you don't mind counter delays, you can listen to the document directly.
66
+ db .doc (" pages/hello-world" ).onSnapshot ((snap ) => {
67
+ console .log (" Eventually consistent view of visits: " + snap .get (" stats.visits" ));
68
+ });
69
+ </script >
70
+ </body >
71
+ </html >
72
+ ```
73
73
74
74
### Using the extension
75
75
0 commit comments