Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Commit 6a68602

Browse files
committed
Add ContextUpRef type
1 parent 65709cf commit 6a68602

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/context-ref.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export interface ContextTarget<Src, Seed = unknown> extends ContextRequest<any,
7575

7676
/**
7777
* Context value reference that can serve both as [[ContextRequest]] and as [[ContextTarget]].
78+
*
79+
* @typeparam Value Context value type.
80+
* @typeparam Src Source value type.
81+
* @typeparam Seed Value seed type.
7882
*/
7983
export interface ContextRef<Value, Src = Value, Seed = unknown>
8084
extends ContextRequest<Value, Seed>, ContextTarget<Src, Seed> {

src/context-up-key.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ class ContextSeedUpKey<Src> extends ContextSeedKey<Src | EventKeeper<Src[]>, Aft
9898

9999
}
100100

101+
/**
102+
* Updatable context value reference.
103+
*
104+
* @typeparam Value Context value type.
105+
* @typeparam Src Source value type.
106+
* @typeparam Seed Value seed type.
107+
*/
108+
export type ContextUpRef<Value, Src, Seed = unknown> = ContextRef<Value, Src | EventKeeper<Src[]>, Seed>;
109+
101110
/**
102111
* Abstract implementation of updatable context value key.
103112
*
@@ -108,7 +117,9 @@ class ContextSeedUpKey<Src> extends ContextSeedKey<Src | EventKeeper<Src[]>, Aft
108117
* @typeparam Value Context value type.
109118
* @typeparam Src Source value type.
110119
*/
111-
export abstract class ContextUpKey<Value, Src> extends ContextKey<Value, Src | EventKeeper<Src[]>, AfterEvent<Src[]>> {
120+
export abstract class ContextUpKey<Value, Src>
121+
extends ContextKey<Value, Src | EventKeeper<Src[]>, AfterEvent<Src[]>>
122+
implements ContextUpRef<Value, Src, AfterEvent<Src[]>> {
112123

113124
readonly seedKey: ContextSeedKey<Src | EventKeeper<Src[]>, AfterEvent<Src[]>>;
114125

@@ -131,8 +142,7 @@ export abstract class ContextUpKey<Value, Src> extends ContextKey<Value, Src | E
131142
* @typeparam Value Context value type.
132143
* @typeparam Seed Value seed type.
133144
*/
134-
export type SingleContextUpRef<Value, Seed = unknown> =
135-
ContextRef<AfterEvent<[Value]>, Value | AfterEvent<Value[]>, Seed>;
145+
export type SingleContextUpRef<Value, Seed = unknown> = ContextUpRef<AfterEvent<[Value]>, Value, Seed>;
136146

137147
/**
138148
* Single updatable context value key.
@@ -211,8 +221,7 @@ export class SingleContextUpKey<Value>
211221
* @typeparam Src Source value type.
212222
* @typeparam Seed Value seed type.
213223
*/
214-
export type MultiContextUpRef<Src, Seed = unknown> =
215-
ContextRef<AfterEvent<Src[]>, Src | AfterEvent<Src[]>, Seed>;
224+
export type MultiContextUpRef<Src, Seed = unknown> = ContextUpRef<AfterEvent<Src[]>, Src, Seed>;
216225

217226
/**
218227
* Multiple updatable context values key.

src/fn-context-key.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { AfterEvent, EventKeeper } from 'fun-events';
22
import { ContextSeedKey, ContextValueOpts } from './context-key';
33
import { ContextKeyError } from './context-key-error';
4-
import { ContextRef } from './context-ref';
5-
import { ContextUpKey } from './context-up-key';
4+
import { ContextUpKey, ContextUpRef } from './context-up-key';
65
import { ContextValues } from './context-values';
76

87
/**
@@ -12,10 +11,8 @@ import { ContextValues } from './context-values';
1211
* @typeparam Ret Function return value type.
1312
* @typeparam Seed Value seed type.
1413
*/
15-
export type FnContextRef<Args extends any[], Ret = void, Seed = unknown> = ContextRef<
16-
(this: void, ...args: Args) => Ret,
17-
((this: void, ...args: Args) => Ret) | EventKeeper<((this: void, ...args: Args) => Ret)[]>,
18-
Seed>;
14+
export type FnContextRef<Args extends any[], Ret = void, Seed = unknown> =
15+
ContextUpRef<(this: void, ...args: Args) => Ret, (this: void, ...args: Args) => Ret, Seed>;
1916

2017
/**
2118
* A key of updatable context function value.

0 commit comments

Comments
 (0)