@ispb/react-lazy 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -0
- package/dist/async.d.ts +44 -0
- package/dist/async.js +79 -0
- package/dist/async.js.map +1 -0
- package/dist/components.d.ts +9 -0
- package/dist/components.js +36 -0
- package/dist/components.js.map +1 -0
- package/dist/hoc.d.ts +18 -0
- package/dist/hoc.js +13 -0
- package/dist/hoc.js.map +1 -0
- package/dist/hooks.d.ts +18 -0
- package/dist/hooks.js +137 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +4 -0
- package/dist/internal.js +20 -0
- package/dist/internal.js.map +1 -0
- package/dist/observable.d.ts +22 -0
- package/dist/observable.js +56 -0
- package/dist/observable.js.map +1 -0
- package/dist/state.d.ts +39 -0
- package/{src/state.ts → dist/state.js} +9 -48
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +5 -3
- package/.yarnrc.yml +0 -8
- package/src/async.tsx +0 -124
- package/src/components.tsx +0 -46
- package/src/hoc.tsx +0 -37
- package/src/hooks.ts +0 -155
- package/src/index.tsx +0 -9
- package/src/internal.ts +0 -21
- package/src/observable.tsx +0 -83
- package/src/types.tsx +0 -75
- package/tsconfig.json +0 -27
package/src/observable.tsx
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ReactNode, useEffect, useState } from "react"
|
|
3
|
-
import { Observable, ObservedValueOf } from "rxjs"
|
|
4
|
-
import { Lazy } from "./components.js"
|
|
5
|
-
import { LazyHOCOptions, lazified } from "./hoc.js"
|
|
6
|
-
import { useLazyFlatten } from "./hooks.js"
|
|
7
|
-
import { useIsFirstMount } from "./internal.js"
|
|
8
|
-
import { LazyState } from "./state.js"
|
|
9
|
-
import { LazyEvent, LazyOverrides } from "./types.js"
|
|
10
|
-
|
|
11
|
-
export type ObservableLazyInput = Observable<any>// | Record<string, ObservableInput<any>>
|
|
12
|
-
export type ObservableLazyOutput<X extends ObservableLazyInput> = X extends Observable<any> ? ObservedValueOf<X> : { [K in keyof X]: ObservedValueOf<X[K]> }
|
|
13
|
-
|
|
14
|
-
export interface ObservableLazyOptions<D> {
|
|
15
|
-
|
|
16
|
-
readonly of: Observable<D>
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function useObservableLazyWrapped<D>(options: ObservableLazyOptions<LazyEvent<D>>) {
|
|
21
|
-
return useLazyFlatten(useObservableLazy(options))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function useObservableLazy<D>(options: ObservableLazyOptions<D>) {
|
|
25
|
-
const [event, setEvent] = useState<LazyEvent<D>>({ status: "loading" as const })
|
|
26
|
-
const isFirstMount = useIsFirstMount()
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!isFirstMount) {
|
|
29
|
-
setEvent({
|
|
30
|
-
status: "loading"
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
const sub = options.of.subscribe({
|
|
34
|
-
next: value => {
|
|
35
|
-
setEvent({
|
|
36
|
-
status: "fulfilled",
|
|
37
|
-
value
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
error: reason => {
|
|
41
|
-
setEvent({
|
|
42
|
-
status: "rejected",
|
|
43
|
-
reason
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
return () => {
|
|
48
|
-
sub.unsubscribe()
|
|
49
|
-
}
|
|
50
|
-
}, [
|
|
51
|
-
options.of
|
|
52
|
-
])
|
|
53
|
-
return event
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface ObservingOptions<D, P> extends ObservableLazyOptions<D>, LazyHOCOptions<LazyState<D>, P> {
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function observing<I extends {}, D extends {}, P extends {}>(factory: (props: I) => ObservingOptions<D, P>) {
|
|
60
|
-
return lazified((props: I) => {
|
|
61
|
-
const options = factory(props)
|
|
62
|
-
const event = useObservableLazy(options)
|
|
63
|
-
return {
|
|
64
|
-
event,
|
|
65
|
-
passthrough: options.passthrough,
|
|
66
|
-
overrides: options.overrides,
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface ObservingProps<D> extends ObservableLazyOptions<D> {
|
|
72
|
-
|
|
73
|
-
readonly children: (value: D, state: LazyState<D>) => ReactNode
|
|
74
|
-
readonly overrides?: LazyOverrides | undefined
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const Observing = <D,>(props: ObservingProps<D>) => {
|
|
79
|
-
const event = useObservableLazy(props)
|
|
80
|
-
return <Lazy event={event}
|
|
81
|
-
overrides={props.overrides}
|
|
82
|
-
children={props.children} />
|
|
83
|
-
}
|
package/src/types.tsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react"
|
|
2
|
-
|
|
3
|
-
export type LazyLoading = { readonly status: "loading" }
|
|
4
|
-
export type LazyFulfilled<D> = { readonly status: "fulfilled", readonly value: D }
|
|
5
|
-
export type LazyRejected = { readonly status: "rejected", readonly reason: unknown, readonly retry?: (() => void) | undefined }
|
|
6
|
-
export type LazySettled<D> = LazyFulfilled<D> | LazyRejected
|
|
7
|
-
export type LazyEvent<D> = LazySettled<D> | LazyLoading
|
|
8
|
-
|
|
9
|
-
export type OnLoading = (props: LoadingProps) => ReactNode
|
|
10
|
-
export type OnReloading = (props: ReloadingProps) => ReactNode
|
|
11
|
-
export type OnError = (props: ErrorProps) => ReactNode
|
|
12
|
-
|
|
13
|
-
type LazyMeta = string
|
|
14
|
-
|
|
15
|
-
export interface LoadingProps {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The message to display.
|
|
19
|
-
*/
|
|
20
|
-
readonly message?: LazyMeta | undefined
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ReloadingProps {
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Whether or not the data is currently reloading.
|
|
28
|
-
*/
|
|
29
|
-
readonly reloading: boolean
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The message to display.
|
|
33
|
-
*/
|
|
34
|
-
readonly message?: LazyMeta | undefined
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The children.
|
|
38
|
-
*/
|
|
39
|
-
readonly children: ReactNode
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ErrorProps {
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The error.
|
|
47
|
-
*/
|
|
48
|
-
readonly reason: unknown
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The message to display.
|
|
52
|
-
*/
|
|
53
|
-
readonly message?: LazyMeta | undefined
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface LazyOptions {
|
|
58
|
-
|
|
59
|
-
readonly onLoading?: OnLoading | undefined
|
|
60
|
-
readonly onReloading?: OnReloading | undefined
|
|
61
|
-
readonly onError?: OnError | undefined
|
|
62
|
-
|
|
63
|
-
readonly defaultMessage?: LazyMeta | undefined
|
|
64
|
-
readonly loadingMessage?: LazyMeta | undefined
|
|
65
|
-
readonly reloadingMessage?: LazyMeta | undefined
|
|
66
|
-
readonly errorMessage?: LazyMeta | undefined
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Overrides for lazy options.
|
|
72
|
-
*/
|
|
73
|
-
export type LazyOverrides = Partial<LazyOptions>
|
|
74
|
-
|
|
75
|
-
export type ExtractLazy<T> = T extends LazyFulfilled<infer D> ? D : never
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react-jsx",
|
|
4
|
-
"strict": true,
|
|
5
|
-
"alwaysStrict": true,
|
|
6
|
-
"allowUnreachableCode": false,
|
|
7
|
-
"allowUnusedLabels": false,
|
|
8
|
-
"noImplicitAny": true,
|
|
9
|
-
"noImplicitThis": true,
|
|
10
|
-
"noImplicitOverride": true,
|
|
11
|
-
"noUnusedLocals": true,
|
|
12
|
-
"noUnusedParameters": true,
|
|
13
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
14
|
-
"noUncheckedIndexedAccess": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": true,
|
|
16
|
-
"useUnknownInCatchVariables": true,
|
|
17
|
-
"exactOptionalPropertyTypes": true,
|
|
18
|
-
"moduleResolution": "nodenext",
|
|
19
|
-
"module": "nodenext",
|
|
20
|
-
"target": "esnext",
|
|
21
|
-
"declaration": true,
|
|
22
|
-
"sourceMap": true,
|
|
23
|
-
"skipLibCheck": true,
|
|
24
|
-
"rootDir": "src",
|
|
25
|
-
"outDir": "dist"
|
|
26
|
-
}
|
|
27
|
-
}
|