-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added testing and finished ObservableProvider
- Loading branch information
1 parent
6407bcc
commit c20a1d6
Showing
11 changed files
with
45,847 additions
and
10,115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
{ | ||
"name": "react-providerx", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"version": "0.0.1", | ||
"description": "A state management library built for React, using RxJS and Observables", | ||
"main": "lib/index.js", | ||
"types": "lib", | ||
"homepage": "https://github.com/DudeBro249/providerx", | ||
"scripts": { | ||
"build": "tsc -p ." | ||
"build": "npx tsc -p ." | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"author": "DudeBro249", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"rxjs": "^6.6.6", | ||
"rxjs-hooks": "^0.6.2" | ||
"rxjs": "^6.6.6" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { useObservable } from "rxjs-hooks" | ||
import { ObservableProvider } from "../providers/observableProvider" | ||
import { ObservableProvider } from '../providers/observableProvider' | ||
import { useState, useEffect } from 'react' | ||
|
||
type UseProviderValues<T> = { | ||
isLoading: boolean | ||
data: T | ||
} | ||
|
||
export const useProvider = <T>(provider: ObservableProvider<T>) => { | ||
try { | ||
const value = useObservable(() => provider.behaviorSubject$.asObservable()) | ||
return { | ||
isLoading: value === null, | ||
data: value, | ||
error: null | ||
const [currentValue, setCurrentValue] = useState<T | null>(null) | ||
|
||
useEffect(() => { | ||
const handleSubscriptionValue = (value: any) => { | ||
setCurrentValue(value) | ||
} | ||
} | ||
catch (error) { | ||
return { | ||
isLoading: false, | ||
data: null, | ||
error: error, | ||
const subscription = (provider.behaviorSubject$.asObservable() as any).subscribe(handleSubscriptionValue) | ||
return () => { | ||
subscription.unsubscribe() | ||
} | ||
} | ||
}, [provider.behaviorSubject$]) | ||
|
||
return { | ||
isLoading: currentValue === null || currentValue === undefined, | ||
data: currentValue, | ||
error: null | ||
} as UseProviderValues<T> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.