(props: DashContextProviderProps)
| 46 | }; |
| 47 | |
| 48 | export function DashContextProvider(props: DashContextProviderProps) { |
| 49 | const {children, componentPath} = props; |
| 50 | |
| 51 | const stringPath = useMemo<string>( |
| 52 | () => JSON.stringify(componentPath), |
| 53 | [componentPath] |
| 54 | ); |
| 55 | const store = useStore(); |
| 56 | |
| 57 | const isLoading = useCallback( |
| 58 | (options?: LoadingOptions) => { |
| 59 | const {extraPath, rawPath, filterFunc} = options || {}; |
| 60 | let loadingPath = [stringPath]; |
| 61 | if (extraPath) { |
| 62 | loadingPath = [ |
| 63 | JSON.stringify(concat(componentPath, extraPath)) |
| 64 | ]; |
| 65 | } else if (rawPath) { |
| 66 | loadingPath = [JSON.stringify(rawPath)]; |
| 67 | } |
| 68 | const loading = pathOr( |
| 69 | [], |
| 70 | loadingPath, |
| 71 | (store.getState() as any).loading |
| 72 | ); |
| 73 | return filterFunc |
| 74 | ? loading.filter(filterFunc).length > 0 |
| 75 | : loading.length > 0; |
| 76 | }, |
| 77 | [stringPath] |
| 78 | ); |
| 79 | |
| 80 | const useLoading = useCallback( |
| 81 | (options?: LoadingOptions) => { |
| 82 | const {filterFunc, extraPath, rawPath} = options || {}; |
| 83 | return useSelector((state: any) => { |
| 84 | let loadingPath = [stringPath]; |
| 85 | if (extraPath) { |
| 86 | loadingPath = [ |
| 87 | JSON.stringify(concat(componentPath, extraPath)) |
| 88 | ]; |
| 89 | } else if (rawPath) { |
| 90 | loadingPath = [JSON.stringify(rawPath)]; |
| 91 | } |
| 92 | const load = pathOr([], loadingPath, state.loading); |
| 93 | if (filterFunc) { |
| 94 | return load.filter(filterFunc).length > 0; |
| 95 | } |
| 96 | return load.length > 0; |
| 97 | }); |
| 98 | }, |
| 99 | [stringPath] |
| 100 | ); |
| 101 | |
| 102 | const ctxValue = useMemo(() => { |
| 103 | return { |
| 104 | componentPath, |
| 105 | isLoading, |
nothing calls this directly
no test coverage detected
searching dependent graphs…