mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
trying to solve that issue
This commit is contained in:
parent
1efed6b2d2
commit
4511e4440c
@ -16,6 +16,7 @@ export interface Instance<T, K> {
|
||||
export function createInstance<T, K extends KeysBaseType>(
|
||||
key: K,
|
||||
observable: Observable<T>,
|
||||
onAfterChange: () => void,
|
||||
): Instance<T, K> {
|
||||
let subject = new BehaviorSubject<T | EMPTY_VALUE>(EMPTY_VALUE)
|
||||
|
||||
@ -35,6 +36,7 @@ export function createInstance<T, K extends KeysBaseType>(
|
||||
next: (v) => {
|
||||
deferred.res(v)
|
||||
subject.next(v)
|
||||
onAfterChange()
|
||||
},
|
||||
error: (e) => {
|
||||
deferred.rej(e)
|
||||
@ -69,6 +71,7 @@ export function createInstance<T, K extends KeysBaseType>(
|
||||
}
|
||||
},
|
||||
reset() {
|
||||
// TODO how to reset without activating straight away with this flow?
|
||||
if (error !== EMPTY_VALUE || subject.getValue() !== EMPTY_VALUE) {
|
||||
// If the new subscription returns the same value synchronously, do not complete the previous result.
|
||||
// TODO the child nodes should also reset... are they resetting?
|
||||
|
||||
@ -15,6 +15,12 @@ import { NestedMap, Wildcard } from "./nested-map"
|
||||
import { StatePromise } from "./promises"
|
||||
import { Instance, createInstance } from "./state-instance"
|
||||
|
||||
export type InstanceEvent =
|
||||
| "added"
|
||||
| "ready"
|
||||
| "removed"
|
||||
| "reset"
|
||||
| "postchange"
|
||||
export interface InternalStateNode<T, K extends KeysBaseType> {
|
||||
keysOrder: Array<keyof K>
|
||||
getInstances: (
|
||||
@ -26,7 +32,7 @@ export interface InternalStateNode<T, K extends KeysBaseType> {
|
||||
removeInstance: (key: K) => void
|
||||
resetInstance: (key: K) => void
|
||||
instanceChange$: Observable<{
|
||||
type: "added" | "ready" | "removed" | "reset"
|
||||
type: InstanceEvent
|
||||
key: K
|
||||
}>
|
||||
getContext: <TC>(
|
||||
@ -98,7 +104,7 @@ export function createStateNode<K extends KeysBaseType, R>(
|
||||
throw inactiveContext()
|
||||
}
|
||||
const instanceChange$ = new Subject<{
|
||||
type: "added" | "ready" | "removed" | "reset"
|
||||
type: InstanceEvent
|
||||
key: K
|
||||
}>()
|
||||
const addInstance = (key: K) => {
|
||||
@ -147,6 +153,11 @@ export function createStateNode<K extends KeysBaseType, R>(
|
||||
}
|
||||
}),
|
||||
),
|
||||
() =>
|
||||
instanceChange$.next({
|
||||
type: "postchange",
|
||||
key,
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@ -178,7 +189,6 @@ export function createStateNode<K extends KeysBaseType, R>(
|
||||
if (!instance) {
|
||||
// TODO is this a valid path? Maybe throw error instead!
|
||||
addInstance(key)
|
||||
activateInstance(key)
|
||||
return
|
||||
}
|
||||
// Only kill + readd if it was already active.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user