Skip to content

Commit dbcc49c

Browse files
committed
Added why section in readme and renamed to in the README
1 parent b5e71c6 commit dbcc49c

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Firestack makes using the latest [Firebase](http://firebase.com) straight-forwar
66

77
Firestack is a _light-weight_ layer sitting atop the native Firebase libraries for iOS and Android (coming soon), deferring to as much of the JavaScript library as possible. For parts of the api that are natively supported by the Firebase JavaScript api, this library acts as a thin proxy to the JS objects, while it provides a native shim to those that are not covered.
88

9+
## Why?
10+
11+
Firebase is awesome and it's combination with the Google Cloud Platform makes it super awesome. Sadly, the latest version of Firebase requires the `window` object. That's where Firestack comes in! Firestack provides a really thin layer that sits on top of the native Firebase SDKs and attempts to use the JavaScript library as much as possible rather than reinventing the wheel.
12+
913
## Installing
1014

1115
Install the `npm` package with:
@@ -88,8 +92,8 @@ import Firestack from 'react-native-firestack'
8892
We need to tell the Firebase library we want to _configure_ the project. Firestack provides a way to configure both the native and the JavaScript side of the project at the same time with a single command:
8993

9094
```javascript
91-
const server = new Firestack();
92-
server.configure()
95+
const firestack = new Firestack();
96+
firestack.configure()
9397
.then(() => console.log("Project configured and ready to boot"));
9498
```
9599

@@ -106,7 +110,7 @@ Firestack handles authentication for us out of the box, both with email/password
106110
Firebase gives us a reactive method for listening for authentication. That is we can set up a listener to call a method when the user logs in and out. To set up the listener, call the `listenForAuth()` method:
107111

108112
```javascript
109-
server.listenForAuth(function(evt) {
113+
firestack.listenForAuth(function(evt) {
110114
// evt is the authentication event
111115
// it contains an `error` key for carrying the
112116
// error message in case of an error
@@ -127,15 +131,15 @@ server.listenForAuth(function(evt) {
127131
We can remove this listener by calling the `unlistenForAuth()` method. This is important to release resources from our app when we don't need to hold on to the listener any longer.
128132

129133
```javascript
130-
server.unlistenForAuth()
134+
firestack.unlistenForAuth()
131135
```
132136

133137
#### createUserWithEmail()
134138

135139
We can create a user by calling the `createUserWithEmail()` function. The `createUserWithEmail()` accepts two parameters, an email and a password.
136140

137141
```javascript
138-
server.createUserWithEmail('ari@fullstack.io', '123456')
142+
firestack.createUserWithEmail('ari@fullstack.io', '123456')
139143
.then((user) => {
140144
console.log('user created', user)
141145
})
@@ -149,7 +153,7 @@ server.createUserWithEmail('ari@fullstack.io', '123456')
149153
To sign a user in with their email and password, use the `signInWithEmail()` function. It accepts two parameters, the user's email and password:
150154

151155
```javascript
152-
server.signInWithEmail('ari@fullstack.io', '123456')
156+
firestack.signInWithEmail('ari@fullstack.io', '123456')
153157
.then((user) => {
154158
console.log('User successfully logged in', user)
155159
})
@@ -163,7 +167,7 @@ server.signInWithEmail('ari@fullstack.io', '123456')
163167
To sign a user using a self-signed custom token, use the `signInWithCustomToken()` function. It accepts one parameter, the custom token:
164168

165169
```javascript
166-
server.signInWithCustomToken(TOKEN)
170+
firestack.signInWithCustomToken(TOKEN)
167171
.then((user) => {
168172
console.log('User successfully logged in', user)
169173
})
@@ -205,7 +209,7 @@ Once the app is configured with the instructions, we can call the `oauthManager`
205209
const appUrl = 'app-uri://oauth-callback/twitter'
206210
authManager.authorizeWithCallbackURL('twitter', appUrl)
207211
.then(creds => {
208-
return server.signInWithProvider('twitter', creds.oauth_token, creds.oauth_token_secret)
212+
return firestack.signInWithProvider('twitter', creds.oauth_token, creds.oauth_token_secret)
209213
.then(() => {
210214
// We're now signed in through Firebase
211215
})
@@ -226,7 +230,7 @@ When the auth token has expired, we can ask firebase to reauthenticate with the
226230
We can update the current user's email by using the command: `updateUserEmail()`. It accepts a single argument: the user's new email:
227231

228232
```javascript
229-
server.updateUserEmail('ari+rocks@fullstack.io')
233+
firestack.updateUserEmail('ari+rocks@fullstack.io')
230234
.then((res) => console.log('Updated user email'))
231235
.catch(err => console.error('There was an error updating user email'))
232236
```
@@ -236,7 +240,7 @@ server.updateUserEmail('ari+rocks@fullstack.io')
236240
We can update the current user's password using the `updateUserPassword()` method. It accepts a single parameter: the new password for the current user
237241

238242
```javascript
239-
server.updateUserPassword('somethingReallyS3cr3t733t')
243+
firestack.updateUserPassword('somethingReallyS3cr3t733t')
240244
.then(res => console.log('Updated user password'))
241245
.catch(err => console.error('There was an error updating your password'))
242246
```
@@ -246,7 +250,7 @@ server.updateUserPassword('somethingReallyS3cr3t733t')
246250
To send a password reset for a user based upon their email, we can call the `sendPasswordResetWithEmail()` method. It accepts a single parameter: the email of the user to send a reset email.
247251

248252
```javascript
249-
server.sendPasswordResetWithEmail('ari+rocks@fullstack.io')
253+
firestack.sendPasswordResetWithEmail('ari+rocks@fullstack.io')
250254
.then(res => console.log('Check your inbox for further instructions'))
251255
.catch(err => console.error('There was an error :('))
252256
```
@@ -260,7 +264,7 @@ It accepts a single parameter:
260264
* object which contains updated key/values for the user's profile. Possible keys are listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile).
261265

262266
```javascript
263-
server.updateUserProfile({
267+
firestack.updateUserProfile({
264268
displayName: 'Ari Lerner'
265269
})
266270
.then(res => console.log('Your profile has been updated'))
@@ -272,7 +276,7 @@ server.updateUserProfile({
272276
It's possible to delete a user completely from your account on Firebase. Calling the `deleteUser()` method will take care of this for you.
273277

274278
```javascript
275-
server.deleteUser()
279+
firestack.deleteUser()
276280
.then(res => console.log('Sad to see you go'))
277281
.catch(err => console.error('There was an error - Now you are trapped!'))
278282
```
@@ -282,7 +286,7 @@ server.deleteUser()
282286
To sign the current user out, use the `signOut()` method. It accepts no parameters
283287

284288
```javascript
285-
server.signOut()
289+
firestack.signOut()
286290
.then(res => console.log('You have been signed out'))
287291
.catch(err => console.error('Uh oh... something weird happened'))
288292
```
@@ -292,7 +296,7 @@ server.signOut()
292296
Although you _can_ get the current user using the `getCurrentUser()` method, it's better to use this from within the callback function provided by `listenForAuth()`. However, if you need to get the current user, call the `getCurrentUser()` method:
293297

294298
```javascript
295-
server.getCurrentUser()
299+
firestack.getCurrentUser()
296300
.then(user => console.log('The currently logged in user', user))
297301
.catch(err => console.error('An error occurred'))
298302
```
@@ -304,7 +308,7 @@ Wouldn't it be nice to send analytics about your app usage from your users? Well
304308
#### logEventWithName()
305309

306310
```javascript
307-
server.logEventWithName("launch", {
311+
firestack.logEventWithName("launch", {
308312
'screen': 'Main screen'
309313
})
310314
.then(res => console.log('Sent event named launch'))
@@ -324,7 +328,7 @@ In order to store anything on Firebase, we need to set the storage url provided
324328
The `setStorageUrl()` method accepts a single parameter: your root storage url.
325329

326330
```javascript
327-
server.setStorageUrl(`gs://${config.firebase.storageBucket}`)
331+
firestack.setStorageUrl(`gs://${config.firebase.storageBucket}`)
328332
.then(() => console.log('The storage url has been set'))
329333
.catch(() => console.error('This is weird: something happened...'))
330334
```
@@ -334,7 +338,7 @@ server.setStorageUrl(`gs://${config.firebase.storageBucket}`)
334338
We can upload a file using the `uploadFile()` method. Using the `uploadFile()` method, we can set the name of the destination file, the path where we want to store it, as well as any metadata along with the file.
335339

336340
```javascript
337-
server.uploadFile(`photos/${auth.user.uid}/${filename}`, path, {
341+
firestack.uploadFile(`photos/${auth.user.uid}/${filename}`, path, {
338342
contentType: 'image/jpeg',
339343
contentEncoding: 'base64',
340344
})
@@ -347,7 +351,7 @@ To upload camera photos, we can combine this method with the `react-native-camer
347351
```javascript
348352
this.camera.capture()
349353
.then(({path}) => {
350-
server.uploadFile(`photos/${auth.user.uid}/${filename}`, path, {
354+
firestack.uploadFile(`photos/${auth.user.uid}/${filename}`, path, {
351355
contentType: 'image/jpeg',
352356
contentEncoding: 'base64',
353357
})
@@ -360,7 +364,7 @@ this.camera.capture()
360364
To retrieve a stored file, we can get the url to download it from using the `storage` attribute. This method allows us to call right through to the native JavaScript object provided by the Firebase library:
361365

362366
```javascript
363-
server.storage.ref(photo.fullPath)
367+
firestack.storage.ref(photo.fullPath)
364368
.getDownloadURL()
365369
.then(url => {
366370
// url contains the download url
@@ -376,7 +380,7 @@ server.storage.ref(photo.fullPath)
376380
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.
377381

378382
```javascript
379-
server.database
383+
firestack.database
380384
.ref(LIST_KEY)
381385
.orderByChild('timestamp')
382386
.on('value', snapshot => {
@@ -391,7 +395,7 @@ server.database
391395
Firebase provides some static values based upon the server. We can use the `ServerValue` constant to retrieve these. For instance, to grab the TIMESTAMP on the server, use the `TIMESTAMP` value:
392396

393397
```javascript
394-
const timestamp = server.ServerValue.TIMESTAMP
398+
const timestamp = firestack.ServerValue.TIMESTAMP
395399
```
396400

397401
### Events
@@ -401,15 +405,15 @@ const timestamp = server.ServerValue.TIMESTAMP
401405
We can listen to arbitrary events fired by the Firebase library using the `on()` method. The `on()` method accepts a name and a function callback:
402406

403407
```javascript
404-
server.on('listenForAuth', (evt) => console.log('Got an event'));
408+
firestack.on('listenForAuth', (evt) => console.log('Got an event'));
405409
```
406410

407411
#### off()
408412

409413
To unsubscribe to events fired by Firebase, we can call the `off()` method with the name of the event we want to unsubscribe.
410414

411415
```javascript
412-
server.off('listenForAuth');
416+
firestack.off('listenForAuth');
413417
```
414418

415419
## Contributing

0 commit comments

Comments
 (0)