Skip to content

Commit 1bd8fd7

Browse files
committed
Renamed type Context to Ctx
1 parent aa3422f commit 1bd8fd7

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-element",
3-
"version": "0.0.209",
3+
"version": "0.0.212",
44
"description": "",
55
"license": "LGPL-3.0",
66
"main": "./index.js",

src/main/js-element-hooks.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { intercept, Context, Ctrl } from 'js-element'
1+
import { intercept, Ctrl, Ctx } from 'js-element'
22

33
// === data ==========================================================
44

@@ -25,18 +25,10 @@ type MessageCreators = {
2525
[key: string]: (...args: any[]) => Message
2626
}
2727

28-
type Selectors<S extends State> = {
29-
[key: string]: (state: S) => any
30-
}
31-
32-
type SelectorsOf<S extends State, U extends Selectors<S>> = {
33-
[K in keyof U]: U[K] extends (state: S) => infer R ? R : never
34-
}
35-
36-
type CtxConfig = Record<string, Context<any> | (() => any)>
28+
type CtxConfig = Record<string, Ctx<any> | (() => any)>
3729

3830
type ResultOfCtxConfig<C extends CtxConfig> = {
39-
[K in keyof C]: C[K] extends Context<infer R>
31+
[K in keyof C]: C[K] extends Ctx<infer R>
4032
? R
4133
: C[K] extends () => infer R
4234
? R
@@ -524,7 +516,7 @@ function isEqualArray(arr1: any[], arr2: any[]) {
524516
// === context =======================================================
525517

526518
type ContextDetail<T> = {
527-
context: Context<T>
519+
context: Ctx<T>
528520
callback: (newValue: T) => void
529521
cancelled: Promise<null>
530522
}
@@ -533,7 +525,7 @@ export const useCtx = hook('useCtx', useCtxFn)
533525

534526
function useCtxFn<C extends CtxConfig>(config: C): ResultOfCtxConfig<C>
535527

536-
function useCtxFn<T>(ctx: Context<T>): () => T
528+
function useCtxFn<T>(ctx: Ctx<T>): () => T
537529

538530
function useCtxFn(arg: any): any {
539531
if (arg && arg.kind === 'context') {
@@ -554,7 +546,7 @@ function useCtxFn(arg: any): any {
554546
return ret
555547
}
556548

557-
function withConsumer<T>(ctx: Context<T>): () => T {
549+
function withConsumer<T>(ctx: Ctx<T>): () => T {
558550
const c = currentCtrl!
559551
const host = c.getHost()
560552
let cancel: null | (() => void) = null

src/main/js-element.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
export { component, createCtx, elem, intercept, prop, setMethods, Attrs }
55

66
// types
7-
export { Context, Ctrl, MethodsOf }
7+
export { Ctx, Ctrl, MethodsOf }
88

99
// === data ==========================================================
1010

@@ -67,7 +67,7 @@ type Ctrl = {
6767

6868
type InterceptFn = (ctrl: Ctrl, next: () => void) => void
6969

70-
type Context<T> = Readonly<{
70+
type Ctx<T> = Readonly<{
7171
kind: 'context'
7272
defaultValue: T
7373
}>
@@ -86,7 +86,7 @@ function elem<E extends Component, C>(params: {
8686

8787
function elem<T, E extends Component & { value?: T }>(params: {
8888
tag: `${string}-provider`
89-
ctx: Context<T>
89+
ctx: Ctx<T>
9090
}): (clazz: new () => E) => void
9191

9292
function elem<E extends Component>(params: any) {
@@ -516,14 +516,14 @@ function registerElement(
516516

517517
// === context =======================================================
518518

519-
function createCtx<T>(defaultValue?: T): Context<T> {
519+
function createCtx<T>(defaultValue?: T): Ctx<T> {
520520
return Object.freeze({
521521
kind: 'context',
522522
defaultValue: defaultValue!
523523
})
524524
}
525525

526-
function initProvider(self: any, ctrl: Ctrl, ctx: Context<any>): () => null {
526+
function initProvider(self: any, ctrl: Ctrl, ctx: Ctx<any>): () => null {
527527
const subscribers = new Set<any>() // TODO
528528
let cleanup: any = null // TODO
529529
let value = ctx.defaultValue

0 commit comments

Comments
 (0)