Skip to content

Commit b51d7bf

Browse files
committed
Some updates
1 parent cd3d8d9 commit b51d7bf

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
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-elements",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "",
55
"main": "./index.js",
66
"module": "./dist/js-elements.esm.production.js",

rollup.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ function createConfig(pkg, moduleFormat, productive) {
4242
plugins: [
4343
resolve(),
4444
commonjs(),
45-
// tslint({
46-
//}),
4745
replace({
4846
exclude: 'node_modules/**',
4947
delimiters: ['', ''],

src/main/core/base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Ctrl, Ref, UIEvent, VNode } from './types'
1+
import { Component, Ctrl, Props, Ref, UIEvent, VNode } from './types'
22
import { h, renderer } from './vdom'
33

44
// @ts-ignore
@@ -32,7 +32,7 @@ type Notifier = {
3232
notify(): void
3333
}
3434

35-
// === decorators =====================================================
35+
// === public decorators =============================================
3636

3737
function attr(kind: AttrKind): (proto: object, key: string) => void {
3838
return (proto: any, key: string) => {
@@ -48,7 +48,7 @@ function attr(kind: AttrKind): (proto: object, key: string) => void {
4848
}
4949
}
5050

51-
// === pulbic API ====================================================
51+
// === public functions ==============================================
5252

5353
function ref<T>(value: T | null = null): Ref<T> {
5454
return { current: value }
@@ -71,7 +71,7 @@ function event<T extends string, D = null>(
7171

7272
function define(tagName: string, main: () => () => VNode): Component<{}>
7373

74-
function define<P>(
74+
function define<P extends Props>(
7575
tagName: string,
7676
propsClass: { new (): P },
7777
main: (props: P) => () => VNode

src/main/core/hooks.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,30 @@ export const useInterval = createCoreHook(
451451

452452
// === useTimer ========================================================
453453

454-
export const useTimer = createCoreHook('useTimer', function <
455-
T
456-
>(c: Ctrl, delay: number | (() => number), getter: (n: number) => T = getDate as any): () => T {
457-
let idx = 0
458-
const getDelay = typeof delay === 'function' ? delay : () => delay
459-
const [getValue, setValue] = useValue(getter(idx++))
454+
type TimerSignature = {
455+
(delay: number | (() => number)): () => Date
456+
<T>(delay: number | (() => number), getValue: (n: number) => T): () => T
457+
}
460458

461-
useInterval(
462-
() => {
463-
setValue(getter(idx++))
464-
},
465-
() => getDelay()
466-
)
459+
export const useTimer = createHook(
460+
'useTimer',
461+
(delay: number | (() => number), get: (n: number) => any = getDate) => {
462+
let idx = 0
463+
const getDelay = typeof delay === 'function' ? delay : () => delay
464+
const [getValue, setValue] = useValue(get(idx++))
467465

468-
return getValue
469-
})
466+
useInterval(
467+
() => {
468+
setValue(get(idx++))
469+
},
470+
() => getDelay()
471+
)
472+
473+
return getValue
474+
}
475+
) as TimerSignature
470476

471-
function getDate(idx: number) {
477+
function getDate() {
472478
return new Date()
473479
}
474480

src/main/core/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export type VElement<T extends Props = Props> = Record<any, any> // TODO
33
export type Ref<T> = { current: T | null }
44
export type Methods = Record<string, (...args: any[]) => any>
55
export type EventHandler<T> = (ev: T) => void
6-
76
export type UIEvent<T extends string, D = null> = CustomEvent<D> & { type: T }
87

98
export type VNode =
@@ -17,7 +16,11 @@ export type VNode =
1716
export type Task = () => void
1817
export type Message = { type: string } & Record<string, any>
1918
export type State = Record<string, any>
20-
export type Component<P> = (props?: P, ...children: VNode[]) => VElement<P>
19+
20+
export type Component<P> = {
21+
(props?: P, ...children: VNode[]): VElement<P>
22+
tagName: string
23+
}
2124

2225
export type MethodsOf<C> = C extends Component<infer P>
2326
? P extends { ref?: Ref<infer M> }
@@ -26,8 +29,8 @@ export type MethodsOf<C> = C extends Component<infer P>
2629
: never
2730

2831
export type Ctrl = {
29-
// library agnostic component control functions
3032
getName(): string
33+
getHost(): HTMLElement
3134
isInitialized(): boolean
3235
isMounted(): boolean
3336
hasUpdated(): boolean
@@ -37,12 +40,11 @@ export type Ctrl = {
3740
beforeUpdate(task: Task): void
3841
afterUpdate(task: Task): void
3942
beforeUnmount(task: Task): void
40-
getHost(): HTMLElement
4143
}
4244

4345
export type Store<S extends State> = {
4446
getState(): S
45-
subscribe(listener: () => void): () => void
47+
subscribe(subscriber: () => void): () => void
4648
dispatch(msg: Message): void
4749
destroy?(): void
4850
}

0 commit comments

Comments
 (0)