Skip to content

Commit

Permalink
- Added typings
Browse files Browse the repository at this point in the history
  • Loading branch information
v-jaebe committed Nov 14, 2018
1 parent 282809a commit e583577
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@
},
{
"kind": "packageJSON",
"content": "{\n \"name\": \"react-hook-utils\",\n \"version\": \"1.0.2\",\n \"description\": \"\",\n \"author\": \"\",\n \"license\": \"MIT\",\n \"repository\": \"https://github.com/jacob-ebey/react-hook-utils.git\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.es.js\",\n \"jsnext:main\": \"dist/index.es.js\",\n \"engines\": {\n \"node\": \">=8\",\n \"npm\": \">=5\"\n },\n \"scripts\": {\n \"test\": \"cross-env CI=1 react-scripts test --coverage --env=jsdom\",\n \"coveralls\": \"cat ./coverage/lcov.info | coveralls\",\n \"test:watch\": \"react-scripts test --env=jsdom\",\n \"build\": \"rollup -c && esdoc\",\n \"start\": \"rollup -c -w\",\n \"prepare\": \"npm run build\",\n \"predeploy\": \"cd example && npm install && npm run build\",\n \"deploy\": \"gh-pages -d example/build\"\n },\n \"peerDependencies\": {\n \"react\": \"^16.7.0-alpha.0\",\n \"react-dom\": \"^16.7.0-alpha.0\",\n \"scheduler\": \"^0.11.0-alpha.0\"\n },\n \"devDependencies\": {\n \"@svgr/rollup\": \"^2.4.1\",\n \"babel-core\": \"^6.26.3\",\n \"babel-eslint\": \"^8.2.5\",\n \"babel-plugin-external-helpers\": \"^6.22.0\",\n \"babel-preset-env\": \"^1.7.0\",\n \"babel-preset-react\": \"^6.24.1\",\n \"babel-preset-stage-0\": \"^6.24.1\",\n \"coveralls\": \"^3.0.2\",\n \"cross-env\": \"^5.1.4\",\n \"esdoc\": \"^1.1.0\",\n \"esdoc-standard-plugin\": \"^1.0.0\",\n \"eslint\": \"^5.0.1\",\n \"eslint-config-standard\": \"^11.0.0\",\n \"eslint-config-standard-react\": \"^6.0.0\",\n \"eslint-plugin-import\": \"^2.13.0\",\n \"eslint-plugin-node\": \"^7.0.1\",\n \"eslint-plugin-promise\": \"^4.0.0\",\n \"eslint-plugin-react\": \"^7.10.0\",\n \"eslint-plugin-standard\": \"^3.1.0\",\n \"gh-pages\": \"^1.2.0\",\n \"react\": \"16.7.0-alpha.0\",\n \"react-dom\": \"16.7.0-alpha.0\",\n \"react-scripts\": \"^1.1.4\",\n \"react-testing-library\": \"^5.2.3\",\n \"rollup\": \"^0.64.1\",\n \"rollup-plugin-babel\": \"^3.0.7\",\n \"rollup-plugin-commonjs\": \"^9.1.3\",\n \"rollup-plugin-node-resolve\": \"^3.3.0\",\n \"rollup-plugin-peer-deps-external\": \"^2.2.0\",\n \"rollup-plugin-postcss\": \"^1.6.2\",\n \"rollup-plugin-url\": \"^1.4.0\",\n \"scheduler\": \"0.11.0-alpha.0\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ]\n}\n",
"content": "{\n \"name\": \"react-hook-utils\",\n \"version\": \"1.0.3\",\n \"description\": \"\",\n \"author\": \"\",\n \"license\": \"MIT\",\n \"repository\": \"https://github.com/jacob-ebey/react-hook-utils.git\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.es.js\",\n \"jsnext:main\": \"dist/index.es.js\",\n \"typings\": \"react-hooks-utils.d.ts\",\n \"engines\": {\n \"node\": \">=8\",\n \"npm\": \">=5\"\n },\n \"scripts\": {\n \"test\": \"cross-env CI=1 react-scripts test --coverage --env=jsdom\",\n \"coveralls\": \"cat ./coverage/lcov.info | coveralls\",\n \"test:watch\": \"react-scripts test --env=jsdom\",\n \"build\": \"rollup -c && esdoc\",\n \"start\": \"rollup -c -w\",\n \"prepare\": \"npm run build\",\n \"predeploy\": \"cd example && npm install && npm run build\",\n \"deploy\": \"gh-pages -d example/build\"\n },\n \"peerDependencies\": {\n \"react\": \"^16.7.0-alpha.0\",\n \"react-dom\": \"^16.7.0-alpha.0\",\n \"scheduler\": \"^0.11.0-alpha.0\"\n },\n \"devDependencies\": {\n \"@svgr/rollup\": \"^2.4.1\",\n \"babel-core\": \"^6.26.3\",\n \"babel-eslint\": \"^8.2.5\",\n \"babel-plugin-external-helpers\": \"^6.22.0\",\n \"babel-preset-env\": \"^1.7.0\",\n \"babel-preset-react\": \"^6.24.1\",\n \"babel-preset-stage-0\": \"^6.24.1\",\n \"coveralls\": \"^3.0.2\",\n \"cross-env\": \"^5.1.4\",\n \"esdoc\": \"^1.1.0\",\n \"esdoc-standard-plugin\": \"^1.0.0\",\n \"eslint\": \"^5.0.1\",\n \"eslint-config-standard\": \"^11.0.0\",\n \"eslint-config-standard-react\": \"^6.0.0\",\n \"eslint-plugin-import\": \"^2.13.0\",\n \"eslint-plugin-node\": \"^7.0.1\",\n \"eslint-plugin-promise\": \"^4.0.0\",\n \"eslint-plugin-react\": \"^7.10.0\",\n \"eslint-plugin-standard\": \"^3.1.0\",\n \"gh-pages\": \"^1.2.0\",\n \"react\": \"16.7.0-alpha.0\",\n \"react-dom\": \"16.7.0-alpha.0\",\n \"react-scripts\": \"^1.1.4\",\n \"react-testing-library\": \"^5.2.3\",\n \"rollup\": \"^0.64.1\",\n \"rollup-plugin-babel\": \"^3.0.7\",\n \"rollup-plugin-commonjs\": \"^9.1.3\",\n \"rollup-plugin-node-resolve\": \"^3.3.0\",\n \"rollup-plugin-peer-deps-external\": \"^2.2.0\",\n \"rollup-plugin-postcss\": \"^1.6.2\",\n \"rollup-plugin-url\": \"^1.4.0\",\n \"scheduler\": \"0.11.0-alpha.0\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ]\n}\n",
"longname": "C:\\Source\\react-hook-utils\\package.json",
"name": "package.json",
"static": true,
Expand Down
4 changes: 2 additions & 2 deletions docs/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
<td class="coverage"><span data-ice="coverage">42 %</span><span data-ice="coverageCount" class="coverage-count">3/7</span></td>
<td style="display: none;" data-ice="size">6697 byte</td>
<td style="display: none;" data-ice="lines">255</td>
<td style="display: none;" data-ice="updated">2018-11-04 00:19:09 (UTC)</td>
<td style="display: none;" data-ice="updated">2018-11-04 02:38:25 (UTC)</td>
</tr>
<tr data-ice="file">
<td data-ice="filePath"><span><a href="file/dist/index.js.html#errorLines=22,36,5,7,74">dist/index.js</a></span></td>
<td data-ice="identifier" class="identifiers">-</td>
<td class="coverage"><span data-ice="coverage">37 %</span><span data-ice="coverageCount" class="coverage-count">3/8</span></td>
<td style="display: none;" data-ice="size">6850 byte</td>
<td style="display: none;" data-ice="lines">261</td>
<td style="display: none;" data-ice="updated">2018-11-04 00:19:09 (UTC)</td>
<td style="display: none;" data-ice="updated">2018-11-04 02:38:25 (UTC)</td>
</tr>
</tbody>
</table>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "react-hook-utils",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"author": "",
"license": "MIT",
"repository": "https://github.com/jacob-ebey/react-hook-utils.git",
"main": "dist/index.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.es.js",
"typings": "react-hooks-utils.d.ts",
"engines": {
"node": ">=8",
"npm": ">=5"
Expand Down
58 changes: 58 additions & 0 deletions react-hook-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
declare module "react-hook-utils" {
export interface EventHandler {
(...params: any[]): void;
add(callback: (...params: any[]) => void);
remove(callback: (...params: any[]) => void);
}

/**
* Creates a new event that allows subscribers to add and remove event handlers.
* @return {function}
* @property {function(handler: function)} add Add a new event handler.
* @property {function(handler: function)} remove Remove an event handler.
*/
export function createEvent(): EventHandler;

export type ReducerFunc<TState> = (state: TState, ...rest: any[]) => TState;

export interface Reducer<TState> {
[key: string]: ReducerFunc<TState>;
}

export type ReducerInstance<TState, TReducer extends Reducer<TState>> = {
[key in keyof TReducer]: (...params: any[]) => void
};

export type ReducerSelectorFunc<TState, TResult> = (state: TState) => TResult;

export type UseReducerFunc<TState, TReducer extends Reducer<TState>> = <
TResult = TState
>(
selector?: ReducerSelectorFunc<TState, TResult>,
onComponentStateChanged?: (state: TResult) => void
) => [TResult, ReducerInstance<TState, TReducer>];

/**
* Creates a global reducer for use within any number of components. The function returned allows for a selector function to be passed to limit the re-renders of the consuming component.
*
* @param {Object} initialValue The initial value for the state.
* @param {Object} reducer The dispatch functions.
* @param {function(state: Object)} [onStateChange=undefined] onStateChange An optional callback for when the state changes. Can be used for persisting to local storage.
* @return {function(selector: function = undefined, onComponentStateChanged: function = undefined): [Object, Object]}
*/
export function globalReducer<TState, TReducer extends Reducer<TState>>(
initialState: TState,
reducer: TReducer,
onStateChange?: (state: TState) => void
): UseReducerFunc<TState, TReducer>;

/**
* Use a promise and receive [data, error, loading] values. It is strongly recommended to use in conjunction with useMemo.
*
* @param {Promise} promise The promise to use.
* @return {[Object, Error, boolean]}
*/
export function usePromise<T = any>(
promise: Promise<T>
): [T | null, Error | null, boolean];
}

0 comments on commit e583577

Please sign in to comment.