export missing types

This commit is contained in:
Víctor Oliva 2022-10-29 13:36:31 +02:00
parent c75896006f
commit ed4c2a49c4
4 changed files with 13 additions and 6 deletions

View File

@ -24,7 +24,7 @@
"dist"
],
"scripts": {
"build": "npm run build:ts && npm run build:esm2017 && npm run build:esm2019 && npm run build:cjs:dev && npm run build:cjs:prod",
"build": "npm run build:ts && npm run build:esm2017 && npm run build:esm2019",
"build:esm2019": "esbuild src/index.tsx --bundle --outfile=./dist/context-state.es2019.mjs --target=es2019 --external:react --external:rxjs --external:use-sync-external-store --format=esm --sourcemap",
"build:esm2017": "esbuild src/index.tsx --bundle --outfile=./dist/context-state.es2017.js --target=es2017 --external:react --external:rxjs --external:use-sync-external-store --format=esm --sourcemap",
"build:cjs:dev": "node cjsBuild.js",

View File

@ -1,2 +1,7 @@
export * from "./types"
export * from "./combineStates"
export * from "./create-signal"
export * from "./create-root"
export * from "./route-state"
export * from "./substate"
export * from "./types"
export { StatePromise } from "./internal/promisses"

View File

@ -6,7 +6,7 @@ import {
} from "./internal"
import { of } from "rxjs"
import { substate } from "./substate"
import { StateNode, CtxFn, StringRecord } from "./types"
import { StateNode, GetValueFn, StringRecord } from "./types"
export class InvalidRouteError extends Error {
constructor(key: string, keys: string[]) {
@ -33,12 +33,12 @@ export const routeState = <
>(
parent: StateNode<T, K>,
routes: O,
selector: (value: T, ctx: CtxFn<T, K>) => keyof O,
selector: (value: T, ctx: GetValueFn) => string & keyof O,
): [StateNode<keyof O, K>, OT] => {
const internalParent = getInternals(parent)
const keys = new Set(Object.keys(routes))
const keyState = substate(parent, (ctx) => {
const key = selector(ctx(parent), ctx as any) as string
const key = selector(ctx(parent), ctx)
if (!keys.has(key)) throw new InvalidRouteError(key, [...keys])
return of(key)
})

View File

@ -28,8 +28,10 @@ interface GetObservableFn<K> {
): Observable<T>
}
export type GetValueFn = <CT>(node: StateNode<CT, any>) => CT
export type CtxFn<T, K extends StringRecord<any>> = (
ctxValue: <CT>(node: StateNode<CT, any>) => CT,
ctxValue: GetValueFn,
ctxObservable: GetObservableFn<K>,
key: K,
) => Observable<T>