From 20355d2076c580077d9ff1983846897da6b8b389 Mon Sep 17 00:00:00 2001 From: Chen Junda Date: Thu, 28 Feb 2019 14:28:33 +0800 Subject: [PATCH] fix: export WithStoresProps --- README.md | 10 +++++++--- package.json | 12 ++++++------ src/index.ts | 4 ++-- src/withStores.tsx | 6 ++++-- tests/hoc.spec.tsx | 8 ++++++-- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6087c21..5894a6b 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ function CounterWithHook() { function ComponentWithRenderProps() { return ( - {({ useStore }) => { // inject only `useStore` with the same signature and usage as above + {({ useStore }: ConsumerActions) => { // inject a ConsumerActions object. Explicitly specifying type is not required. const store = useStore(TestStore); return ( @@ -75,7 +75,11 @@ function ComponentWithRenderProps() { } // 3.2 Use HOC -const ComponentWithHOC = withStores(({ useStore }) => ( + +// extends WithStoresProps to get `useStore` function +interface Props extends WithStoresProps { } + +const ComponentWithHOC = withStores(({ useStore }: Props) => ( {useStore(TestStore).state.value} )); @@ -205,7 +209,7 @@ class BStore extends Store<{ text: string; derived: string; }> { - [X] Add test - [X] Achieve high test coverage - [X] Implement `setState` promise resolve after component update for hook use -- [ ] [Partial observer](https://github.com/viccrubs/simstate/blob/partial-observer/partial-observer-proposal.md) +- [X] [Partial observer](https://github.com/viccrubs/simstate/blob/partial-observer/partial-observer-proposal.md) - [ ] SSR utilities and its example # Related Articles diff --git a/package.json b/package.json index b6d613f..28e46dd 100644 --- a/package.json +++ b/package.json @@ -30,18 +30,18 @@ "tslib": "^1.9.3" }, "peerDependencies": { - "react": ">=16.8.0" + "react": ">=16.8.3" }, "devDependencies": { "@types/enzyme": "^3.9.0", - "@types/jest": "^24.0.6", - "@types/react": ">=16.8.0", + "@types/jest": "^24.0.9", + "@types/react": ">=16.8.5", "coveralls": "^3.0.3", "cross-env": "^5.2.0", "enzyme": "^3.9.0", - "enzyme-adapter-react-16": "^1.9.1", + "enzyme-adapter-react-16": "^1.10.0", "jest": "^24.1.0", - "react": ">=16.8.0", + "react": ">=16.8.3", "react-dom": "^16.8.3", "rimraf": "^2.6.3", "rollup": "latest", @@ -50,7 +50,7 @@ "rollup-plugin-serve": "latest", "rollup-plugin-typescript2": "latest", "rollup-watch": "latest", - "standard-version": "^5.0.0", + "standard-version": "^5.0.1", "ts-jest": "^24.0.0", "tslint": "latest", "tslint-react": "^3.6.0", diff --git a/src/index.ts b/src/index.ts index 9bc56e9..1364d3c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,5 +13,5 @@ export { useStores }; import StoreConsumer, { ConsumerActions } from "./StoreConsumer"; export { StoreConsumer, ConsumerActions }; -import withStores from "./withStores"; -export { withStores }; +import withStores, { WithStoresProps } from "./withStores"; +export { withStores, WithStoresProps }; diff --git a/src/withStores.tsx b/src/withStores.tsx index 8f3f70c..7ae7e24 100644 --- a/src/withStores.tsx +++ b/src/withStores.tsx @@ -2,12 +2,14 @@ import React from "react"; import StoreConsumer, { ConsumerActions } from "./StoreConsumer"; import { Omit } from "./types"; +export type WithStoresProps = ConsumerActions; + /** * Higher-Order component usage * @param WrappedComponent */ export default function withStores -

(WrappedComponent: React.ComponentType

) { +

(WrappedComponent: React.ComponentType

) { const Component = (props: P) => ( {(actions) => { @@ -21,5 +23,5 @@ export default function withStores ); - return Component as unknown as React.ComponentType>; + return Component as unknown as React.ComponentType>; } diff --git a/tests/hoc.spec.tsx b/tests/hoc.spec.tsx index 8e83b05..f8c99ce 100644 --- a/tests/hoc.spec.tsx +++ b/tests/hoc.spec.tsx @@ -1,12 +1,16 @@ import { TestStore } from "./common"; import React from "react"; import { mount } from "enzyme"; -import withStores from "../src/withStores"; +import withStores, { WithStoresProps } from "../src/withStores"; import StoreProvider from "../src/StoreProvider"; +interface Props extends WithStoresProps { + +} + describe("HOC", () => { - const Component = withStores(({ useStore }) => { + const Component = withStores(({ useStore }: Props) => { const store = useStore(TestStore); return ( {store.state.value}