@equinor/fusion-observable
Advanced tools
Comparing version 6.0.0 to 7.0.0
@@ -8,4 +8,4 @@ import { useMemo } from 'react'; | ||
export const useObservableInputState = (input, initial) => { | ||
return useObservableState(useObservableInput(input), { initial }).next; | ||
return useObservableState(useObservableInput(input), { initial }); | ||
}; | ||
//# sourceMappingURL=useObservableInput.js.map |
import { useObservableSelector } from './useObservableSelector'; | ||
import { useObservableState } from './useObservableState'; | ||
export const useObservableSelectorState = (subject, selector, initial, compare) => useObservableState(useObservableSelector(subject, selector, compare), { initial }).next; | ||
export const useObservableSelectorState = (subject, selector, initial, compare) => useObservableState(useObservableSelector(subject, selector, compare), { initial }); | ||
//# sourceMappingURL=useObservableSelectorState.js.map |
@@ -1,13 +0,27 @@ | ||
import { useMemo, useState } from 'react'; | ||
import { useCallback, useLayoutEffect, useMemo, useState } from 'react'; | ||
import { useObservableLayoutSubscription } from './useObservableSubscription'; | ||
export function useObservableState(subject, opt) { | ||
var _a; | ||
const initial = (_a = opt === null || opt === void 0 ? void 0 : opt.initial) !== null && _a !== void 0 ? _a : subject.value; | ||
const [next, setNext] = useState(initial); | ||
const [initialValue] = useState(opt === null || opt === void 0 ? void 0 : opt.initial); | ||
const [next, setNext] = useState(initialValue); | ||
const [error, setError] = useState(null); | ||
const [complete, setComplete] = useState(false); | ||
useObservableLayoutSubscription(subject, useMemo(() => ({ next: setNext, error: setError, complete: () => setComplete(true) }), []), opt === null || opt === void 0 ? void 0 : opt.teardown); | ||
return { next, error, complete }; | ||
const resetState = useCallback(() => { | ||
setError(null); | ||
setNext(initialValue); | ||
setComplete(false); | ||
}, [setNext, setError, setComplete, initialValue]); | ||
useLayoutEffect(() => { | ||
const subjectValue = subject.value; | ||
subjectValue && setNext(subjectValue); | ||
return resetState; | ||
}, [setNext, resetState, subject]); | ||
const subscriber = useMemo(() => ({ | ||
next: setNext, | ||
error: setError, | ||
complete: () => setComplete(true), | ||
}), [setNext, setError, setComplete]); | ||
useObservableLayoutSubscription(subject, subscriber, opt === null || opt === void 0 ? void 0 : opt.teardown); | ||
return { value: next, error, complete }; | ||
} | ||
export default useObservableState; | ||
//# sourceMappingURL=useObservableState.js.map |
import { Observable, ObservableInput } from 'rxjs'; | ||
import { ObservableStateReturnType } from './useObservableState'; | ||
export declare const useObservableInput: <T>(input: ObservableInput<T>) => Observable<T>; | ||
export declare const useObservableInputState: <T>(input: ObservableInput<T>, initial?: T | undefined) => T | undefined; | ||
export declare const useObservableInputState: <T, E = unknown, I = undefined>(input: ObservableInput<T>, initial: I) => ObservableStateReturnType<T | I, E>; |
@@ -0,2 +1,3 @@ | ||
import { ObservableStateReturnType } from './useObservableState'; | ||
import { Observable } from '../types'; | ||
export declare const useObservableSelectorState: <S, P extends keyof S, R = S[P]>(subject: Observable<S>, selector: P | ((state: S) => R), initial?: R | undefined, compare?: ((x: R, y: R) => boolean) | undefined) => R | undefined; | ||
export declare const useObservableSelectorState: <S, P extends keyof S, R = S[P], E = unknown>(subject: Observable<S>, selector: P | ((state: S) => R), initial?: R | undefined, compare?: ((x: R, y: R) => boolean) | undefined) => ObservableStateReturnType<R | undefined, E>; |
import { Observable } from '../types'; | ||
type ObservableStateOptions<S> = { | ||
initial?: S; | ||
type ObservableStateOptions<S = undefined> = { | ||
initial: S; | ||
teardown?: VoidFunction; | ||
}; | ||
type ObservableStateReturnType<S, E = unknown> = { | ||
next: S; | ||
export type ObservableStateReturnType<S, E = unknown> = { | ||
value: S; | ||
error: E | null; | ||
complete: boolean; | ||
}; | ||
export declare function useObservableState<S>(subject: Observable<S>): ObservableStateReturnType<S>; | ||
export declare function useObservableState<S, E = unknown>(subject: Observable<S>, opt?: ObservableStateOptions<S>): ObservableStateReturnType<S, E>; | ||
export declare function useObservableState<S>(subject: Observable<S>): ObservableStateReturnType<S | undefined>; | ||
export declare function useObservableState<S, E = unknown, I = undefined>(subject: Observable<S>, opt: ObservableStateOptions<S> | ObservableStateOptions<I>): ObservableStateReturnType<S | I, E>; | ||
export declare function useObservableState<S, E = unknown, I = undefined>(subject: Observable<S>, opt: { | ||
initial: I; | ||
teardown?: VoidFunction; | ||
}): ObservableStateReturnType<S | I, E>; | ||
export default useObservableState; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "WIP", | ||
@@ -72,3 +72,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "48e578f429ca02ed6bb0240d7c8ae64a80ed52a4" | ||
"gitHead": "5c04abe62f8da3121c3b54bbab8c6703fcfbb7f6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143087
712