@equinor/fusion-observable
Advanced tools
Comparing version 0.1.12 to 0.2.0
@@ -5,2 +5,3 @@ export { Query } from './Query'; | ||
export { QueryError } from './errors'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.js.map |
@@ -23,2 +23,8 @@ import { asyncScheduler, firstValueFrom, Observable, Subscription } from 'rxjs'; | ||
} | ||
get status() { | ||
return this.value.status; | ||
} | ||
get error() { | ||
return this.value.error; | ||
} | ||
constructor(queryFn, config) { | ||
@@ -25,0 +31,0 @@ super((subscriber) => { |
import { interval, Observable, Subject } from 'rxjs'; | ||
import { debounce, pluck, filter, withLatestFrom, map } from 'rxjs/operators'; | ||
import { debounce, filter, withLatestFrom, map } from 'rxjs/operators'; | ||
import { Query } from './Query'; | ||
@@ -16,3 +16,3 @@ import { QueryCache } from './QueryCache'; | ||
constructor(queryFn, options) { | ||
super((subscriber) => this.__state$.pipe(pluck('data')).subscribe(subscriber)); | ||
super((subscriber) => this.__state$.pipe(map((x) => x.data)).subscribe(subscriber)); | ||
this.__client$ = new Query(queryFn, { | ||
@@ -19,0 +19,0 @@ retry: options?.retry, |
export * from './useObservable'; | ||
export * from './useObservableEffect'; | ||
export * from './useObservableEpic'; | ||
export * from './useObservableRef'; | ||
@@ -8,2 +9,4 @@ export * from './useObservableState'; | ||
export * from './useObservableSubscription'; | ||
export * from './useObservableInput'; | ||
export * from './useQueryClient'; | ||
//# sourceMappingURL=index.js.map |
import { useEffect, useLayoutEffect } from 'react'; | ||
export const useObservableSubscription = (observable, observer) => { | ||
export const useObservableSubscription = (observable, observer, teardown) => { | ||
useEffect(() => { | ||
const subscription = observable.subscribe(observer); | ||
subscription.add(teardown); | ||
return () => subscription.unsubscribe(); | ||
}, [observable, observer]); | ||
}; | ||
export const useObservableLayoutSubscription = (observable, observer) => { | ||
export const useObservableLayoutSubscription = (observable, observer, teardown) => { | ||
useLayoutEffect(() => { | ||
const subscription = observable.subscribe(observer); | ||
subscription.add(teardown); | ||
return () => subscription.unsubscribe(); | ||
@@ -12,0 +14,0 @@ }, [observable, observer]); |
@@ -12,3 +12,3 @@ import { asyncScheduler, BehaviorSubject, EMPTY, from, Observable, Subject, } from 'rxjs'; | ||
get value() { | ||
return this.__state$.getValue(); | ||
return this.__state$.value; | ||
} | ||
@@ -36,4 +36,11 @@ get closed() { | ||
const mapper = (fn ? fn : actionTypeOrFn); | ||
return (action$ ?? this.__action$) | ||
.pipe(mergeMap((action) => from(Promise.resolve(mapper(action, this.value))).pipe(catchError((err) => { | ||
return action$ | ||
.pipe(mergeMap((action) => from(new Promise((resolve, reject) => { | ||
try { | ||
resolve(mapper(action, this.value)); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
})).pipe(catchError((err) => { | ||
console.warn('unhandled effect', err); | ||
@@ -60,2 +67,3 @@ return EMPTY; | ||
unsubscribe() { | ||
this.__action$.unsubscribe(); | ||
this.__state$.unsubscribe(); | ||
@@ -62,0 +70,0 @@ } |
export { Query } from './Query'; | ||
export { QueryCache } from './QueryCache'; | ||
export { QueryClient } from './QueryClient'; | ||
export { QueryClient, QueryOptions } from './QueryClient'; | ||
export { QueryError } from './errors'; | ||
export * from './types'; |
import { Observable, Subscription } from 'rxjs'; | ||
import { ExtractAction } from '..'; | ||
import { Actions, ActionType, RequestAction } from './actions'; | ||
import { RetryOpt, QueryFn, QueryState } from './types'; | ||
import { RetryOpt, QueryFn, QueryState, QueryStatus } from './types'; | ||
declare type QueryOptions = { | ||
@@ -15,2 +15,4 @@ controller: AbortController; | ||
get closed(): boolean; | ||
get status(): QueryStatus; | ||
get error(): unknown; | ||
constructor(queryFn: QueryFn<TType, TArgs>, config?: { | ||
@@ -17,0 +19,0 @@ retry?: Partial<RetryOpt>; |
export * from './useObservable'; | ||
export * from './useObservableEffect'; | ||
export * from './useObservableEpic'; | ||
export * from './useObservableRef'; | ||
@@ -8,1 +9,3 @@ export * from './useObservableState'; | ||
export * from './useObservableSubscription'; | ||
export * from './useObservableInput'; | ||
export * from './useQueryClient'; |
import { Observable, Observer } from 'rxjs'; | ||
export declare const useObservableSubscription: <T>(observable: Observable<T>, observer: Partial<Observer<T>> | ((value: T) => void)) => void; | ||
export declare const useObservableLayoutSubscription: <T>(observable: Observable<T>, observer: Partial<Observer<T>> | ((value: T) => void)) => void; | ||
export declare const useObservableSubscription: <T>(observable: Observable<T>, observer: Partial<Observer<T>> | ((value: T) => void), teardown?: () => void) => void; | ||
export declare const useObservableLayoutSubscription: <T>(observable: Observable<T>, observer: Partial<Observer<T>> | ((value: T) => void), teardown?: () => void) => void; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "0.1.12", | ||
"version": "0.2.0", | ||
"description": "WIP", | ||
@@ -84,3 +84,3 @@ "private": false, | ||
}, | ||
"gitHead": "db8d65b393e368a87840015939e321b7cc707259" | ||
"gitHead": "5f5ceed6b3f4f6ab12036f1f2953d293dff86cae" | ||
} |
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
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
131194
87
808