Skip to content

Commit

Permalink
add EmptyStore type
Browse files Browse the repository at this point in the history
  • Loading branch information
huang2002 committed Jan 30, 2019
1 parent 222c3e7 commit 419b304
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/core/HUI.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -52,6 +52,7 @@ export namespace HUI {
export type HandlerMap<T extends object = any> = _HandlerMap<T>;
export type Setter<T = unknown> = _Setter<T>;
export type SetterRecord<T = unknown> = _SetterRecord<T>;
export type EmptyStore = _EmptyStore;

export type RenderOptions<C extends Store = Store> = _RenderOptions<C>;

Expand Down
2 changes: 2 additions & 0 deletions src/core/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type PartialHandlers<H extends HandlerMap, T> = { [K in keyof H]?: Inject
export type StoreType<S> = S extends Store<infer T> ? T : never;
export type StoreHandlers<S> = S extends Store<any, infer H> ? H : never;

export type EmptyStore = Store<{}>;

export interface Store<T extends object = any, H extends HandlerMap<T> = any> {

valueMap: MapOf<T>;
Expand Down
4 changes: 2 additions & 2 deletions src/ext/Fragment.ts
Original file line number Diff line number Diff line change
@@ -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<FragmentProps, Store<{}>, Store<{}>>('HUI.Fragment', {
export const Fragment = define<FragmentProps, EmptyStore, EmptyStore>('HUI.Fragment', {
render: function frag_render(props) {
return props.children;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ext/Portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,10 +14,10 @@ export interface PortalProps {

export interface PortalStore {
p: Node;
f: HNode<FragmentProps, Store<{}>, Store<{}>>;
f: HNode<FragmentProps, EmptyStore, EmptyStore>;
}

export const Portal = define<PortalProps, Store<PortalStore>, Store<{}>>('HUI.Portal', {
export const Portal = define<PortalProps, Store<PortalStore>, EmptyStore>('HUI.Portal', {

init: function port_init(props, store) {
store.set('p', props.parent || _document.body);
Expand Down
4 changes: 2 additions & 2 deletions test/src/CatchTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ interface ThrowerProps {
msg: string;
}

const Thrower = HUI.define<ThrowerProps, HUI.Store<{}>, HUI.Store<{}>>('Thrower', {
const Thrower = HUI.define<ThrowerProps, HUI.EmptyStore, HUI.EmptyStore>('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 (
Expand Down
2 changes: 1 addition & 1 deletion test/src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type DialogStoreHandlers = {
toggle: () => void;
}

const Dialog = HUI.define<{}, HUI.Store<DialogStore, DialogStoreHandlers>, HUI.Store<{}>>('Dialog', {
const Dialog = HUI.define<{}, HUI.Store<DialogStore, DialogStoreHandlers>, HUI.EmptyStore>('Dialog', {

state: ['on'],

Expand Down
6 changes: 3 additions & 3 deletions test/src/Greeting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interface GreetingProps {
children: string;
}

const Greeting = HUI.define<GreetingProps, HUI.Store<{}>, TestContext>('Greeting', {
const Greeting = HUI.define<GreetingProps, HUI.EmptyStore, TestContext>('Greeting', {
context: ['target'],
init(props, store, context) {
context.set('target', props.children[0]);
Expand Down Expand Up @@ -43,7 +43,7 @@ const Greeting = HUI.define<GreetingProps, HUI.Store<{}>, 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')}`;
Expand All @@ -55,7 +55,7 @@ interface RefTestStore {
ref?: HTMLParagraphElement;
}

const RefTest = HUI.define<{}, HUI.Store<RefTestStore>, HUI.Store<{}>>('RefTest', {
const RefTest = HUI.define<{}, HUI.Store<RefTestStore>, HUI.EmptyStore>('RefTest', {

state: ['msg'],

Expand Down
2 changes: 1 addition & 1 deletion test/src/Inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface InspectorProps {
children: unknown;
}

const Inspector = HUI.define<InspectorProps, HUI.Store<{}>, HUI.Store<{}>>('Inspector', {
const Inspector = HUI.define<InspectorProps, HUI.EmptyStore, HUI.EmptyStore>('Inspector', {

render(props) {
HUI.defer((self) => {
Expand Down
2 changes: 1 addition & 1 deletion test/src/TestInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface TestInputStore {
value: string;
}

const TestInput = HUI.define<TestInputProps, HUI.Store<TestInputStore>, HUI.Store<{}>>('TestInput', {
const TestInput = HUI.define<TestInputProps, HUI.Store<TestInputStore>, HUI.EmptyStore>('TestInput', {

state: ['value'],

Expand Down
2 changes: 1 addition & 1 deletion test/src/ThrowTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interface ThrowTestStore {
msg: string;
}

const ThrowTest = HUI.define<{}, HUI.Store<ThrowTestStore>, HUI.Store<{}>>('ThrowTest', {
const ThrowTest = HUI.define<{}, HUI.Store<ThrowTestStore>, HUI.EmptyStore>('ThrowTest', {

state: ['msg'],

Expand Down
2 changes: 1 addition & 1 deletion test/src/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type TimerStoreHandlers = {
setInterval: (interval: number) => any;
}

const Timer = HUI.define<TimerProps, HUI.Store<TimerStore, TimerStoreHandlers>, HUI.Store<{}>>('Timer', {
const Timer = HUI.define<TimerProps, HUI.Store<TimerStore, TimerStoreHandlers>, HUI.EmptyStore>('Timer', {

state: ['time'],

Expand Down

0 comments on commit 419b304

Please sign in to comment.