From 419b304ba5cb7a634ae5a4e6c48d82ffea153d8d Mon Sep 17 00:00:00 2001 From: hhh <1340545944@qq.com> Date: Wed, 30 Jan 2019 22:09:29 +0800 Subject: [PATCH] add EmptyStore type --- src/core/HUI.ts | 3 ++- src/core/Store.ts | 2 ++ src/ext/Fragment.ts | 4 ++-- src/ext/Portal.ts | 6 +++--- test/src/CatchTest.tsx | 4 ++-- test/src/Dialog.tsx | 2 +- test/src/Greeting.tsx | 6 +++--- test/src/Inspector.ts | 2 +- test/src/TestInput.tsx | 2 +- test/src/ThrowTest.tsx | 2 +- test/src/Timer.tsx | 2 +- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/core/HUI.ts b/src/core/HUI.ts index d0460d2..f30895d 100644 --- a/src/core/HUI.ts +++ b/src/core/HUI.ts @@ -1,7 +1,7 @@ import { HProps as _HProps, HDesc as _HDesc, HNode as _HNode } from "./HNode"; import { registry, define, HType as _HType } from "./registry"; import { _assign, _Infinity, _requestAnimationFrame } from "../utils/refCache"; -import { Store as _Store, createStore, HandlerMap as _HandlerMap, Setter as _Setter, SetterRecord as _SetterRecord, StoreType as _StoreType, StoreHandlers as _StoreHandlers, PartialHandlers as _PartialHandlers } from "./Store"; +import { Store as _Store, createStore, HandlerMap as _HandlerMap, Setter as _Setter, SetterRecord as _SetterRecord, StoreType as _StoreType, StoreHandlers as _StoreHandlers, PartialHandlers as _PartialHandlers, EmptyStore as _EmptyStore } from "./Store"; import { RenderOptions as _RenderOptions, renderToDOM } from "./render"; import { propHandlers, EleProps as _EleProps, PropHandler as _PropHandler, RefCallback as _RefCallback, AttributeMap as _AttributeMap } from "./propHandlers"; import { EventRecord as _EventRecord, EventMap as _EventMap } from "./events"; @@ -52,6 +52,7 @@ export namespace HUI { export type HandlerMap = _HandlerMap; export type Setter = _Setter; export type SetterRecord = _SetterRecord; + export type EmptyStore = _EmptyStore; export type RenderOptions = _RenderOptions; diff --git a/src/core/Store.ts b/src/core/Store.ts index 90a9bc9..081d5d9 100644 --- a/src/core/Store.ts +++ b/src/core/Store.ts @@ -20,6 +20,8 @@ export type PartialHandlers = { [K in keyof H]?: Inject export type StoreType = S extends Store ? T : never; export type StoreHandlers = S extends Store ? H : never; +export type EmptyStore = Store<{}>; + export interface Store = any> { valueMap: MapOf; diff --git a/src/ext/Fragment.ts b/src/ext/Fragment.ts index e975b3a..5956134 100644 --- a/src/ext/Fragment.ts +++ b/src/ext/Fragment.ts @@ -1,11 +1,11 @@ import { define } from "../core/registry"; -import { Store } from "../core/Store"; +import { EmptyStore } from "../core/Store"; export interface FragmentProps { children: unknown; } -export const Fragment = define, Store<{}>>('HUI.Fragment', { +export const Fragment = define('HUI.Fragment', { render: function frag_render(props) { return props.children; } diff --git a/src/ext/Portal.ts b/src/ext/Portal.ts index 426e50c..369dbcf 100644 --- a/src/ext/Portal.ts +++ b/src/ext/Portal.ts @@ -5,7 +5,7 @@ import { clear } from "../utils/clear"; import { HNode } from "../core/HNode"; import { FragmentProps, Fragment } from "./Fragment"; import { HUI } from "../core/HUI"; -import { Store } from "../core/Store"; +import { Store, EmptyStore } from "../core/Store"; export interface PortalProps { parent?: Node; @@ -14,10 +14,10 @@ export interface PortalProps { export interface PortalStore { p: Node; - f: HNode, Store<{}>>; + f: HNode; } -export const Portal = define, Store<{}>>('HUI.Portal', { +export const Portal = define, EmptyStore>('HUI.Portal', { init: function port_init(props, store) { store.set('p', props.parent || _document.body); diff --git a/test/src/CatchTest.tsx b/test/src/CatchTest.tsx index 9a5359a..1c885ea 100644 --- a/test/src/CatchTest.tsx +++ b/test/src/CatchTest.tsx @@ -2,13 +2,13 @@ interface ThrowerProps { msg: string; } -const Thrower = HUI.define, HUI.Store<{}>>('Thrower', { +const Thrower = HUI.define('Thrower', { render(props) { throw props.msg; } }); -const CatchTest = HUI.define<{}, HUI.Store<{}>, HUI.Store<{}>>('CatchTest', { +const CatchTest = HUI.define<{}, HUI.EmptyStore, HUI.EmptyStore>('CatchTest', { render() { return ( diff --git a/test/src/Dialog.tsx b/test/src/Dialog.tsx index bcc8009..3cdd3c4 100644 --- a/test/src/Dialog.tsx +++ b/test/src/Dialog.tsx @@ -6,7 +6,7 @@ type DialogStoreHandlers = { toggle: () => void; } -const Dialog = HUI.define<{}, HUI.Store, HUI.Store<{}>>('Dialog', { +const Dialog = HUI.define<{}, HUI.Store, HUI.EmptyStore>('Dialog', { state: ['on'], diff --git a/test/src/Greeting.tsx b/test/src/Greeting.tsx index 4b33d89..664a318 100644 --- a/test/src/Greeting.tsx +++ b/test/src/Greeting.tsx @@ -2,7 +2,7 @@ interface GreetingProps { children: string; } -const Greeting = HUI.define, TestContext>('Greeting', { +const Greeting = HUI.define('Greeting', { context: ['target'], init(props, store, context) { context.set('target', props.children[0]); @@ -43,7 +43,7 @@ const Greeting = HUI.define, TestContext>('Greeting } }); -const ShowTarget = HUI.define<{}, HUI.Store<{}>, TestContext>('ShowTarget', { +const ShowTarget = HUI.define<{}, HUI.EmptyStore, TestContext>('ShowTarget', { context: ['target'], render(props, store, context) { return `context.target: ${context.get('target')}`; @@ -55,7 +55,7 @@ interface RefTestStore { ref?: HTMLParagraphElement; } -const RefTest = HUI.define<{}, HUI.Store, HUI.Store<{}>>('RefTest', { +const RefTest = HUI.define<{}, HUI.Store, HUI.EmptyStore>('RefTest', { state: ['msg'], diff --git a/test/src/Inspector.ts b/test/src/Inspector.ts index c1d5d21..75ee6e7 100644 --- a/test/src/Inspector.ts +++ b/test/src/Inspector.ts @@ -8,7 +8,7 @@ interface InspectorProps { children: unknown; } -const Inspector = HUI.define, HUI.Store<{}>>('Inspector', { +const Inspector = HUI.define('Inspector', { render(props) { HUI.defer((self) => { diff --git a/test/src/TestInput.tsx b/test/src/TestInput.tsx index 0e93d25..48c297a 100644 --- a/test/src/TestInput.tsx +++ b/test/src/TestInput.tsx @@ -7,7 +7,7 @@ interface TestInputStore { value: string; } -const TestInput = HUI.define, HUI.Store<{}>>('TestInput', { +const TestInput = HUI.define, HUI.EmptyStore>('TestInput', { state: ['value'], diff --git a/test/src/ThrowTest.tsx b/test/src/ThrowTest.tsx index 9ebe609..dbaf611 100644 --- a/test/src/ThrowTest.tsx +++ b/test/src/ThrowTest.tsx @@ -2,7 +2,7 @@ interface ThrowTestStore { msg: string; } -const ThrowTest = HUI.define<{}, HUI.Store, HUI.Store<{}>>('ThrowTest', { +const ThrowTest = HUI.define<{}, HUI.Store, HUI.EmptyStore>('ThrowTest', { state: ['msg'], diff --git a/test/src/Timer.tsx b/test/src/Timer.tsx index 484db69..0611b6e 100644 --- a/test/src/Timer.tsx +++ b/test/src/Timer.tsx @@ -11,7 +11,7 @@ type TimerStoreHandlers = { setInterval: (interval: number) => any; } -const Timer = HUI.define, HUI.Store<{}>>('Timer', { +const Timer = HUI.define, HUI.EmptyStore>('Timer', { state: ['time'],