1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types'], factory) :
|
4 | (global = global || self, factory(global.ReactFirestore = {}, global.React, global.PropTypes));
|
5 | }(this, function (exports, React, PropTypes) { 'use strict';
|
6 |
|
7 | var React__default = 'default' in React ? React['default'] : React;
|
8 | PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
|
9 |
|
10 | function _inheritsLoose(subClass, superClass) {
|
11 | subClass.prototype = Object.create(superClass.prototype);
|
12 | subClass.prototype.constructor = subClass;
|
13 | subClass.__proto__ = superClass;
|
14 | }
|
15 |
|
16 | var FirestoreCache = function () {};
|
17 |
|
18 | var FirestoreContext = React__default.createContext(null);
|
19 |
|
20 | var FirestoreProvider =
|
21 |
|
22 | function (_Component) {
|
23 | _inheritsLoose(FirestoreProvider, _Component);
|
24 |
|
25 | function FirestoreProvider(props) {
|
26 | var _this = _Component.call(this, props) || this;
|
27 |
|
28 | var firebase = props.firebase,
|
29 | useTimestampsInSnapshots = props.useTimestampsInSnapshots;
|
30 | var firestore = firebase.firestore();
|
31 |
|
32 | if (typeof useTimestampsInSnapshots !== 'undefined') {
|
33 | firestore.settings({
|
34 | timestampsInSnapshots: useTimestampsInSnapshots
|
35 | });
|
36 | }
|
37 |
|
38 | _this.state = {
|
39 | firestoreDatabase: firestore,
|
40 | firestoreCache: new FirestoreCache()
|
41 | };
|
42 | return _this;
|
43 | }
|
44 |
|
45 | var _proto = FirestoreProvider.prototype;
|
46 |
|
47 | _proto.render = function render() {
|
48 | return React__default.createElement(FirestoreContext.Provider, {
|
49 | value: this.state
|
50 | }, this.props.children);
|
51 | };
|
52 |
|
53 | return FirestoreProvider;
|
54 | }(React.Component);
|
55 |
|
56 | FirestoreProvider.defaultProps = {};
|
57 | FirestoreProvider.propTypes = {
|
58 | firebase: PropTypes.object.isRequired,
|
59 | children: PropTypes.node.isRequired,
|
60 | useTimestampsInSnapshots: PropTypes.bool
|
61 | };
|
62 |
|
63 | var Firestore = function (_ref) {
|
64 | var render = _ref.render;
|
65 | return React__default.createElement(FirestoreContext.Consumer, null, function (_ref2) {
|
66 | var firestoreDatabase = _ref2.firestoreDatabase;
|
67 | return render({
|
68 | firestore: firestoreDatabase
|
69 | });
|
70 | });
|
71 | };
|
72 |
|
73 | Firestore.propTypes = {
|
74 | render: PropTypes.func.isRequired
|
75 | };
|
76 |
|
77 | function _extends() {
|
78 | _extends = Object.assign || function (target) {
|
79 | for (var i = 1; i < arguments.length; i++) {
|
80 | var source = arguments[i];
|
81 |
|
82 | for (var key in source) {
|
83 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
84 | target[key] = source[key];
|
85 | }
|
86 | }
|
87 | }
|
88 |
|
89 | return target;
|
90 | };
|
91 |
|
92 | return _extends.apply(this, arguments);
|
93 | }
|
94 |
|
95 | function _objectWithoutPropertiesLoose(source, excluded) {
|
96 | if (source == null) return {};
|
97 | var target = {};
|
98 | var sourceKeys = Object.keys(source);
|
99 | var key, i;
|
100 |
|
101 | for (i = 0; i < sourceKeys.length; i++) {
|
102 | key = sourceKeys[i];
|
103 | if (excluded.indexOf(key) >= 0) continue;
|
104 | target[key] = source[key];
|
105 | }
|
106 |
|
107 | return target;
|
108 | }
|
109 |
|
110 | function unwrapExports (x) {
|
111 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
|
112 | }
|
113 |
|
114 | function createCommonjsModule(fn, module) {
|
115 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
116 | }
|
117 |
|
118 | var reactIs_production_min = createCommonjsModule(function (module, exports) {
|
119 |
|
120 | Object.defineProperty(exports, "__esModule", {
|
121 | value: !0
|
122 | });
|
123 | var b = "function" === typeof Symbol && Symbol.for,
|
124 | c = b ? Symbol.for("react.element") : 60103,
|
125 | d = b ? Symbol.for("react.portal") : 60106,
|
126 | e = b ? Symbol.for("react.fragment") : 60107,
|
127 | f = b ? Symbol.for("react.strict_mode") : 60108,
|
128 | g = b ? Symbol.for("react.profiler") : 60114,
|
129 | h = b ? Symbol.for("react.provider") : 60109,
|
130 | k = b ? Symbol.for("react.context") : 60110,
|
131 | l = b ? Symbol.for("react.async_mode") : 60111,
|
132 | m = b ? Symbol.for("react.concurrent_mode") : 60111,
|
133 | n = b ? Symbol.for("react.forward_ref") : 60112,
|
134 | p = b ? Symbol.for("react.suspense") : 60113,
|
135 | q = b ? Symbol.for("react.memo") : 60115,
|
136 | r = b ? Symbol.for("react.lazy") : 60116;
|
137 |
|
138 | function t(a) {
|
139 | if ("object" === typeof a && null !== a) {
|
140 | var u = a.$$typeof;
|
141 |
|
142 | switch (u) {
|
143 | case c:
|
144 | switch (a = a.type, a) {
|
145 | case l:
|
146 | case m:
|
147 | case e:
|
148 | case g:
|
149 | case f:
|
150 | case p:
|
151 | return a;
|
152 |
|
153 | default:
|
154 | switch (a = a && a.$$typeof, a) {
|
155 | case k:
|
156 | case n:
|
157 | case h:
|
158 | return a;
|
159 |
|
160 | default:
|
161 | return u;
|
162 | }
|
163 |
|
164 | }
|
165 |
|
166 | case r:
|
167 | case q:
|
168 | case d:
|
169 | return u;
|
170 | }
|
171 | }
|
172 | }
|
173 |
|
174 | function v(a) {
|
175 | return t(a) === m;
|
176 | }
|
177 |
|
178 | exports.typeOf = t;
|
179 | exports.AsyncMode = l;
|
180 | exports.ConcurrentMode = m;
|
181 | exports.ContextConsumer = k;
|
182 | exports.ContextProvider = h;
|
183 | exports.Element = c;
|
184 | exports.ForwardRef = n;
|
185 | exports.Fragment = e;
|
186 | exports.Lazy = r;
|
187 | exports.Memo = q;
|
188 | exports.Portal = d;
|
189 | exports.Profiler = g;
|
190 | exports.StrictMode = f;
|
191 | exports.Suspense = p;
|
192 |
|
193 | exports.isValidElementType = function (a) {
|
194 | return "string" === typeof a || "function" === typeof a || a === e || a === m || a === g || a === f || a === p || "object" === typeof a && null !== a && (a.$$typeof === r || a.$$typeof === q || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n);
|
195 | };
|
196 |
|
197 | exports.isAsyncMode = function (a) {
|
198 | return v(a) || t(a) === l;
|
199 | };
|
200 |
|
201 | exports.isConcurrentMode = v;
|
202 |
|
203 | exports.isContextConsumer = function (a) {
|
204 | return t(a) === k;
|
205 | };
|
206 |
|
207 | exports.isContextProvider = function (a) {
|
208 | return t(a) === h;
|
209 | };
|
210 |
|
211 | exports.isElement = function (a) {
|
212 | return "object" === typeof a && null !== a && a.$$typeof === c;
|
213 | };
|
214 |
|
215 | exports.isForwardRef = function (a) {
|
216 | return t(a) === n;
|
217 | };
|
218 |
|
219 | exports.isFragment = function (a) {
|
220 | return t(a) === e;
|
221 | };
|
222 |
|
223 | exports.isLazy = function (a) {
|
224 | return t(a) === r;
|
225 | };
|
226 |
|
227 | exports.isMemo = function (a) {
|
228 | return t(a) === q;
|
229 | };
|
230 |
|
231 | exports.isPortal = function (a) {
|
232 | return t(a) === d;
|
233 | };
|
234 |
|
235 | exports.isProfiler = function (a) {
|
236 | return t(a) === g;
|
237 | };
|
238 |
|
239 | exports.isStrictMode = function (a) {
|
240 | return t(a) === f;
|
241 | };
|
242 |
|
243 | exports.isSuspense = function (a) {
|
244 | return t(a) === p;
|
245 | };
|
246 | });
|
247 | unwrapExports(reactIs_production_min);
|
248 | var reactIs_production_min_1 = reactIs_production_min.typeOf;
|
249 | var reactIs_production_min_2 = reactIs_production_min.AsyncMode;
|
250 | var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode;
|
251 | var reactIs_production_min_4 = reactIs_production_min.ContextConsumer;
|
252 | var reactIs_production_min_5 = reactIs_production_min.ContextProvider;
|
253 | var reactIs_production_min_6 = reactIs_production_min.Element;
|
254 | var reactIs_production_min_7 = reactIs_production_min.ForwardRef;
|
255 | var reactIs_production_min_8 = reactIs_production_min.Fragment;
|
256 | var reactIs_production_min_9 = reactIs_production_min.Lazy;
|
257 | var reactIs_production_min_10 = reactIs_production_min.Memo;
|
258 | var reactIs_production_min_11 = reactIs_production_min.Portal;
|
259 | var reactIs_production_min_12 = reactIs_production_min.Profiler;
|
260 | var reactIs_production_min_13 = reactIs_production_min.StrictMode;
|
261 | var reactIs_production_min_14 = reactIs_production_min.Suspense;
|
262 | var reactIs_production_min_15 = reactIs_production_min.isValidElementType;
|
263 | var reactIs_production_min_16 = reactIs_production_min.isAsyncMode;
|
264 | var reactIs_production_min_17 = reactIs_production_min.isConcurrentMode;
|
265 | var reactIs_production_min_18 = reactIs_production_min.isContextConsumer;
|
266 | var reactIs_production_min_19 = reactIs_production_min.isContextProvider;
|
267 | var reactIs_production_min_20 = reactIs_production_min.isElement;
|
268 | var reactIs_production_min_21 = reactIs_production_min.isForwardRef;
|
269 | var reactIs_production_min_22 = reactIs_production_min.isFragment;
|
270 | var reactIs_production_min_23 = reactIs_production_min.isLazy;
|
271 | var reactIs_production_min_24 = reactIs_production_min.isMemo;
|
272 | var reactIs_production_min_25 = reactIs_production_min.isPortal;
|
273 | var reactIs_production_min_26 = reactIs_production_min.isProfiler;
|
274 | var reactIs_production_min_27 = reactIs_production_min.isStrictMode;
|
275 | var reactIs_production_min_28 = reactIs_production_min.isSuspense;
|
276 |
|
277 | var reactIs_development = createCommonjsModule(function (module, exports) {
|
278 |
|
279 | (function () {
|
280 | Object.defineProperty(exports, '__esModule', {
|
281 | value: true
|
282 | });
|
283 |
|
284 |
|
285 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
286 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
287 | var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
288 | var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
289 | var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
290 | var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
291 | var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
292 | var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
293 | var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
294 | var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
295 | var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
296 | var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
297 | var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
298 | var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
299 |
|
300 | |
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 | var lowPriorityWarning = function () {};
|
314 |
|
315 | {
|
316 | var printWarning = function (format) {
|
317 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
318 | args[_key - 1] = arguments[_key];
|
319 | }
|
320 |
|
321 | var argIndex = 0;
|
322 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
323 | return args[argIndex++];
|
324 | });
|
325 |
|
326 | if (typeof console !== 'undefined') {
|
327 | console.warn(message);
|
328 | }
|
329 |
|
330 | try {
|
331 |
|
332 |
|
333 |
|
334 | throw new Error(message);
|
335 | } catch (x) {}
|
336 | };
|
337 |
|
338 | lowPriorityWarning = function (condition, format) {
|
339 | if (format === undefined) {
|
340 | throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
|
341 | }
|
342 |
|
343 | if (!condition) {
|
344 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
345 | args[_key2 - 2] = arguments[_key2];
|
346 | }
|
347 |
|
348 | printWarning.apply(undefined, [format].concat(args));
|
349 | }
|
350 | };
|
351 | }
|
352 | var lowPriorityWarning$1 = lowPriorityWarning;
|
353 |
|
354 | function typeOf(object) {
|
355 | if (typeof object === 'object' && object !== null) {
|
356 | var $$typeof = object.$$typeof;
|
357 |
|
358 | switch ($$typeof) {
|
359 | case REACT_ELEMENT_TYPE:
|
360 | var type = object.type;
|
361 |
|
362 | switch (type) {
|
363 | case REACT_ASYNC_MODE_TYPE:
|
364 | case REACT_CONCURRENT_MODE_TYPE:
|
365 | case REACT_FRAGMENT_TYPE:
|
366 | case REACT_PROFILER_TYPE:
|
367 | case REACT_STRICT_MODE_TYPE:
|
368 | case REACT_SUSPENSE_TYPE:
|
369 | return type;
|
370 |
|
371 | default:
|
372 | var $$typeofType = type && type.$$typeof;
|
373 |
|
374 | switch ($$typeofType) {
|
375 | case REACT_CONTEXT_TYPE:
|
376 | case REACT_FORWARD_REF_TYPE:
|
377 | case REACT_PROVIDER_TYPE:
|
378 | return $$typeofType;
|
379 |
|
380 | default:
|
381 | return $$typeof;
|
382 | }
|
383 |
|
384 | }
|
385 |
|
386 | case REACT_LAZY_TYPE:
|
387 | case REACT_MEMO_TYPE:
|
388 | case REACT_PORTAL_TYPE:
|
389 | return $$typeof;
|
390 | }
|
391 | }
|
392 |
|
393 | return undefined;
|
394 | }
|
395 |
|
396 |
|
397 | var hasWarnedAboutDeprecatedIsAsyncMode = false;
|
398 |
|
399 | function isAsyncMode(object) {
|
400 | {
|
401 | if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
402 | hasWarnedAboutDeprecatedIsAsyncMode = true;
|
403 | lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
|
404 | }
|
405 | }
|
406 | return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
407 | }
|
408 |
|
409 | function isConcurrentMode(object) {
|
410 | return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
411 | }
|
412 |
|
413 | exports.typeOf = typeOf;
|
414 | exports.AsyncMode = REACT_ASYNC_MODE_TYPE;
|
415 | exports.ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
416 | exports.ContextConsumer = REACT_CONTEXT_TYPE;
|
417 | exports.ContextProvider = REACT_PROVIDER_TYPE;
|
418 | exports.Element = REACT_ELEMENT_TYPE;
|
419 | exports.ForwardRef = REACT_FORWARD_REF_TYPE;
|
420 | exports.Fragment = REACT_FRAGMENT_TYPE;
|
421 | exports.Lazy = REACT_LAZY_TYPE;
|
422 | exports.Memo = REACT_MEMO_TYPE;
|
423 | exports.Portal = REACT_PORTAL_TYPE;
|
424 | exports.Profiler = REACT_PROFILER_TYPE;
|
425 | exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
426 | exports.Suspense = REACT_SUSPENSE_TYPE;
|
427 |
|
428 | exports.isValidElementType = function (type) {
|
429 | return typeof type === 'string' || typeof type === 'function' ||
|
430 | type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
|
431 | };
|
432 |
|
433 | exports.isAsyncMode = isAsyncMode;
|
434 | exports.isConcurrentMode = isConcurrentMode;
|
435 |
|
436 | exports.isContextConsumer = function (object) {
|
437 | return typeOf(object) === REACT_CONTEXT_TYPE;
|
438 | };
|
439 |
|
440 | exports.isContextProvider = function (object) {
|
441 | return typeOf(object) === REACT_PROVIDER_TYPE;
|
442 | };
|
443 |
|
444 | exports.isElement = function (object) {
|
445 | return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
446 | };
|
447 |
|
448 | exports.isForwardRef = function (object) {
|
449 | return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
450 | };
|
451 |
|
452 | exports.isFragment = function (object) {
|
453 | return typeOf(object) === REACT_FRAGMENT_TYPE;
|
454 | };
|
455 |
|
456 | exports.isLazy = function (object) {
|
457 | return typeOf(object) === REACT_LAZY_TYPE;
|
458 | };
|
459 |
|
460 | exports.isMemo = function (object) {
|
461 | return typeOf(object) === REACT_MEMO_TYPE;
|
462 | };
|
463 |
|
464 | exports.isPortal = function (object) {
|
465 | return typeOf(object) === REACT_PORTAL_TYPE;
|
466 | };
|
467 |
|
468 | exports.isProfiler = function (object) {
|
469 | return typeOf(object) === REACT_PROFILER_TYPE;
|
470 | };
|
471 |
|
472 | exports.isStrictMode = function (object) {
|
473 | return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
474 | };
|
475 |
|
476 | exports.isSuspense = function (object) {
|
477 | return typeOf(object) === REACT_SUSPENSE_TYPE;
|
478 | };
|
479 | })();
|
480 | });
|
481 | unwrapExports(reactIs_development);
|
482 | var reactIs_development_1 = reactIs_development.typeOf;
|
483 | var reactIs_development_2 = reactIs_development.AsyncMode;
|
484 | var reactIs_development_3 = reactIs_development.ConcurrentMode;
|
485 | var reactIs_development_4 = reactIs_development.ContextConsumer;
|
486 | var reactIs_development_5 = reactIs_development.ContextProvider;
|
487 | var reactIs_development_6 = reactIs_development.Element;
|
488 | var reactIs_development_7 = reactIs_development.ForwardRef;
|
489 | var reactIs_development_8 = reactIs_development.Fragment;
|
490 | var reactIs_development_9 = reactIs_development.Lazy;
|
491 | var reactIs_development_10 = reactIs_development.Memo;
|
492 | var reactIs_development_11 = reactIs_development.Portal;
|
493 | var reactIs_development_12 = reactIs_development.Profiler;
|
494 | var reactIs_development_13 = reactIs_development.StrictMode;
|
495 | var reactIs_development_14 = reactIs_development.Suspense;
|
496 | var reactIs_development_15 = reactIs_development.isValidElementType;
|
497 | var reactIs_development_16 = reactIs_development.isAsyncMode;
|
498 | var reactIs_development_17 = reactIs_development.isConcurrentMode;
|
499 | var reactIs_development_18 = reactIs_development.isContextConsumer;
|
500 | var reactIs_development_19 = reactIs_development.isContextProvider;
|
501 | var reactIs_development_20 = reactIs_development.isElement;
|
502 | var reactIs_development_21 = reactIs_development.isForwardRef;
|
503 | var reactIs_development_22 = reactIs_development.isFragment;
|
504 | var reactIs_development_23 = reactIs_development.isLazy;
|
505 | var reactIs_development_24 = reactIs_development.isMemo;
|
506 | var reactIs_development_25 = reactIs_development.isPortal;
|
507 | var reactIs_development_26 = reactIs_development.isProfiler;
|
508 | var reactIs_development_27 = reactIs_development.isStrictMode;
|
509 | var reactIs_development_28 = reactIs_development.isSuspense;
|
510 |
|
511 | var reactIs = createCommonjsModule(function (module) {
|
512 |
|
513 | module.exports = reactIs_development;
|
514 | });
|
515 |
|
516 | |
517 |
|
518 |
|
519 |
|
520 | var REACT_STATICS = {
|
521 | childContextTypes: true,
|
522 | contextType: true,
|
523 | contextTypes: true,
|
524 | defaultProps: true,
|
525 | displayName: true,
|
526 | getDefaultProps: true,
|
527 | getDerivedStateFromError: true,
|
528 | getDerivedStateFromProps: true,
|
529 | mixins: true,
|
530 | propTypes: true,
|
531 | type: true
|
532 | };
|
533 | var KNOWN_STATICS = {
|
534 | name: true,
|
535 | length: true,
|
536 | prototype: true,
|
537 | caller: true,
|
538 | callee: true,
|
539 | arguments: true,
|
540 | arity: true
|
541 | };
|
542 | var FORWARD_REF_STATICS = {
|
543 | '$$typeof': true,
|
544 | render: true,
|
545 | defaultProps: true,
|
546 | displayName: true,
|
547 | propTypes: true
|
548 | };
|
549 | var MEMO_STATICS = {
|
550 | '$$typeof': true,
|
551 | compare: true,
|
552 | defaultProps: true,
|
553 | displayName: true,
|
554 | propTypes: true,
|
555 | type: true
|
556 | };
|
557 | var TYPE_STATICS = {};
|
558 | TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
|
559 |
|
560 | function getStatics(component) {
|
561 | if (reactIs.isMemo(component)) {
|
562 | return MEMO_STATICS;
|
563 | }
|
564 |
|
565 | return TYPE_STATICS[component['$$typeof']] || REACT_STATICS;
|
566 | }
|
567 |
|
568 | var defineProperty = Object.defineProperty;
|
569 | var getOwnPropertyNames = Object.getOwnPropertyNames;
|
570 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
571 | var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
572 | var getPrototypeOf = Object.getPrototypeOf;
|
573 | var objectPrototype = Object.prototype;
|
574 |
|
575 | function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
576 | if (typeof sourceComponent !== 'string') {
|
577 |
|
578 | if (objectPrototype) {
|
579 | var inheritedComponent = getPrototypeOf(sourceComponent);
|
580 |
|
581 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
582 | hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
583 | }
|
584 | }
|
585 |
|
586 | var keys = getOwnPropertyNames(sourceComponent);
|
587 |
|
588 | if (getOwnPropertySymbols) {
|
589 | keys = keys.concat(getOwnPropertySymbols(sourceComponent));
|
590 | }
|
591 |
|
592 | var targetStatics = getStatics(targetComponent);
|
593 | var sourceStatics = getStatics(sourceComponent);
|
594 |
|
595 | for (var i = 0; i < keys.length; ++i) {
|
596 | var key = keys[i];
|
597 |
|
598 | if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
|
599 | var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
600 |
|
601 | try {
|
602 |
|
603 | defineProperty(targetComponent, key, descriptor);
|
604 | } catch (e) {}
|
605 | }
|
606 | }
|
607 |
|
608 | return targetComponent;
|
609 | }
|
610 |
|
611 | return targetComponent;
|
612 | }
|
613 |
|
614 | var hoistNonReactStatics_cjs = hoistNonReactStatics;
|
615 |
|
616 | var withFirestore = function (Component) {
|
617 | var C = function (_ref) {
|
618 | var wrappedComponentRef = _ref.wrappedComponentRef,
|
619 | remainingProps = _objectWithoutPropertiesLoose(_ref, ["wrappedComponentRef"]);
|
620 |
|
621 | return React__default.createElement(FirestoreContext.Consumer, null, function (value) {
|
622 | if (!value) {
|
623 | throw new Error('FirestoreProvider is missing');
|
624 | }
|
625 |
|
626 | var firestoreDatabase = value.firestoreDatabase;
|
627 | return React__default.createElement(Component, _extends({}, remainingProps, {
|
628 | firestore: firestoreDatabase,
|
629 | ref: wrappedComponentRef
|
630 | }));
|
631 | });
|
632 | };
|
633 |
|
634 | C.displayName = "withFirestore(" + (Component.displayName || Component.name) + ")";
|
635 | C.WrappedComponent = Component;
|
636 | C.propTypes = {
|
637 | wrappedComponentRef: PropTypes.func
|
638 | };
|
639 | return hoistNonReactStatics_cjs(C, Component);
|
640 | };
|
641 |
|
642 | |
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 | function deepEqual(a, b) {
|
649 | if (Array.isArray(a) && Array.isArray(b)) {
|
650 | if (a.length !== b.length) {
|
651 | return false;
|
652 | }
|
653 |
|
654 | for (var i = 0; i < a.length; i++) {
|
655 | if (!deepEqual(a[i], b[i])) {
|
656 | return false;
|
657 | }
|
658 | }
|
659 |
|
660 | return true;
|
661 | } else {
|
662 | return a === b;
|
663 | }
|
664 | }
|
665 |
|
666 | var FirestoreCollection =
|
667 |
|
668 | function (_Component) {
|
669 | _inheritsLoose(FirestoreCollection, _Component);
|
670 |
|
671 | function FirestoreCollection() {
|
672 | var _this;
|
673 |
|
674 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
675 | args[_key] = arguments[_key];
|
676 | }
|
677 |
|
678 | _this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
679 | _this.state = {
|
680 | isLoading: true,
|
681 | data: [],
|
682 | error: null,
|
683 | snapshot: null
|
684 | };
|
685 |
|
686 | _this.setupFirestoreListener = function () {
|
687 | var _this$props = _this.props,
|
688 | firestore = _this$props.firestore,
|
689 | path = _this$props.path,
|
690 | queryProps = _objectWithoutPropertiesLoose(_this$props, ["firestore", "path"]);
|
691 |
|
692 | var collectionRef = firestore.collection(path);
|
693 |
|
694 | var query = _this.buildQuery(collectionRef, queryProps);
|
695 |
|
696 | _this.unsubscribe = query.onSnapshot(_this.handleOnSnapshotSuccess, _this.handleOnSnapshotError);
|
697 | };
|
698 |
|
699 | _this.handleOnSnapshotSuccess = function (snapshot) {
|
700 | if (snapshot) {
|
701 | _this.setState({
|
702 | isLoading: false,
|
703 | data: snapshot.docs.map(function (doc) {
|
704 | return _extends({
|
705 | id: doc.id
|
706 | }, doc.data());
|
707 | }),
|
708 | error: null,
|
709 | snapshot: snapshot
|
710 | });
|
711 | }
|
712 | };
|
713 |
|
714 | _this.handleOnSnapshotError = function (error) {
|
715 | _this.setState({
|
716 | isLoading: false,
|
717 | data: [],
|
718 | error: error,
|
719 | snapshot: null
|
720 | });
|
721 | };
|
722 |
|
723 | _this.buildQuery = function (collectionRef, queryProps) {
|
724 | var sort = queryProps.sort,
|
725 | limit = queryProps.limit,
|
726 | filter = queryProps.filter;
|
727 | var query = collectionRef;
|
728 |
|
729 | if (sort) {
|
730 | sort.split(',').forEach(function (sortItem) {
|
731 | var _sortItem$split = sortItem.split(':'),
|
732 | field = _sortItem$split[0],
|
733 | order = _sortItem$split[1];
|
734 |
|
735 | query = query.orderBy(field, order);
|
736 | });
|
737 | }
|
738 |
|
739 | if (limit) {
|
740 | query = query.limit(limit);
|
741 | }
|
742 |
|
743 | if (filter) {
|
744 |
|
745 | if (Array.isArray(filter[0])) {
|
746 | filter.forEach(function (clause) {
|
747 | var _query;
|
748 |
|
749 | query = (_query = query).where.apply(_query, clause);
|
750 | });
|
751 | } else {
|
752 | var _query2;
|
753 |
|
754 |
|
755 | query = (_query2 = query).where.apply(_query2, filter);
|
756 | }
|
757 | }
|
758 |
|
759 | return query;
|
760 | };
|
761 |
|
762 | return _this;
|
763 | }
|
764 |
|
765 | var _proto = FirestoreCollection.prototype;
|
766 |
|
767 | _proto.componentDidMount = function componentDidMount() {
|
768 | this.setupFirestoreListener();
|
769 | };
|
770 |
|
771 | _proto.componentWillUnmount = function componentWillUnmount() {
|
772 | this.handleUnsubscribe();
|
773 | };
|
774 |
|
775 | _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
776 | var _this2 = this;
|
777 |
|
778 | if (nextProps.path !== this.props.path || nextProps.sort !== this.props.sort || nextProps.limit !== this.props.limit || !deepEqual(nextProps.filter, this.props.filter)) {
|
779 | this.handleUnsubscribe();
|
780 | this.setState({
|
781 | isLoading: true
|
782 | }, function () {
|
783 | return _this2.setupFirestoreListener();
|
784 | });
|
785 | }
|
786 | };
|
787 |
|
788 | _proto.handleUnsubscribe = function handleUnsubscribe() {
|
789 | if (this.unsubscribe) {
|
790 | this.unsubscribe();
|
791 | }
|
792 | };
|
793 |
|
794 | _proto.render = function () {
|
795 | var _this$props2 = this.props,
|
796 | children = _this$props2.children,
|
797 | render = _this$props2.render;
|
798 | if (render) return render(this.state);
|
799 | if (typeof children === 'function') return children(this.state);
|
800 | return null;
|
801 | };
|
802 |
|
803 | return FirestoreCollection;
|
804 | }(React.Component);
|
805 |
|
806 | FirestoreCollection.propTypes = {
|
807 | path: PropTypes.string.isRequired,
|
808 | sort: PropTypes.string,
|
809 | limit: PropTypes.number,
|
810 | filter: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object])), PropTypes.arrayOf(PropTypes.array)]),
|
811 | children: PropTypes.func,
|
812 | render: PropTypes.func,
|
813 | firestore: PropTypes.object.isRequired
|
814 | };
|
815 | var FirestoreCollection$1 = withFirestore(FirestoreCollection);
|
816 |
|
817 | var FirestoreDocument =
|
818 |
|
819 | function (_Component) {
|
820 | _inheritsLoose(FirestoreDocument, _Component);
|
821 |
|
822 | function FirestoreDocument() {
|
823 | var _this;
|
824 |
|
825 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
826 | args[_key] = arguments[_key];
|
827 | }
|
828 |
|
829 | _this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
830 | _this.state = {
|
831 | isLoading: true,
|
832 | data: null,
|
833 | error: null,
|
834 | snapshot: null
|
835 | };
|
836 |
|
837 | _this.setupFirestoreListener = function () {
|
838 | var _this$props = _this.props,
|
839 | firestore = _this$props.firestore,
|
840 | path = _this$props.path;
|
841 | var documentRef = firestore.doc(path);
|
842 | _this.unsubscribe = documentRef.onSnapshot(_this.handleOnSnapshotSuccess, _this.handleOnSnapshotError);
|
843 | };
|
844 |
|
845 | _this.handleOnSnapshotError = function (error) {
|
846 | _this.setState({
|
847 | isLoading: false,
|
848 | error: error,
|
849 | data: null,
|
850 | snapshot: null
|
851 | });
|
852 | };
|
853 |
|
854 | _this.handleOnSnapshotSuccess = function (snapshot) {
|
855 | if (snapshot) {
|
856 | var newState = {
|
857 | isLoading: false,
|
858 | error: null,
|
859 | snapshot: snapshot
|
860 | };
|
861 |
|
862 | try {
|
863 | var documentData = snapshot.data();
|
864 | newState.data = _extends({
|
865 | id: snapshot.id
|
866 | }, documentData);
|
867 | } catch (error) {
|
868 | newState.error = error;
|
869 | }
|
870 |
|
871 | _this.setState(newState);
|
872 | }
|
873 | };
|
874 |
|
875 | return _this;
|
876 | }
|
877 |
|
878 | var _proto = FirestoreDocument.prototype;
|
879 |
|
880 | _proto.componentDidMount = function componentDidMount() {
|
881 | this.setupFirestoreListener();
|
882 | };
|
883 |
|
884 | _proto.componentWillUnmount = function componentWillUnmount() {
|
885 | this.handleUnsubscribe();
|
886 | };
|
887 |
|
888 | _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
889 | var _this2 = this;
|
890 |
|
891 | if (nextProps.path !== this.props.path) {
|
892 | this.handleUnsubscribe();
|
893 | this.setState({
|
894 | isLoading: true
|
895 | }, function () {
|
896 | return _this2.setupFirestoreListener();
|
897 | });
|
898 | }
|
899 | };
|
900 |
|
901 | _proto.handleUnsubscribe = function handleUnsubscribe() {
|
902 | if (this.unsubscribe) {
|
903 | this.unsubscribe();
|
904 | }
|
905 | };
|
906 |
|
907 | _proto.render = function () {
|
908 | var _this$props2 = this.props,
|
909 | children = _this$props2.children,
|
910 | render = _this$props2.render;
|
911 | if (render) return render(this.state);
|
912 | if (typeof children === 'function') return children(this.state);
|
913 | return null;
|
914 | };
|
915 |
|
916 | return FirestoreDocument;
|
917 | }(React.Component);
|
918 |
|
919 | FirestoreDocument.propTypes = {
|
920 | path: PropTypes.string.isRequired,
|
921 | children: PropTypes.func,
|
922 | render: PropTypes.func,
|
923 | firestore: PropTypes.object.isRequired
|
924 | };
|
925 | var FirestoreDocument$1 = withFirestore(FirestoreDocument);
|
926 |
|
927 | exports.Firestore = Firestore;
|
928 | exports.FirestoreProvider = FirestoreProvider;
|
929 | exports.FirestoreCollection = FirestoreCollection$1;
|
930 | exports.FirestoreDocument = FirestoreDocument$1;
|
931 | exports.withFirestore = withFirestore;
|
932 |
|
933 | Object.defineProperty(exports, '__esModule', { value: true });
|
934 |
|
935 | }));
|
936 |
|