, P extends R>(Component: React.ComponentType) => {
+ return (props: Optionalize
): React.ReactElement => {
+ const value = useHook(namespace);
+ const withProps = mapHookToProps(value);
+ return (
+
+ );
+ };
+ };
+ };
+}
diff --git a/src/createWithHooks.tsx b/src/createWithHooks.tsx
deleted file mode 100644
index 96c8c82..0000000
--- a/src/createWithHooks.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import React from 'react';
-import { Hooks } from './types';
-
-type Optionalize = Omit;
-
-export default function(useHooks) {
- return function withHooks<
- K extends keyof Ms,
- M extends (hooks: ReturnType) => Record
- >(namespace: K, mapHooksToProps?: M) {
- mapHooksToProps = (mapHooksToProps || ((hooks: ReturnType) => ({ [namespace]: hooks }))) as M;
- return , P extends R>(Component: React.ComponentType) => {
- return (props: Optionalize
): React.ReactElement => {
- const value = useHooks(namespace);
- const withProps = mapHooksToProps(value);
- return (
-
- );
- };
- };
- };
-}
diff --git a/src/executor.tsx b/src/executor.tsx
index 2393527..042285e 100644
--- a/src/executor.tsx
+++ b/src/executor.tsx
@@ -6,7 +6,7 @@ interface ExecutorProps {
namespace: string;
}
-export default function(props: ExecutorProps) {
+export default function (props: ExecutorProps) {
const { useValue, onUpdate, namespace } = props;
const updateRef = useRef(onUpdate);
@@ -17,7 +17,7 @@ export default function(props: ExecutorProps) {
try {
data = useValue();
} catch (e) {
- console.error(`Invoking '${namespace || 'unknown'}' hooks failed:`, e);
+ console.error(`Invoking '${namespace || 'unknown'}' hook failed:`, e);
}
useMemo(() => {
@@ -34,4 +34,4 @@ export default function(props: ExecutorProps) {
});
return null;
-};
+}
diff --git a/src/index.ts b/src/index.ts
index 7ea38dd..8945edf 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,24 +1,24 @@
import Dispatcher from './dispatcher';
import createContext from './createContext';
import createProvider from './createProvider';
-import createUseHooks from './createUseHooks';
-import createGetHooks from './createGetHooks';
-import createWithHooks from './createWithHooks';
+import createUseHook from './createUseHook';
+import createGetHook from './createGetHook';
+import createWithHook from './createWithHook';
import { Hooks } from './types';
export const createStore = function(hooks: H) {
const dispatcher = new Dispatcher();
const { context, useContext } = createContext();
const Provider = createProvider(context, dispatcher, hooks);
- const useHooks = createUseHooks(useContext);
- const getHooks = createGetHooks(dispatcher);
- const withHooks = createWithHooks(useHooks);
+ const useHook = createUseHook(useContext);
+ const getHook = createGetHook(dispatcher);
+ const withHook = createWithHook(useHook);
return {
Provider,
- useHooks,
- getHooks,
- withHooks,
+ useHook,
+ getHook,
+ withHook,
};
};
diff --git a/tsconfig.json b/tsconfig.json
index e74127e..bde0c4b 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,13 +1,15 @@
{
"compilerOptions": {
"target": "es5",
+ "module": "ES6",
+ "lib": ["es5", "dom"],
+ "moduleResolution": "node",
"jsx": "react",
"experimentalDecorators": true,
"declaration": true,
"esModuleInterop": true,
"sourceMap": true,
- "outDir": "lib",
- "lib": ["es5", "dom"]
+ "outDir": "esm",
},
"files": [
"src/index.ts"