Skip to content

Commit c56f4da

Browse files
authored
v2.1.1
* fix(query): console.error for profile listener only called if `logErrors` config option is enabled * feat(core): `enableLogging` now only enables Firebase Database logging (`react-redux-firebase` errors now only logged when `logErrors` is truthy * fix(storage): remove getter that includes warning for "snaphot" misspelling (fires unnecessarily) * feat(docs): docs building/uploading scripts updated and simplified
2 parents d7fc3d1 + 8b11f39 commit c56f4da

File tree

12 files changed

+103
-753
lines changed

12 files changed

+103
-753
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ es/**
66
lib/**
77
_book/**
88
_site/**
9-
test/mocha.opts
109
docs/**

bin/api-docs-generate.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const exec = require('child_process').exec
1+
/* eslint-disable no-console */
2+
const exec = require('child-process-promise').exec
3+
24
const files = [
35
{
46
src: 'firebaseConnect.js',
@@ -41,27 +43,33 @@ const files = [
4143
dest: 'constants.md'
4244
}
4345
]
44-
const pathToDocumentationJs = 'node_modules/documentation/bin/documentation.js'
4546

46-
const generateDocForFile = (file) => {
47-
return new Promise((resolve, reject) => {
48-
exec(`${pathToDocumentationJs} build src/${file.src} -f md -o docs/api/${file.dest} --shallow`, (error, stdout) => {
49-
if (error !== null) {
50-
return reject(error)
51-
}
52-
resolve(stdout)
47+
function generateDocForFile(file) {
48+
return exec(
49+
`$(npm bin)/documentation build src/${file.src} -f md -o docs/api/${
50+
file.dest
51+
} --shallow`
52+
)
53+
.then(res => {
54+
console.log('Successfully generated', file.dest || file)
55+
return res
56+
})
57+
.catch(error => {
58+
console.log('error generating doc: ', error.message || error)
59+
return Promise.reject(error)
5360
})
54-
})
5561
}
5662

57-
(function () {
58-
files.forEach(file => {
59-
generateDocForFile(file)
60-
.then((res) => {
61-
console.log('Successfully generated', file) // eslint-disable-line no-console
62-
})
63-
.catch((err) => {
64-
console.log('error generating doc: ', err) // eslint-disable-line no-console
65-
})
66-
})
63+
;(async function() {
64+
console.log(
65+
'Generating API documentation (docs/api) from JSDoc comments within src...\n'
66+
)
67+
try {
68+
await Promise.all(files.map(generateDocForFile))
69+
console.log('\nAPI documentation generated successfully!')
70+
process.exit(0)
71+
} catch (err) {
72+
console.log('Error generating API documentation: ', err.message || err)
73+
process.exit(1)
74+
}
6775
})()

bin/api-docs-upload.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const first = [
1313
'_book/docs/README.md'
1414
]
1515

16-
const second = [
17-
'_book/gitbook/**',
18-
'_book/docs/**'
19-
]
16+
const second = ['_book/gitbook/**', '_book/docs/**']
2017

2118
const project = 'docs.react-redux-firebase.com'
2219

@@ -26,15 +23,15 @@ const project = 'docs.react-redux-firebase.com'
2623
* @return {Promise} Resolves with stdout of running command
2724
* @private
2825
*/
29-
const runCommand = (cmd) =>
30-
exec(cmd)
31-
.catch((err) =>
32-
Promise.reject(
33-
err.message && err.message.indexOf('not found') !== -1
34-
? new Error(`${cmd.split(' ')[0]} must be installed to upload`)
35-
: err
36-
)
26+
function runCommand(cmd) {
27+
return exec(cmd).catch(err =>
28+
Promise.reject(
29+
err.message && err.message.indexOf('not found') !== -1
30+
? new Error(`${cmd.split(' ')[0]} must be installed to upload`)
31+
: err
3732
)
33+
)
34+
}
3835

3936
/**
4037
* Upload file or folder to cloud storage. gsutil is used instead of
@@ -43,14 +40,16 @@ const runCommand = (cmd) =>
4340
* @return {Promise} Resolve with an object containing stdout and uploadPath
4441
* @private
4542
*/
46-
const upload = (entityPath) => {
43+
function upload(entityPath) {
4744
const prefix = `history/v${version.split('-')[0]}`
48-
const uploadPath = `${project}/${prefix}/${entityPath.replace('_book/', '').replace('/**', '')}`
45+
const uploadPath = `${project}/${prefix}/${entityPath
46+
.replace('_book/', '')
47+
.replace('/**', '')}`
4948
const command = `gsutil -m cp -r -a public-read ${entityPath} gs://${uploadPath}`
50-
return runCommand(command)
51-
.then(({ stdout, stderr }) =>
52-
stdout ? Promise.reject(stdout) : ({ output: stderr, uploadPath })
53-
)
49+
return runCommand(command).then(
50+
({ stdout, stderr }) =>
51+
stdout ? Promise.reject(stdout) : { output: stderr, uploadPath }
52+
)
5453
}
5554

5655
/**
@@ -59,32 +58,31 @@ const upload = (entityPath) => {
5958
* @return {Promise} Resolves with an array of upload results
6059
* @private
6160
*/
62-
const uploadList = (files) => {
61+
function uploadList(files) {
6362
return Promise.all(
6463
files.map(file =>
6564
upload(file)
6665
.then(({ uploadPath, output }) => {
6766
console.log(`Successfully uploaded: ${uploadPath}`) // eslint-disable-line no-console
6867
return output
6968
})
70-
.catch((err) => {
71-
console.log('error:', err.message || err) // eslint-disable-line no-console
69+
.catch(err => {
70+
console.log('Error uploading:', err.message || err) // eslint-disable-line no-console
7271
return Promise.reject(err)
7372
})
7473
)
7574
)
7675
}
7776

78-
(function () {
79-
runCommand('gsutil') // check for existence of gsutil
80-
.then(() => uploadList(first))
81-
.then(() => uploadList(second))
82-
.then(() => {
83-
console.log('Docs uploaded successfully') // eslint-disable-line no-console
84-
process.exit(0)
85-
})
86-
.catch((err) => {
87-
console.log('Error uploading docs:', err.message) // eslint-disable-line no-console
88-
process.exit(1)
89-
})
77+
;(async function() {
78+
try {
79+
await runCommand('gsutil') // check for existence of gsutil
80+
await uploadList(first)
81+
await uploadList(second)
82+
console.log('Docs uploaded successfully') // eslint-disable-line no-console
83+
process.exit(0)
84+
} catch (err) {
85+
console.log('Error uploading docs:', err.message) // eslint-disable-line no-console
86+
process.exit(1)
87+
}
9088
})()

docs/api/constants.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ Default configuration options
8787
- `sessions` **([String][4] \| [Function][5])** `sessions` Location on Firebase where user
8888
sessions are stored (only if presense is set). Often set to `'sessions'` or
8989
`'userSessions'`. If a function is passed, the arguments are: `(currentUser, firebase)`.
90-
- `enableLogging` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Whether or not firebase
90+
- `enableLogging` **[Boolean][6]** `false` Whether or not firebase
9191
database logging is enabled. Providing `true` turns on error logging
9292
(enabled by itself through `logErrors`).
93-
- `logErrors` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to log internal
93+
- `logErrors` **[Boolean][6]** `true` Whether or not to log internal
9494
Firebase errors (i.e. error querying or writing data) to the javascript
9595
console .
96-
- `preserveOnLogout` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** `null` Data parameters to
96+
- `preserveOnLogout` **([Array][7] \| [Object][8])** `null` Data parameters to
9797
preserve when logging out. If Array is passed, each item represents keys
9898
within state.firebase.data preserve. If an object is passed, Keys associate
9999
with parts of state to preserve, and the values are Arrays contain keys
@@ -107,9 +107,11 @@ Default configuration options
107107
whatever is returned from the function is set to that slice of state (`auth`).
108108
- `updateProfileOnLogin` **[Boolean][6]** `true` Whether or not to update
109109
user profile when logging in.
110-
- `useFirestoreForStorageMeta` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Write storage
110+
- `useFirestoreForProfile` **[Boolean][6]** `false` Write profile
111+
data to Firestore instead of Real Time Database.
112+
- `useFirestoreForStorageMeta` **[Boolean][6]** `false` Write storage
111113
file metadata to Firestore instead of Real Time Database.
112-
- `resetBeforeLogin` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to reset auth
114+
- `resetBeforeLogin` **[Boolean][6]** `true` Whether or not to reset auth
113115
and profile when logging in (see issue
114116
[#254][9]
115117
for more details).

docs/api/enhancer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ along side applyMiddleware.
4343
preserve when logging out. Keys associate with parts of state to preserve,
4444
and the values are Arrays contain keys for keys within that slice of state
4545
to preserve.
46-
- `config.useFirestoreForProfile` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Write profile
46+
- `config.useFirestoreForProfile` **[Boolean][4]** `false` Write profile
4747
data to Firestore instead of Real Time Database.
48-
- `config.useFirestoreForStorageMeta` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Write storage
48+
- `config.useFirestoreForStorageMeta` **[Boolean][4]** `false` Write storage
4949
file metadata to Firestore instead of Real Time Database.
50-
- `config.enableRedirectHandling` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
50+
- `config.enableRedirectHandling` **[Boolean][4]** Whether or not to enable
5151
auth redirect handling listener. (default: `true`)
5252
- `config.onAuthStateChanged` **[Function][5]** Function run when auth state
5353
changes. Argument Pattern: `(authData, firebase, dispatch)`

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -9,7 +9,7 @@
99
"unpkg": "dist/react-redux-firebase.min.js",
1010
"scripts": {
1111
"clean": "rimraf es lib dist coverage",
12-
"lint": "eslint src/** test/unit/** test/setup.js",
12+
"lint": "eslint ./src/** ./bin/** ./test/**/*.js",
1313
"lint:fix": "npm run lint -- --fix",
1414
"format": "prettier --write \"src/**/*.js\" \"test/**/*.js\"",
1515
"test": "mocha -R spec ./test/unit/**",
@@ -26,11 +26,11 @@
2626
"prepush": "npm run lint",
2727
"docs:clean": "rimraf _book",
2828
"docs:prepare": "gitbook install",
29-
"docs:api": "node bin/api-docs-generate",
29+
"docs:api": "babel-node bin/api-docs-generate",
3030
"docs:build": "npm run docs:prepare && gitbook build -g prescottprue/react-redux-firebase && npm run docs:api",
3131
"docs:watch": "npm run docs:prepare && gitbook serve",
3232
"docs:publish": "npm run docs:clean && npm run docs:build && cp CNAME _book && cd _book && git init && git commit --allow-empty -m 'update book' && git checkout -b gh-pages && touch .nojekyll && git add . && git commit -am 'update book' && git push [email protected]:prescottprue/react-redux-firebase gh-pages --force",
33-
"docs:upload": "node bin/api-docs-upload"
33+
"docs:upload": "babel-node bin/api-docs-upload"
3434
},
3535
"license": "MIT",
3636
"homepage": "http://react-redux-firebase.com",

src/actions/auth.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ export const handleProfileWatchResponse = (
141141
* @private
142142
*/
143143
function createProfileWatchErrorHandler(dispatch, firebase) {
144-
const { config: { onProfileListenerError } } = firebase._
145-
return err => {
146-
/* eslint-disable no-console */
147-
console.error(`Error with profile listener: ${err.message || ''}`, err)
144+
const { config: { onProfileListenerError, logErrors } } = firebase._
145+
return function handleProfileError(err) {
146+
if (logErrors) {
147+
// eslint-disable-next-line no-console
148+
console.error(`Error with profile listener: ${err.message || ''}`, err)
149+
}
148150
if (isFunction(onProfileListenerError)) {
149151
const factoryResult = onProfileListenerError(err, firebase)
152+
// Return factoryResult if it is a promise
150153
if (isFunction(factoryResult.then)) {
151154
return factoryResult
152155
}

src/actions/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const watchEvent = (firebase, dispatch, options) => {
3535
isQuery,
3636
storeAs
3737
} = options
38-
const { config: { enableLogging, logErrors } } = firebase._
38+
const { config: { logErrors } } = firebase._
3939

4040
const watchPath = !storeAs ? path : `${path}@${storeAs}`
4141
const id = queryId || getQueryIdFromPath(path)
@@ -159,7 +159,7 @@ export const watchEvent = (firebase, dispatch, options) => {
159159
})
160160
},
161161
err => {
162-
if (enableLogging || logErrors) {
162+
if (logErrors) {
163163
// eslint-disable-next-line no-console
164164
console.log(
165165
`RRF: Error retrieving data for path: ${path}, storeAs: ${storeAs}. Firebase:`,

src/actions/storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const uploadFile = (dispatch, firebase, config) => {
3636
throw new Error('Firebase storage is required to upload files')
3737
}
3838
const { path, file, dbPath, options = { progress: false } } = config || {}
39-
const { enableLogging, logErrors } = firebase._.config
39+
const { logErrors } = firebase._.config
4040

4141
// File renaming through options (supporting string and function)
4242
const nameFromOptions = isFunction(options.name)
@@ -95,7 +95,7 @@ export const uploadFile = (dispatch, firebase, config) => {
9595
})
9696
})
9797
.catch(err => {
98-
if (enableLogging || logErrors) {
98+
if (logErrors) {
9999
/* eslint-disable no-console */
100100
console.error &&
101101
console.error(`RRF: Error uploading file: ${err.message || err}`, err)

0 commit comments

Comments
 (0)