UNPKG

6.76 kBJavaScriptView Raw
1/**
2 * @constant
3 * @type {String}
4 * @description Prefix for all actions within library
5 * @example
6 * import { constants } from 'react-redux-firebase'
7 * constants.actionsPrefix === '@@reduxFirestore' // true
8 */
9export const actionsPrefix = '@@reduxFirestore';
10
11/**
12 * @constant
13 * @type {Object}
14 * @description Object containing all action types
15 * @property {String} START - `@@reduxFirestore/START`
16 * @property {String} ERROR - `@@reduxFirestore/ERROR`
17 * @property {String} SET_LISTENER - `@@reduxFirestore/SET_LISTENER`
18 * @property {String} UNSET_LISTENER - `@@reduxFirestore/UNSET_LISTENER`
19 * @property {String} LISTENER_RESPONSE - `@@reduxFirestore/LISTENER_RESPONSE`
20 * @property {String} LISTENER_ERROR - `@@reduxFirestore/LISTENER_ERROR`
21 * @property {String} CLEAR_DATA - `@@reduxFirestore/CLEAR_DATA`
22 * @property {String} CLEAR_ERROR - `@@reduxFirestore/CLEAR_ERROR`
23 * @property {String} CLEAR_ERRORS - `@@reduxFirestore/CLEAR_ERRORS`
24 * @property {String} GET_REQUEST - `@@reduxFirestore/GET_REQUEST`
25 * @property {String} GET_SUCCESS - `@@reduxFirestore/GET_SUCCESS`
26 * @property {String} GET_FAILURE - `@@reduxFirestore/GET_FAILURE`
27 * @property {String} SET_REQUEST - `@@reduxFirestore/SET_REQUEST`
28 * @property {String} SET_SUCCESS - `@@reduxFirestore/SET_SUCCESS`
29 * @property {String} SET_FAILURE - `@@reduxFirestore/SET_FAILURE`
30 * @property {String} ADD_REQUEST - `@@reduxFirestore/ADD_REQUEST`
31 * @property {String} ADD_SUCCESS - `@@reduxFirestore/ADD_SUCCESS`
32 * @property {String} ADD_FAILURE - `@@reduxFirestore/ADD_FAILURE`
33 * @property {String} UPDATE_REQUEST - `@@reduxFirestore/UPDATE_REQUEST`
34 * @property {String} UPDATE_SUCCESS - `@@reduxFirestore/UPDATE_SUCCESS`
35 * @property {String} UPDATE_FAILURE - `@@reduxFirestore/UPDATE_FAILURE`
36 * @property {String} DELETE_REQUEST - `@@reduxFirestore/DELETE_REQUEST`
37 * @property {String} DELETE_SUCCESS - `@@reduxFirestore/DELETE_SUCCESS`
38 * @property {String} DELETE_FAILURE - `@@reduxFirestore/DELETE_FAILURE`
39 * @property {String} ON_SNAPSHOT_REQUEST - `@@reduxFirestore/ON_SNAPSHOT_REQUEST`
40 * @property {String} ON_SNAPSHOT_SUCCESS - `@@reduxFirestore/ON_SNAPSHOT_SUCCESS`
41 * @property {String} ON_SNAPSHOT_FAILURE - `@@reduxFirestore/ON_SNAPSHOT_FAILURE`
42 * @property {String} TRANSACTION_START - `@@reduxFirestore/TRANSACTION_START`
43 * @property {String} TRANSACTION_SUCCESS - `@@reduxFirestore/TRANSACTION_SUCCESS`
44 * @property {String} TRANSACTION_FAILURE - `@@reduxFirestore/TRANSACTION_FAILURE`
45 * @example
46 * import { actionTypes } from 'react-redux-firebase'
47 * actionTypes.SET === '@@reduxFirestore/SET' // true
48 */
49export const actionTypes = {
50 START: `${actionsPrefix}/START`,
51 ERROR: `${actionsPrefix}/ERROR`,
52 CLEAR_DATA: `${actionsPrefix}/CLEAR_DATA`,
53 CLEAR_ERROR: `${actionsPrefix}/CLEAR_ERROR`,
54 CLEAR_ERRORS: `${actionsPrefix}/CLEAR_ERRORS`,
55 SET_LISTENER: `${actionsPrefix}/SET_LISTENER`,
56 UNSET_LISTENER: `${actionsPrefix}/UNSET_LISTENER`,
57 GET_REQUEST: `${actionsPrefix}/GET_REQUEST`,
58 GET_SUCCESS: `${actionsPrefix}/GET_SUCCESS`,
59 GET_FAILURE: `${actionsPrefix}/GET_FAILURE`,
60 SET_REQUEST: `${actionsPrefix}/SET_REQUEST`,
61 SET_SUCCESS: `${actionsPrefix}/SET_SUCCESS`,
62 SET_FAILURE: `${actionsPrefix}/SET_FAILURE`,
63 ADD_REQUEST: `${actionsPrefix}/ADD_REQUEST`,
64 ADD_SUCCESS: `${actionsPrefix}/ADD_SUCCESS`,
65 ADD_FAILURE: `${actionsPrefix}/ADD_FAILURE`,
66 UPDATE_REQUEST: `${actionsPrefix}/UPDATE_REQUEST`,
67 UPDATE_SUCCESS: `${actionsPrefix}/UPDATE_SUCCESS`,
68 UPDATE_FAILURE: `${actionsPrefix}/UPDATE_FAILURE`,
69 DELETE_REQUEST: `${actionsPrefix}/DELETE_REQUEST`,
70 DELETE_SUCCESS: `${actionsPrefix}/DELETE_SUCCESS`,
71 DELETE_FAILURE: `${actionsPrefix}/DELETE_FAILURE`,
72 ATTACH_LISTENER: `${actionsPrefix}/ATTACH_LISTENER`,
73 LISTENER_RESPONSE: `${actionsPrefix}/LISTENER_RESPONSE`,
74 LISTENER_ERROR: `${actionsPrefix}/LISTENER_ERROR`,
75 ON_SNAPSHOT_REQUEST: `${actionsPrefix}/ON_SNAPSHOT_REQUEST`,
76 ON_SNAPSHOT_SUCCESS: `${actionsPrefix}/ON_SNAPSHOT_SUCCESS`,
77 ON_SNAPSHOT_FAILURE: `${actionsPrefix}/ON_SNAPSHOT_FAILURE`,
78 DOCUMENT_ADDED: `${actionsPrefix}/DOCUMENT_ADDED`,
79 DOCUMENT_MODIFIED: `${actionsPrefix}/DOCUMENT_MODIFIED`,
80 DOCUMENT_REMOVED: `${actionsPrefix}/DOCUMENT_REMOVED`,
81 TRANSACTION_START: `${actionsPrefix}/TRANSACTION_START`,
82 TRANSACTION_SUCCESS: `${actionsPrefix}/TRANSACTION_SUCCESS`,
83 TRANSACTION_FAILURE: `${actionsPrefix}/TRANSACTION_FAILURE`,
84};
85
86/**
87 * @constant
88 * @type {Object}
89 * @name defaultConfig
90 * @description Default configuration options
91 * @property {Boolean} logListenerError - `true` Whether or not to use
92 * console.error to log listener error objects. Errors from listeners
93 * are helpful to developers on multiple occasions including when index
94 * needs to be added.
95 * @property {Object} preserveOnDelete - `null` Values to
96 * preserve from state when DELETE_SUCCESS action is dispatched. Note that this
97 * will not prevent the LISTENER_RESPONSE action from removing items from
98 * state.ordered if you have a listener attached.
99 * @property {Object} preserveOnListenerError - `null` Values to
100 * preserve from state when LISTENER_ERROR action is dispatched.
101 * @property {Boolean} enhancerNamespace - `'firestore'` Namespace under which
102 * enhancer places internal instance on redux store (i.e. store.firestore).
103 * @property {Boolean|Function} allowMultipleListeners - `false` Whether or not
104 * to allow multiple listeners to be attached for the same query. If a function
105 * is passed the arguments it receives are `listenerToAttach`,
106 * `currentListeners`, and the function should return a boolean.
107 * @property {Function} onAttemptCollectionDelete - `null` (arguments:
108 * `(queryOption, dispatch, firebase)`) Function run when attempting to delete
109 * a collection. If not provided (default) delete promise will be rejected with
110 * "Only documents can be deleted" unless. This is due to the fact that
111 * Collections can not be deleted from a client, it should instead be handled
112 * within a cloud function (which can be called by providing a promise
113 * to `onAttemptCollectionDelete` that calls the cloud function).
114 * @type {Object}
115 */
116export const defaultConfig = {
117 logListenerError: true,
118 enhancerNamespace: 'firestore',
119 helpersNamespace: null,
120 allowMultipleListeners: false,
121 preserveOnDelete: null,
122 preserveOnListenerError: null,
123 onAttemptCollectionDelete: null,
124 mergeOrdered: true,
125 mergeOrderedDocUpdates: true,
126 mergeOrderedCollectionUpdates: true,
127};
128
129export const methodsToAddFromFirestore = [
130 'collection',
131 'configureClient',
132 'doc',
133 'batch',
134 'disableNetwork',
135 'enableNetwork',
136 'enablePersistence',
137 'ensureClientConfigured',
138 'setLogLevel',
139 'settings',
140];
141
142export default {
143 actionsPrefix,
144 actionTypes,
145 defaultConfig,
146};