mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
wip
This commit is contained in:
parent
76a4f0c17e
commit
a26a2cfaf7
@ -12,7 +12,7 @@ describe("subtree", () => {
|
||||
|
||||
const otherRoot = createRoot().withTypes<{ value: string }>()
|
||||
|
||||
subtree(subnode, (ctx) => otherRoot.run(null, { value: ctx(subnode) }))
|
||||
subtree(subnode, otherRoot, (ctx) => [null, { value: ctx(subnode) }])
|
||||
|
||||
mainRoot.run()
|
||||
|
||||
@ -31,7 +31,7 @@ describe("subtree", () => {
|
||||
const otherRootCopy = substate(subnode, () => activeObs$(otherRoot))
|
||||
|
||||
const otherRoot = createRoot().withTypes<{ value: string }>()
|
||||
subtree(subnode, (ctx) => otherRoot.run(null, { value: ctx(subnode) }))
|
||||
subtree(subnode, otherRoot, (ctx) => [null, { value: ctx(subnode) }])
|
||||
|
||||
mainRoot.run()
|
||||
|
||||
|
||||
@ -7,17 +7,29 @@ import {
|
||||
StateNode,
|
||||
isSignal,
|
||||
} from "./types"
|
||||
import { RootNode } from "./create-root"
|
||||
|
||||
export function subtree<K extends KeysBaseType>(
|
||||
export function subtree<K extends KeysBaseType, CtxValue, KeyValue>(
|
||||
parent: StateNode<unknown, K>,
|
||||
createInstance: (
|
||||
node: RootNode<CtxValue, string, KeyValue>,
|
||||
instanceSelector: (
|
||||
ctxValue: GetValueFn,
|
||||
ctxObservable: GetObservableFn<K>,
|
||||
key: K,
|
||||
) => () => void,
|
||||
) => [KeyValue] | [KeyValue, CtxValue],
|
||||
): void {
|
||||
const internalParent = getInternals(parent)
|
||||
|
||||
const createInstance = (
|
||||
ctxValue: GetValueFn,
|
||||
ctxObservable: GetObservableFn<K>,
|
||||
key: K,
|
||||
) => {
|
||||
const [keyValue, context] = instanceSelector(ctxValue, ctxObservable, key)
|
||||
|
||||
return node.run(keyValue, context!)
|
||||
}
|
||||
|
||||
const teardowns = new NestedMap<K[keyof K], () => void>()
|
||||
const nestedMapKey = (key: K) => internalParent.keysOrder.map((k) => key[k])
|
||||
const teardown = (key: K) => teardowns.get(nestedMapKey(key))?.()
|
||||
|
||||
@ -2,6 +2,7 @@ import { ObservableInput, from, Observable } from "rxjs"
|
||||
import { SUSPENSE } from "@react-rxjs/core"
|
||||
import { defaultStart } from "./internal-utils"
|
||||
|
||||
//
|
||||
/**
|
||||
* A RxJS creation operator that prepends a SUSPENSE on the source observable.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user