From ae3dfc9800bdd2f4236ed6ea2d11047d6f48d5a9 Mon Sep 17 00:00:00 2001 From: DudeBro249 Date: Wed, 7 Apr 2021 23:06:13 +0530 Subject: [PATCH] fixed api and hosted to firebase --- README.md | 60 ++++---- react-providerx/src/hooks/useProvider.ts | 66 +++++---- .../src/models/providerReference.ts | 24 ++-- .../src/observableProvider/autoDispose.ts | 113 +++++++-------- .../src/observableProvider/base.ts | 85 ++++++----- .../src/observableProvider/index.ts | 77 +++++----- react-providerx/src/refresh.ts | 4 +- .../src/pages/HomePage/homePage.tsx | 133 ++++++++---------- .../src/pages/LoginPage/loginPage.tsx | 16 +-- .../src/shared/combine.ts | 38 +++-- .../src/shared/error.ts | 31 ++-- .../src/shared/userData.ts | 45 +++--- website/.firebase/hosting.YnVpbGQ.cache | 36 +++++ website/.firebaserc | 5 + website/firebase.json | 19 +++ 15 files changed, 420 insertions(+), 332 deletions(-) create mode 100644 website/.firebase/hosting.YnVpbGQ.cache create mode 100644 website/.firebaserc create mode 100644 website/firebase.json diff --git a/README.md b/README.md index 84bf4d1..2b018a4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ ## React-ProviderX + A React state management library built on top of RxJS and Observables ## Usage: + The library will cache data within your ObservableProvider, so you can grab values from a provider with the `useProvider` hook - without re-fetching data. + ```tsx import React from 'react' import { useProvider, ObservableProvider, refresh } from 'react-providerx' @@ -11,41 +14,40 @@ import { from } from 'rxjs' import { tap } from 'rxjs/operators' export const userResponseProvider$ = ObservableProvider.autoDispose((ref) => { - const fetchErrorApi = async () => { - const response = await fetch('https://jsonplaceholder.typicode.com/users/1') - const json = await response.json() - return json - } - - return from(fetchErrorApi()).pipe( - catchError((error: Error) => { - console.log('there was an error in fetching the api') - ref.maintainState = false - return throwError(error) - }), - ) -}) + const fetchErrorApi = async () => { + const response = await fetch('https://jsonplaceholder.typicode.com/users/1') + const json = await response.json() + return json + } + return from(fetchErrorApi()).pipe( + catchError((error: any) => { + ref.maintainState = false + return ref.error(error) + }) + ) +}) const Component: React.FC = () => { - const { isLoading, data, error } = useProvider(userResponseProvider$) - if(isLoading) { - return ( -
- Waiting For Data... -
- ) - } - return ( -
- {data} - -
- ) + const { isLoading, data, error } = useProvider(userResponseProvider$) + if (isLoading) { + return
Waiting For Data...
+ } + return ( +
+ {data} + +
+ ) } ``` + ## Supporters -[![Stargazers repo roster for @DudeBro249/providerx](https://reporoster.com/stars/DudeBro249/providerx)](https://github.com/DudeBro249/providerx/stargazers) + +[![Stargazers repo roster for @DudeBro249/providerx](https://reporoster.com/stars/DudeBro249/providerx)](https://github.com/providerx/providerx-js/stargazers) ## License + [Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/) diff --git a/react-providerx/src/hooks/useProvider.ts b/react-providerx/src/hooks/useProvider.ts index 1d5a550..ff91ad8 100644 --- a/react-providerx/src/hooks/useProvider.ts +++ b/react-providerx/src/hooks/useProvider.ts @@ -3,36 +3,50 @@ import { AutoDisposeObservableProvider } from '../observableProvider/autoDispose import { BaseObservableProvider } from '../observableProvider/base' type UseProviderValues = { - isLoading: boolean - data: T - error: any + isLoading: boolean + data: T + error: any } export const useProvider = (provider: BaseObservableProvider) => { - const [currentValue, setCurrentValue] = useState(null) - const [currentError, setCurrentError] = useState(null) + const [currentValue, setCurrentValue] = useState(undefined) + const [currentError, setCurrentError] = useState(undefined) + const [isLoading, setLoading] = useState(false) - useEffect(() => { - const handleError = (error: any) => { - setCurrentError(error) - } + useEffect(() => { + const handleError = (error: any) => { + console.log('useProvider hook: The value of error is: ') + console.log(error) + setCurrentError(error) + } - const handleValue = (value: T) => { - setCurrentValue(value) - } - const [valueSubscription, errorSubscription] = provider.subscribe(handleValue, handleError) - return () => { - valueSubscription.unsubscribe() - errorSubscription.unsubscribe() - if(provider instanceof AutoDisposeObservableProvider) { - provider.registerUnsubscribe() - } - } - }, [provider]) + const handleLoading = (loading: boolean) => { + console.log('useProvider hook: The value of loading is: ') + console.log(loading) + setLoading(loading) + } - return { - isLoading: currentValue === undefined && currentError === undefined, - data: currentValue, - error: currentError, - } as UseProviderValues + const handleValue = (value: T | undefined) => { + console.log('useProvider hook: Got a value down the pipe: ') + console.log(value) + setCurrentValue(value) + } + const [valueSubscription, errorSubscription] = provider.subscribe( + handleValue, + handleError + ) + return () => { + valueSubscription.unsubscribe() + errorSubscription.unsubscribe() + if (provider instanceof AutoDisposeObservableProvider) { + provider.registerUnsubscribe() + } + } + }, []) + + return { + isLoading: currentValue === undefined && currentError === undefined, + data: currentValue, + error: currentError, + } as UseProviderValues } diff --git a/react-providerx/src/models/providerReference.ts b/react-providerx/src/models/providerReference.ts index 3f408bb..91d9d69 100644 --- a/react-providerx/src/models/providerReference.ts +++ b/react-providerx/src/models/providerReference.ts @@ -1,18 +1,18 @@ -import { throwError } from "rxjs" +import { throwError } from 'rxjs' export class ProviderReference { - executionError?: any - - error(error: any) { - this.executionError = error - return throwError(error) - } + executionError?: any + + error(error: any) { + this.executionError = error + return throwError(error) + } } export class AutoDisposeProviderReference extends ProviderReference { - maintainState: boolean - constructor(maintainState?: boolean) { - super() - this.maintainState = maintainState ?? true - } + maintainState: boolean + constructor(maintainState?: boolean) { + super() + this.maintainState = maintainState ?? true + } } diff --git a/react-providerx/src/observableProvider/autoDispose.ts b/react-providerx/src/observableProvider/autoDispose.ts index 9ad625a..f5f0bbe 100644 --- a/react-providerx/src/observableProvider/autoDispose.ts +++ b/react-providerx/src/observableProvider/autoDispose.ts @@ -1,64 +1,67 @@ -import { BehaviorSubject, from, Observable, Subscription } from "rxjs"; -import { AutoDisposeProviderReference } from "../models/providerReference"; -import { BaseObservableProvider } from "./base"; +import { BehaviorSubject, from, Observable, Subscription } from 'rxjs' +import { AutoDisposeProviderReference } from '../models/providerReference' +import { BaseObservableProvider } from './base' -export class AutoDisposeObservableProvider extends BaseObservableProvider { - _valueSubject$: BehaviorSubject | BehaviorSubject - _errorSubject$: BehaviorSubject | BehaviorSubject - observableCreator - ref: AutoDisposeProviderReference - _observable$: Observable - _internalSubscription?: Subscription +export class AutoDisposeObservableProvider< + T +> extends BaseObservableProvider { + observableCreator + ref: AutoDisposeProviderReference + _observable$: Observable + _internalSubscription?: Subscription - constructor(observableCreator: (ref: AutoDisposeProviderReference) => Observable) { - super(observableCreator) - this.observableCreator = observableCreator - this.ref = new AutoDisposeProviderReference(false) - this._observable$ = new Observable() - this._valueSubject$ = new BehaviorSubject(undefined) - this._errorSubject$ = new BehaviorSubject(undefined) + constructor( + observableCreator: (ref: AutoDisposeProviderReference) => Observable + ) { + super(observableCreator) + this.observableCreator = observableCreator + this.ref = new AutoDisposeProviderReference(false) + this._observable$ = new Observable() + } + + static fromPromise( + promise: () => Promise + ): AutoDisposeObservableProvider { + return new AutoDisposeObservableProvider(() => from(promise()) as any) + } + + _reset() { + if (this._internalSubscription !== undefined) { + this._internalSubscription.unsubscribe() } - - static fromPromise(promise: () => Promise): AutoDisposeObservableProvider { - return new AutoDisposeObservableProvider(() => (from(promise()) as any)) + this._valueSubject$ = new BehaviorSubject(undefined) + this._errorSubject$ = new BehaviorSubject(undefined) + } + + _compute() { + this.ref = new AutoDisposeProviderReference(false) + this._reset() + this._observable$ = this.observableCreator(this.ref) + if (this._observable$ === null) { + throw 'observableCreator cannot return null. It must return an instance of Observable' } - - _compute() { - this.ref = new AutoDisposeProviderReference(false) - this._observable$ = this.observableCreator(this.ref) - if(this._observable$ === null) { - throw 'observableCreator cannot return null. It must return an instance of Observable' + this._internalSubscription = this._observable$.subscribe( + (val: T) => { + if (this.ref.executionError !== undefined) { + this._advanceError(this.ref.executionError) + return } - this._internalSubscription = this._observable$.subscribe( - (val: T) => { - if(this.ref.executionError !== undefined) { - this._advanceError(this.ref.executionError) - return - } - this._advanceValue(val) - }, - (error: any) => { - this._advanceError(error) - } - ) - } + this._advanceValue(val) + }, + (error: any) => { + this._advanceError(error) + } + ) + } - _reset() { - if(this._internalSubscription !== undefined) { - this._internalSubscription.unsubscribe() - } - this._valueSubject$ = new BehaviorSubject(undefined) - this._errorSubject$ = new BehaviorSubject(undefined) + registerUnsubscribe() { + if (this.ref.maintainState === true) { + return } - - registerUnsubscribe() { - if(this.ref.maintainState === true) { - return - } - const valueObservers = this._valueSubject$.observers - const errorObservers = this._errorSubject$.observers - if(valueObservers.length < 1 && errorObservers.length < 1) { - this._reset() - } + const valueObservers = this._valueSubject$.observers + const errorObservers = this._errorSubject$.observers + if (valueObservers.length < 1 && errorObservers.length < 1) { + this._reset() } + } } diff --git a/react-providerx/src/observableProvider/base.ts b/react-providerx/src/observableProvider/base.ts index e8a9c41..b9fbccb 100644 --- a/react-providerx/src/observableProvider/base.ts +++ b/react-providerx/src/observableProvider/base.ts @@ -1,47 +1,60 @@ import { BehaviorSubject, Observable, Subscription } from 'rxjs' import { ProviderReference } from '../models/providerReference' +import { filter } from 'rxjs/operators' export abstract class BaseObservableProvider { - _valueSubject$: BehaviorSubject | BehaviorSubject - _errorSubject$: BehaviorSubject | BehaviorSubject - observableCreator - ref: ProviderReference - _observable$: Observable - _internalSubscription?: Subscription - - constructor(observableCreator: any) { - this.observableCreator = observableCreator - this._observable$ = new Observable() - this.ref = new ProviderReference() - this._valueSubject$ = new BehaviorSubject(undefined) - this._errorSubject$ = new BehaviorSubject(undefined) - } - - public get observable() { - if(this._internalSubscription === undefined) { - this._compute() - } - return this._valueSubject$.asObservable() as Observable - } + _valueSubject$: BehaviorSubject + _errorSubject$: BehaviorSubject + observableCreator + ref: ProviderReference + _observable$: Observable + _internalSubscription?: Subscription - public get errorObservable() { - return this._errorSubject$.asObservable() as Observable - } + constructor(observableCreator: (ref: any) => Observable) { + this.observableCreator = observableCreator + this._observable$ = new Observable() + this.ref = new ProviderReference() + this._valueSubject$ = new BehaviorSubject(undefined) + this._errorSubject$ = new BehaviorSubject(undefined) + } - _advanceValue(value: T) { - this._valueSubject$.next(value as any) - this._errorSubject$.next(null as any) + public get observable(): Observable { + if (this._internalSubscription === undefined) { + this._compute() } + return this._valueSubject$.pipe( + filter((value) => value !== undefined) + ) as any + } - _advanceError(error: any) { - this._errorSubject$.next(error) - this._valueSubject$.next(null as any) - } + private get errorObservable(): Observable { + return this._errorSubject$.pipe( + filter((value) => value !== undefined) + ) as any + } - subscribe(dataCallback: (value: T) => void, errorCallback: (error: any) => void): Subscription[] { - this._compute() - return [this.observable.subscribe(dataCallback), this.errorObservable.subscribe(errorCallback)] + _advanceValue(value: T) { + this._valueSubject$.next(value) + this._errorSubject$.next(undefined) + } + + _advanceError(error: any) { + this._errorSubject$.next(error) + this._valueSubject$.next(undefined) + } + + subscribe( + dataCallback: (value: T) => void, + errorCallback: (error: any) => void + ): Subscription[] { + if (this._internalSubscription === undefined) { + this._compute() } - - abstract _compute(): void + return [ + this.observable.subscribe(dataCallback), + this.errorObservable.subscribe(errorCallback), + ] + } + + abstract _compute(): void } diff --git a/react-providerx/src/observableProvider/index.ts b/react-providerx/src/observableProvider/index.ts index dae0738..b7d34ff 100644 --- a/react-providerx/src/observableProvider/index.ts +++ b/react-providerx/src/observableProvider/index.ts @@ -1,47 +1,48 @@ -import { BehaviorSubject, Observable, Subscription } from 'rxjs' -import { ProviderReference, AutoDisposeProviderReference } from '../models/providerReference' +import { Observable, Subscription } from 'rxjs' +import { + ProviderReference, + AutoDisposeProviderReference, +} from '../models/providerReference' import { AutoDisposeObservableProvider } from './autoDispose' import { BaseObservableProvider } from './base' - export class ObservableProvider extends BaseObservableProvider { - _valueSubject$: BehaviorSubject | BehaviorSubject - _errorSubject$: BehaviorSubject | BehaviorSubject - observableCreator: (ref: ProviderReference) => Observable - _observable$: Observable - ref: ProviderReference - _internalSubscription?: Subscription + observableCreator: (ref: ProviderReference) => Observable + _observable$: Observable + ref: ProviderReference + _internalSubscription?: Subscription - constructor(observableCreator: (ref: ProviderReference) => Observable) { - super(observableCreator) - this.observableCreator = observableCreator - this._observable$ = new Observable() - this.ref = new ProviderReference() - this._valueSubject$ = new BehaviorSubject(undefined) - this._errorSubject$ = new BehaviorSubject(undefined) - } + constructor(observableCreator: (ref: ProviderReference) => Observable) { + super(observableCreator) + this.observableCreator = observableCreator + this._observable$ = new Observable() + this.ref = new ProviderReference() + } + + static autoDispose( + observableCreator: (ref: AutoDisposeProviderReference) => Observable + ) { + return new AutoDisposeObservableProvider(observableCreator) + } - static autoDispose(observableCreator: (ref: AutoDisposeProviderReference) => Observable) { - return new AutoDisposeObservableProvider(observableCreator); + _compute() { + this.ref = new ProviderReference() + this._observable$ = this.observableCreator(this.ref) + if (this._observable$ === null) { + throw 'observableCreator cannot return null. It must return an instance of Observable' } - - _compute() { - this.ref = new ProviderReference() - this._observable$ = this.observableCreator(this.ref) - if(this._observable$ === null) { - throw 'observableCreator cannot return null. It must return an instance of Observable' + + this._internalSubscription = this._observable$.subscribe( + (value) => { + if (this.ref.executionError !== undefined) { + this._advanceError(this.ref.executionError) + return } - this._internalSubscription = this._observable$.subscribe( - (val: T) => { - if(this.ref.executionError !== undefined) { - this._advanceError(this.ref.executionError) - return - } - this._advanceValue(val) - }, - (error: any) => { - this._advanceError(error) - } - ) - } + this._advanceValue(value) + }, + (error) => { + this._advanceError(error) + } + ) + } } diff --git a/react-providerx/src/refresh.ts b/react-providerx/src/refresh.ts index b92693d..35d14aa 100644 --- a/react-providerx/src/refresh.ts +++ b/react-providerx/src/refresh.ts @@ -1,5 +1,5 @@ -import { BaseObservableProvider } from "./observableProvider/base" +import { BaseObservableProvider } from './observableProvider/base' export const refresh = (provider: BaseObservableProvider) => { - return provider._compute() + return provider._compute() } diff --git a/tests/react-providerx-test-app/src/pages/HomePage/homePage.tsx b/tests/react-providerx-test-app/src/pages/HomePage/homePage.tsx index f658e44..b6edbdf 100644 --- a/tests/react-providerx-test-app/src/pages/HomePage/homePage.tsx +++ b/tests/react-providerx-test-app/src/pages/HomePage/homePage.tsx @@ -1,93 +1,78 @@ -import { refresh, useProvider } from "react-providerx"; -import { signOut } from "../../services/auth"; -import { documentFamilyProvider$ } from "../../shared/family"; -import { userDataProvider$ } from "../../shared/userData"; -import { errorProvider$ } from "../../shared/error"; -import { userDataCombineProvider } from "../../shared/combine"; +import { refresh, useProvider } from 'react-providerx' +import { signOut } from '../../services/auth' +import { documentFamilyProvider$ } from '../../shared/family' +import { userDataProvider$ } from '../../shared/userData' +import { errorProvider$ } from '../../shared/error' +import { userDataCombineProvider, userIdProvider } from '../../shared/combine' const SubComponent: React.FC = () => { const { isLoading, data, error } = useProvider(errorProvider$) - if(isLoading) { - return
+ if (isLoading) { + return ( +
Loading data... - {data === null ? 'null': 'no error, got data'} -
- } - if(error !== null) { - return
- Something went wrong... + {data === null ? 'null' : 'no error, got data'}
- } - return
- { JSON.stringify(data) } -
+ ) + } + if (error !== null) { + return
Something went wrong...
+ } + return
{JSON.stringify(data)}
} const FamilyTester: React.FC = () => { - const { isLoading, data, error } = useProvider(documentFamilyProvider$.pass('ICvuiU7397D9BjgrrYcq')) - if(isLoading) { - return
- Loading data... -
- } - if(error !== null) { - return
- Something went wrong... -
- } - return ( -
- { JSON.stringify(data) } -
- ) + const { isLoading, data, error } = useProvider( + documentFamilyProvider$.pass('ICvuiU7397D9BjgrrYcq') + ) + if (isLoading) { + return
Loading data...
+ } + if (error) { + return
Something went wrong...
+ } + return
{JSON.stringify(data)}
} const CombineTester: React.FC = () => { const { isLoading, data, error } = useProvider(userDataCombineProvider) - if(isLoading) return
Loading...
- if(error) return
Something went wrong...
+ if (isLoading) return
Loading...
+ if (error) return
Something went wrong...
return ( -
- {JSON.stringify(data)} - -
- ) +
+ {JSON.stringify(data)} + +
+ ) } export const HomePage: React.FC = () => { - const { isLoading, data: userData, error } = useProvider(userDataProvider$) - if(isLoading) { - return
- Loading... -
- } - if(error) { - return ( -
- Something went wrong... -
- ) - } - return ( -
- { JSON.stringify(userData) } -
- - -
- SubComponent: - - FamilyTester: - - CombineTester: - + const { isLoading, data: userData, error } = useProvider(userDataProvider$) + if (isLoading) { + console.log('loading inside component...') + console.log(userData) + return
Loading...
+ } + if (error) { + console.log(error) + return
Something went wrong...
+ } + return ( +
+ {JSON.stringify(userData)} +
+ +
- ); + SubComponent: + + FamilyTester: + + CombineTester: + +
+ ) } diff --git a/tests/react-providerx-test-app/src/pages/LoginPage/loginPage.tsx b/tests/react-providerx-test-app/src/pages/LoginPage/loginPage.tsx index 9a1115b..aa55adf 100644 --- a/tests/react-providerx-test-app/src/pages/LoginPage/loginPage.tsx +++ b/tests/react-providerx-test-app/src/pages/LoginPage/loginPage.tsx @@ -1,12 +1,10 @@ -import { signInWithGoogle } from "../../services/auth"; +import { signInWithGoogle } from '../../services/auth' export const LoginPage: React.FC = () => { - return ( -
- Not Logged In - -
- ); + return ( +
+ Not Logged In + +
+ ) } diff --git a/tests/react-providerx-test-app/src/shared/combine.ts b/tests/react-providerx-test-app/src/shared/combine.ts index 94fc42b..d498dcb 100644 --- a/tests/react-providerx-test-app/src/shared/combine.ts +++ b/tests/react-providerx-test-app/src/shared/combine.ts @@ -1,19 +1,29 @@ -import { ObservableProvider } from 'react-providerx/lib' +import { ObservableProvider } from 'react-providerx' import { from, of } from 'rxjs' -import { switchMap } from 'rxjs/operators' +import { catchError, switchMap } from 'rxjs/operators' -const userIdProvider = new ObservableProvider(() => of('10')) +export const userIdProvider = new ObservableProvider(() => { + const randomNumber = Math.floor(Math.random() * 10) + 1 + return of(randomNumber) +}) -export const userDataCombineProvider = new ObservableProvider(() => { - const fetchUserById = async (id: string) => { - // const response = await fetch('http://errortrial.com/') - const response = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`) - const json = await response.json() - return json - } - return userIdProvider.observable.pipe( - switchMap(id => { - return from(fetchUserById(id)) - }) +export const userDataCombineProvider = new ObservableProvider((ref) => { + const fetchUserById = async (id: number) => { + // const response = await fetch('http://errortrial.com/') + const response = await fetch( + `https://jsonplaceholder.typicode.com/users/${id}` ) + const json = await response.json() + return json + } + return userIdProvider.observable.pipe( + catchError((error) => { + console.log('Got error in userDataCombineProvider: ') + console.log(error) + return ref.error(error) + }), + switchMap((id) => { + return from(fetchUserById(id as number)) + }) + ) }) diff --git a/tests/react-providerx-test-app/src/shared/error.ts b/tests/react-providerx-test-app/src/shared/error.ts index a5a8195..8016c7a 100644 --- a/tests/react-providerx-test-app/src/shared/error.ts +++ b/tests/react-providerx-test-app/src/shared/error.ts @@ -1,19 +1,18 @@ -import { ObservableProvider } from "react-providerx"; -import { from } from "rxjs"; -import { catchError } from "rxjs/operators"; +import { ObservableProvider } from 'react-providerx' +import { from } from 'rxjs' +import { catchError } from 'rxjs/operators' export const errorProvider$ = ObservableProvider.autoDispose((ref) => { - const fetchErrorApi = async () => { - // const response = await fetch('http://errortrial.com/') - const response = await fetch('https://jsonplaceholder.typicode.com/users/1') - const json = await response.json() - return json - } - return from(fetchErrorApi()).pipe( - catchError((error: Error) => { - console.log('there was an error in fetching the api') - ref.maintainState = false - return ref.error(error) - }), - ) + const fetchErrorApi = async () => { + // const response = await fetch('http://errortrial.com/') + const response = await fetch('https://jsonplaceholder.typicode.com/users/1') + const json = await response.json() + return json + } + return from(fetchErrorApi()).pipe( + catchError((error: Error) => { + ref.maintainState = false + return ref.error(error) + }) + ) }) diff --git a/tests/react-providerx-test-app/src/shared/userData.ts b/tests/react-providerx-test-app/src/shared/userData.ts index 3bc33a5..838da3e 100644 --- a/tests/react-providerx-test-app/src/shared/userData.ts +++ b/tests/react-providerx-test-app/src/shared/userData.ts @@ -1,24 +1,27 @@ -import { ObservableProvider } from "react-providerx"; -import { of } from "rxjs"; -import { doc } from 'rxfire/firestore'; -import { map, switchMap } from "rxjs/operators"; -import { db } from "../utils/firebase"; -import { authStateProvider$ } from "./authState"; +import { ObservableProvider } from 'react-providerx' +import { of } from 'rxjs' +import { doc } from 'rxfire/firestore' +import { catchError, map, switchMap } from 'rxjs/operators' +import { db } from '../utils/firebase' +import { authStateProvider$ } from './authState' -export const userDataProvider$ = new ObservableProvider(() => { - const userDataObservable = authStateProvider$.observable.pipe( - switchMap(result => { - if(result === null) { - // Not logged in - return of(null) - } - else { - return doc(db.collection('users').doc(result.uid)).pipe( - map(ds => ({...ds.data(), id: ds.id})) - ) - } - }) - ) +export const userDataProvider$ = new ObservableProvider((ref) => { + const userDataObservable = authStateProvider$.observable.pipe( + catchError((error: any) => { + console.log('Got an error: ') + console.log(error) + return ref.error(error) + }), + switchMap((result) => { + if (result === null) { + return of(null) + } else { + return doc(db.collection('users').doc(result!.uid)).pipe( + map((ds) => ({ ...ds.data(), id: ds.id })) + ) + } + }) + ) - return userDataObservable + return userDataObservable }) diff --git a/website/.firebase/hosting.YnVpbGQ.cache b/website/.firebase/hosting.YnVpbGQ.cache new file mode 100644 index 0000000..bc3c10e --- /dev/null +++ b/website/.firebase/hosting.YnVpbGQ.cache @@ -0,0 +1,36 @@ +sitemap.xml,1617509934033,efcdb1bab4909cf59a58378e9bc5a7d5ab827253bfd7de9315dc39d548ea556a +index.html,1617509933796,41c6d9467cf4696e1eff14841632d64d8b6e057de9bc71575f0524d8cccc9ce7 +404.html,1617509933796,184e16613ba9517f7f0ef45bce383aea2c477d83e2d850119c0f45dad0a65147 +assets/js/0f29724f.32b4517e.js,1617509932161,1e5df2b50a7ce261147aae2faf0767fe0664ef63f68ccd2defefe4fb4bf79855 +assets/js/15.591ba82d.js,1617509932205,27477980db8c206c50e8aa40500c3ecb49bb03078b9e8c38869599a01603aebb +assets/js/1df93b7f.c583568d.js,1617509932161,8f25daca3afacb54e761b98867b538e05986d3cfcaded85f2407b43683d9de90 +assets/js/17896441.fb2d0685.js,1617509932161,17e6eaa41a2c5271fc4b6d5dbaea5d2dfa613d46e25886bc27d17d1279190412 +assets/js/21b7532c.54ac08e2.js,1617509932161,116e94c64b6cc7161ee2ac6a8ba08f951b6132aa2b4db424395e66db8cab2625 +assets/js/14.582fe10a.js,1617509932205,31f61d26675a5b005367d21c6b6ee568036e115cd776a68af5102b839e7638f9 +assets/js/1f391b9e.6143f684.js,1617509932161,f010bdb592e6c38696bd41ffff132b964e83016b963e1ccb93c91753c73b9bf2 +assets/js/3021cf83.57e7ce63.js,1617509932161,c56475b71e5cfdccd7e8ae7e915339303dcfde48d00f6d48130f9f7073c817cd +assets/js/393be207.def2c90f.js,1617509932161,8f12dfb780ca3d2fe72bc8357fdd429cd43cdcdd010c0ff422aa5084a2fa6996 +assets/js/935f2afb.e8191384.js,1617509932161,21fee0ffc1e21fbfcce098d6154aa8e6adc3fd6235dc440a24d9d09a1bd986dc +assets/js/27928b92.7db3e0b1.js,1617509932161,fc13400811a03d43d9549cac94e037183a6926a514df0a997cccd5520d3ca6b2 +assets/js/common.fd994903.js.LICENSE.txt,1617509932205,4519dec729c029f606efb5718df65696406ac11971bb94d80d91689a55887462 +assets/js/74783314.e0957454.js,1617509932161,09ee7356f7e1753a000cb7ec5ddd7bac8c062148cfb409d6fc64d96a2cb63e5e +assets/js/main.fa93e3c7.js.LICENSE.txt,1617509932205,6e366ee89d862f785df35bca2ca340ae1c991582b2b5c55f7822f8a9d2b3df80 +assets/js/styles.69fe0005.js,1617509932161,6a6d66810d6a2db892953285b747aad147c80d1c38408c1552e54a448e19b9ad +assets/js/runtime~main.743c5e1e.js,1617509932161,7cb2922208d74d781aec44249a069abb4376eb7298ba83833d25b116400f9ffb +blog/atom.xml,1617509934033,819a57bf5e3f7cd8324c5056ab63bc3783d7ac5cfa560d4acb67a855b21af17e +blog/rss.xml,1617509934033,e8d16c830c7ec2b0245c4101aa5ac1f5fafb2eee0c9dab4ff4b05e71cbc542cd +docs/index.html,1617509933796,9c615d3cedabd821ce06e4e4a32b04336963a2aa82ab1e4d3c5ebec8fd6ef7b9 +docs/concepts/combining/index.html,1617509933827,2cdfb945050cd1ef66884053dac5b6cc2b747b2f4f3634a134b073df0781c20b +docs/concepts/providers/index.html,1617509933823,25b180693c25745a13524581087f4defa05231f429540e3db21a5aaecb0d57c9 +img/docusaurus.png,1617509933796,cebc2c529c8b0a065d9877d3d0fe03ff0414800bed40c9598378288f48b952cc +assets/js/common.fd994903.js,1617509932152,da096e5aacbf7e199bdcf53f6fd5b1dc56b85d3596ddda3d6f3c7816816398f2 +img/favicon.ico,1617509933800,9560969558cb93cd96174ac947e080bc917ea633b34496fbfb6590e696c0e60b +img/logo.svg,1617509933801,6ce2154d2f3589158da503f642ddc14868089d71c01fe4e4cbdb7c50cabb5686 +docs/concepts/reading/index.html,1617509933827,d40d20dd94796efa125173e9a5a29eaf2bcfdb2d1999b7de5b042e4314a5f554 +assets/css/styles.4b429d86.css,1617509932161,52170413cebfbcbe882f05d9ebb8f5d770a1d390d6fe36a2060cce26646ae9c1 +img/undraw_docusaurus_tree.svg,1617509933818,a5a8f697fa577c8bbbe0065e8d64993815eef7437b19156c0bf61bf1ef0c26f7 +markdown-page/index.html,1617509933796,85762c12e37f2ce00db7f2c813cf8f934b1b818fbaf97c9c80ccce0d70c5ab65 +img/undraw_docusaurus_mountain.svg,1617509933801,c36cb0b7efc58b8eff32543d9bbc5a0ad9463f828487483682acba03602334a1 +img/undraw_docusaurus_react.svg,1617509933818,bf03f86b6746204ed207e8307816f8a35002e45789bb3d8c7a761b2b17c68785 +docs/concepts/error-handling/index.html,1617509933827,f90a316d0d1296636e83ef0724509226e0fa49cc4cf986faa657396d7dedfc75 +assets/js/main.fa93e3c7.js,1617509932174,1e38ba052aae23449cda4ec3f86d5ea01337f25f634bf9b0aa9faa1f9141abd5 diff --git a/website/.firebaserc b/website/.firebaserc new file mode 100644 index 0000000..24ef3f5 --- /dev/null +++ b/website/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "providerx-state" + } +} diff --git a/website/firebase.json b/website/firebase.json new file mode 100644 index 0000000..10b7561 --- /dev/null +++ b/website/firebase.json @@ -0,0 +1,19 @@ +{ + "hosting": { + "public": "build", + "headers": [ + {"source": "/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}]} + ], + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ], + "rewrites": [ + { + "source": "**", + "destination": "/index.html" + } + ] + } +}