Skip to content

Commit ee4f83e

Browse files
authored
Prefer arrow functions, const (#99)
1 parent 6287773 commit ee4f83e

File tree

11 files changed

+101
-100
lines changed

11 files changed

+101
-100
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"arrow-spacing": ["error"],
1414
"no-const-assign": ["error"],
1515
"prefer-const": ["error"],
16+
"prefer-arrow-callback": ["error"],
1617
"spaced-comment": ["error", "always"],
1718
"semi": ["error", "always"]
1819
}

auth/cordova.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function createGoogleProvider() {
1414

1515
function cordovaSignInRedirect(provider) {
1616
// [START auth_cordova_sign_in_redirect]
17-
firebase.auth().signInWithRedirect(provider).then(function() {
17+
firebase.auth().signInWithRedirect(provider).then(() => {
1818
return firebase.auth().getRedirectResult();
1919
}).then((result) => {
2020
/** @type {firebase.auth.OAuthCredential} */

auth/firebaseui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ function fuiConfig() {
218218
// [START auth_fui_config]
219219
var uiConfig = {
220220
callbacks: {
221-
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
221+
signInSuccessWithAuthResult: (authResult, redirectUrl) => {
222222
// User successfully signed in.
223223
// Return type determines whether we continue the redirect automatically
224224
// or whether we leave that to developer to handle.
225225
return true;
226226
},
227-
uiShown: function() {
227+
uiShown: () => {
228228
// The widget is rendered.
229229
// Hide the loader.
230230
document.getElementById('loader').style.display = 'none';

auth/link-multiple-accounts.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ function getProviders() {
4141
function simpleLink(credential) {
4242
// [START auth_simple_link]
4343
auth.currentUser.linkWithCredential(credential)
44-
.then(function(usercred) {
44+
.then((usercred) => {
4545
var user = usercred.user;
4646
console.log("Account linking success", user);
47-
}).catch(function(error) {
47+
}).catch((error) => {
4848
console.log("Account linking error", error);
4949
});
5050
// [END auth_simple_link]
@@ -53,10 +53,10 @@ function simpleLink(credential) {
5353
function anonymousLink(credential) {
5454
// [START auth_anonymous_link]
5555
auth.currentUser.linkWithCredential(credential)
56-
.then(function(usercred) {
56+
.then((usercred) => {
5757
var user = usercred.user;
5858
console.log("Anonymous account successfully upgraded", user);
59-
}).catch(function(error) {
59+
}).catch((error) => {
6060
console.log("Error upgrading anonymous account", error);
6161
});
6262
// [END auth_anonymous_link]
@@ -66,12 +66,12 @@ function linkWithPopup() {
6666
var provider = new firebase.auth.GoogleAuthProvider();
6767

6868
// [START auth_link_with_popup]
69-
auth.currentUser.linkWithPopup(provider).then(function(result) {
69+
auth.currentUser.linkWithPopup(provider).then((result) => {
7070
// Accounts successfully linked.
7171
var credential = result.credential;
7272
var user = result.user;
7373
// ...
74-
}).catch(function(error) {
74+
}).catch((error) => {
7575
// Handle Errors here.
7676
// ...
7777
});
@@ -88,14 +88,14 @@ function linkWithRedirect() {
8888
// [END auth_link_with_redirect]
8989

9090
// [START auth_get_redirect_result]
91-
auth.getRedirectResult().then(function(result) {
91+
auth.getRedirectResult().then((result) => {
9292
if (result.credential) {
9393
// Accounts successfully linked.
9494
var credential = result.credential;
9595
var user = result.user;
9696
// ...
9797
}
98-
}).catch(function(error) {
98+
}).catch((error) => {
9999
// Handle Errors here.
100100
// ...
101101
});
@@ -118,7 +118,7 @@ function mergeAccounts(newCredential) {
118118
repo.delete(prevUser);
119119

120120
// Sign in user with the account you want to link to
121-
auth.signInWithCredential(newCredential).then(function(result) {
121+
auth.signInWithCredential(newCredential).then((result) => {
122122
console.log("Sign In Success", result);
123123
var currentUser = result.user;
124124
var currentUserData = repo.get(currentUser);
@@ -128,15 +128,15 @@ function mergeAccounts(newCredential) {
128128
var mergedData = repo.merge(prevUserData, currentUserData);
129129

130130
return prevUser.linkWithCredential(result.credential)
131-
.then(function(linkResult) {
131+
.then((linkResult) => {
132132
// Sign in with the newly linked credential
133133
return auth.signInWithCredential(linkResult.credential);
134134
})
135-
.then(function(signInResult) {
135+
.then((signInResult) => {
136136
// Save the merged data to the new user
137137
repo.set(signInResult.user, mergedData);
138138
});
139-
}).catch(function(error) {
139+
}).catch((error) => {
140140
// If there are errors we want to undo the data merge/deletion
141141
console.log("Sign In Error", error);
142142
repo.set(prevUser, prevUserData);
@@ -157,10 +157,10 @@ function unlink(providerId) {
157157
var user = auth.currentUser;
158158

159159
// [START auth_unlink_provider]
160-
user.unlink(providerId).then(function() {
160+
user.unlink(providerId).then(() => {
161161
// Auth provider unlinked from account
162162
// ...
163-
}).catch(function(error) {
163+
}).catch((error) => {
164164
// An error happened
165165
// ...
166166
});

database/read-and-write.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) {
2020
username: name,
2121
email: email,
2222
profile_picture : imageUrl
23-
}, function(error) {
23+
}, (error) => {
2424
if (error) {
2525
// The write failed...
2626
} else {

firestore-next/test.firestore.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class City {
1616
}
1717

1818
// Firestore data converter
19-
var cityConverter = {
20-
toFirestore: function(city) {
19+
const cityConverter = {
20+
toFirestore: (city) => {
2121
return {
2222
name: city.name,
2323
state: city.state,
2424
country: city.country
2525
};
2626
},
27-
fromFirestore: function(snapshot, options){
27+
fromFirestore: (snapshot, options) => {
2828
const data = snapshot.data(options);
2929
return new City(data.name, data.state, data.country);
3030
}
@@ -190,7 +190,7 @@ describe("firestore", () => {
190190
const q = query(collection(db, "users"), where("born", "<", 1900));
191191
const unsubscribe = onSnapshot(q, (snapshot) => {
192192
console.log("Current users born before 1900:");
193-
snapshot.forEach(function (userSnapshot) {
193+
snapshot.forEach((userSnapshot) => {
194194
console.log(userSnapshot.data());
195195
});
196196
});
@@ -360,7 +360,7 @@ describe("firestore", () => {
360360
function deleteCollection(db, collectionRef, batchSize) {
361361
const q = query(collectionRef, orderBy('__name__'), limit(batchSize));
362362

363-
return new Promise(function(resolve) {
363+
return new Promise((resolve) => {
364364
deleteQueryBatch(db, q, batchSize, resolve);
365365
});
366366
}
@@ -616,7 +616,7 @@ describe("firestore", () => {
616616
});
617617
// [END listen_document]
618618

619-
setTimeout(function() {
619+
setTimeout(() => {
620620
unsub();
621621
done();
622622
}, 3000);
@@ -632,7 +632,7 @@ describe("firestore", () => {
632632
});
633633
// [END listen_document_local]
634634

635-
setTimeout(function() {
635+
setTimeout(() => {
636636
unsub();
637637
done();
638638
}, 3000);
@@ -650,7 +650,7 @@ describe("firestore", () => {
650650
});
651651
// [END listen_with_metadata]
652652

653-
setTimeout(function() {
653+
setTimeout(() => {
654654
unsub();
655655
done();
656656
}, 3000);
@@ -695,7 +695,7 @@ describe("firestore", () => {
695695
console.log("Current cities in CA: ", cities.join(", "));
696696
});
697697
// [END listen_multiple]
698-
setTimeout(function() {
698+
setTimeout(() => {
699699
unsubscribe();
700700
done();
701701
}, 2500);
@@ -720,7 +720,7 @@ describe("firestore", () => {
720720
});
721721
});
722722
// [END listen_diffs]
723-
setTimeout(function() {
723+
setTimeout(() => {
724724
unsubscribe();
725725
done();
726726
}, 2500);

0 commit comments

Comments
 (0)