@equinor/fusion-observable
Advanced tools
Comparing version 8.1.4 to 8.1.5
@@ -18,3 +18,3 @@ export function createAction(type, prepareAction) { | ||
export const actionSuffixDivider = '::'; | ||
export const matchActionSuffix = (suffix) => new RegExp(`${actionSuffixDivider}\\${suffix}$`); | ||
export const matchActionSuffix = (suffix) => new RegExp(`${actionSuffixDivider}${suffix}$`); | ||
export const actionBaseType = (action) => action.type.replace(matchActionSuffix('\\w+$'), ''); | ||
@@ -21,0 +21,0 @@ export function getType(actionCreator) { |
@@ -1,14 +0,20 @@ | ||
import { useLayoutEffect, useMemo, useState } from 'react'; | ||
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react'; | ||
import { useObservableLayoutSubscription } from './useObservableSubscription'; | ||
export function useObservableState(subject, opt) { | ||
const [next, setNext] = useState(() => { | ||
return (opt === null || opt === void 0 ? void 0 : opt.initial) ? ('value' in subject ? subject.value : opt.initial) : undefined; | ||
}); | ||
const resolveInitial = useCallback(() => { | ||
var _a, _b; | ||
return (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.initial) !== null && _a !== void 0 ? _a : subject.value) !== null && _b !== void 0 ? _b : undefined; | ||
}, [subject, opt === null || opt === void 0 ? void 0 : opt.initial]); | ||
const initialValue = useRef(resolveInitial()); | ||
const [next, setNext] = useState(initialValue.current); | ||
const [error, setError] = useState(null); | ||
const [complete, setComplete] = useState(false); | ||
useLayoutEffect(() => { | ||
initialValue.current = resolveInitial(); | ||
}, [resolveInitial]); | ||
useLayoutEffect(() => { | ||
setError(null); | ||
setComplete(false); | ||
setNext('value' in subject ? subject.value : undefined); | ||
}, [setNext, setError, setComplete, subject]); | ||
setNext(initialValue.current); | ||
}, [setNext, setError, setComplete, subject, initialValue]); | ||
const subscriber = useMemo(() => ({ | ||
@@ -15,0 +21,0 @@ next: setNext, |
@@ -1,2 +0,2 @@ | ||
export const version = '8.1.4'; | ||
export const version = '8.1.5'; | ||
//# sourceMappingURL=version.js.map |
@@ -1,1 +0,1 @@ | ||
export declare const version = "8.1.4"; | ||
export declare const version = "8.1.5"; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "8.1.4", | ||
"version": "8.1.5", | ||
"description": "WIP", | ||
@@ -66,3 +66,3 @@ "keywords": [ | ||
"@types/uuid": "^9.0.4", | ||
"happy-dom": "^12.0.1", | ||
"happy-dom": "^13.3.8", | ||
"react": "^18.2.0", | ||
@@ -69,0 +69,0 @@ "typescript": "^5.1.3", |
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
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
149912
760