@equinor/fusion-observable
Advanced tools
Comparing version 4.0.1 to 6.0.0
@@ -8,4 +8,4 @@ import { useMemo } from 'react'; | ||
export const useObservableInputState = (input, initial) => { | ||
return useObservableState(useObservableInput(input), initial); | ||
return useObservableState(useObservableInput(input), { initial }).next; | ||
}; | ||
//# 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); | ||
export const useObservableSelectorState = (subject, selector, initial, compare) => useObservableState(useObservableSelector(subject, selector, compare), { initial }).next; | ||
//# sourceMappingURL=useObservableSelectorState.js.map |
@@ -1,10 +0,13 @@ | ||
import { useState } from 'react'; | ||
import { useMemo, useState } from 'react'; | ||
import { useObservableLayoutSubscription } from './useObservableSubscription'; | ||
export function useObservableState(subject, initial) { | ||
initial !== null && initial !== void 0 ? initial : (initial = subject.value); | ||
const [state, setState] = useState(initial); | ||
useObservableLayoutSubscription(subject, setState); | ||
return state; | ||
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 [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 }; | ||
} | ||
export default useObservableState; | ||
//# sourceMappingURL=useObservableState.js.map |
import { Observable } from '../types'; | ||
export declare function useObservableState<S>(subject: Observable<S>): S | undefined; | ||
export declare function useObservableState<S>(subject: Observable<S>, initial: S): S; | ||
type ObservableStateOptions<S> = { | ||
initial?: S; | ||
teardown?: VoidFunction; | ||
}; | ||
type ObservableStateReturnType<S, E = unknown> = { | ||
next: 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 default useObservableState; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "4.0.1", | ||
"version": "6.0.0", | ||
"description": "WIP", | ||
@@ -72,3 +72,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "85cb1b4a12ef25787cd6d88da648c566c810b9f5" | ||
"gitHead": "48e578f429ca02ed6bb0240d7c8ae64a80ed52a4" | ||
} |
@@ -101,3 +101,3 @@ # Observable | ||
const { state$, setSelected } = useContext(TodoContext); | ||
const items = useObservableState(state$); | ||
const items = useObservableState(state$).next; | ||
return ( | ||
@@ -104,0 +104,0 @@ <ul> |
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
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
141674
692