From e92e5a9df6b08f0fde700f86df28236f068100d7 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Tue, 19 Dec 2017 11:17:35 +0000 Subject: [PATCH 1/5] Allow store props to override parent props --- src/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 392e76c..4d77fcf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -110,9 +110,9 @@ export function withSetProps< const storeProps = props[id]; return { - ...storeProps, // TODO: Remove casts when TS supports destructing extended types - ...parentProps as any + ...parentProps as any, + ...storeProps, }; }); From 181931c311bee5270855ff68533a95ca4af480f8 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Tue, 19 Dec 2017 11:17:44 +0000 Subject: [PATCH 2/5] Increment minor version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bc44ba..7c92df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dabapps/react-set-props", - "version": "1.0.0", + "version": "1.1.0", "description": "Store arbitrary state in redux with a similar API to setState", "main": "dist/index.js", "types": "dist/index.d.ts", From f0bcae46a649655d6647293563d55fb15b63f429 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Tue, 19 Dec 2017 11:19:11 +0000 Subject: [PATCH 3/5] Rename types --- src/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 4d77fcf..2bec273 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,7 +7,7 @@ const SET_PROPS = 'SET_PROPS'; const CLEAR_PROPS = 'CLEAR_PROPS'; const SET_PROPS_SECRET_KEY = 'SET_PROPS_SECRET_KEY'; -type Component

= React.ComponentClass

| React.StatelessComponent

; +type ComponentType

= React.ComponentClass

| React.StatelessComponent

; export interface StringKeyedObject { [index: string]: any; @@ -94,7 +94,7 @@ export function setPropsReducer( export function withSetProps< Props extends StringKeyedObject, - ExternalProps extends StringKeyedObject = StringKeyedObject + OwnProps extends StringKeyedObject = StringKeyedObject >(getInitialProps: (props: StringKeyedObject) => Props) { const unconnected = (id: string) => @@ -116,21 +116,21 @@ export function withSetProps< }; }); - return (Component: Component & ExternalProps>) => { + return (Component: ComponentType & OwnProps>) => { return connect( - (state, props: ExternalProps): ExternalProps => props, + (state, props: OwnProps): OwnProps => props, { __setProps: setPropsAction, __clearProps: clearPropsAction } ) ( - class SetPropsWrapper extends React.PureComponent & ExternalProps, void> { + class SetPropsWrapper extends React.PureComponent & OwnProps, void> { private __id: string; // tslint:disable-line:variable-name - private Connected: Component>; + private Connected: ComponentType>; public constructor( - inputProps: InternalSetPropsInterface & ExternalProps + inputProps: InternalSetPropsInterface & OwnProps ) { super(inputProps); From 3f905a3d7e7c29bfd19271b69e06a8617d8bc2f4 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Tue, 19 Dec 2017 11:26:20 +0000 Subject: [PATCH 4/5] Update tslint and config --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7c92df8..e18a80f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "prepublish": "npm test && npm run dist", "dist": "rm -rf dist/ && mkdir -p dist/ && tsc --project src/tsconfig.json", "tests": "jest", - "lint": "tslint --project tsconfig.json --type-check '{ts,tests,src}/**/*.{ts,tsx}'", + "lint": "tslint --project tsconfig.json '{ts,tests,src}/**/*.{ts,tsx}'", "test": "npm run lint && npm run tests -- --coverage" }, "repository": { @@ -53,8 +53,8 @@ "react-dom": "15.5.4", "react-test-renderer": "15.5.4", "ts-jest": "20.0.3", - "tslint": "5.1.0", - "tslint-config-dabapps": "github:dabapps/tslint-config-dabapps" + "tslint": "5.8.0", + "tslint-config-dabapps": "github:dabapps/tslint-config-dabapps#v0.4.0" }, "peerDependencies": { "react": ">= 15", From e4ffc5c73ddced39baed4d0452e5887229e9f54f Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Tue, 19 Dec 2017 11:28:32 +0000 Subject: [PATCH 5/5] Fix linting --- src/index.tsx | 8 ++++---- tests/index.tsx | 41 +++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 2bec273..076c5c1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -57,7 +57,7 @@ export function clearPropsAction(id: string) { return { type: CLEAR_PROPS, payload: { - id + id, }, }; } @@ -76,7 +76,7 @@ export function setPropsReducer( ...previous, ...action.payload.props, }, - __secretKey: SET_PROPS_SECRET_KEY + __secretKey: SET_PROPS_SECRET_KEY, }; case CLEAR_PROPS: const clearedState = {...state}; @@ -85,7 +85,7 @@ export function setPropsReducer( return { ...clearedState, - __secretKey: SET_PROPS_SECRET_KEY + __secretKey: SET_PROPS_SECRET_KEY, }; default: return state; @@ -121,7 +121,7 @@ export function withSetProps< (state, props: OwnProps): OwnProps => props, { __setProps: setPropsAction, - __clearProps: clearPropsAction + __clearProps: clearPropsAction, } ) ( diff --git a/tests/index.tsx b/tests/index.tsx index d3102f2..7af02b7 100644 --- a/tests/index.tsx +++ b/tests/index.tsx @@ -8,7 +8,7 @@ import { setPropsAction, SetPropsInterface, setPropsReducer, - withSetProps + withSetProps, } from '../src/'; describe('Set Props', () => { @@ -27,6 +27,7 @@ describe('Set Props', () => { return (

Count: {count} + {/* tslint:disable-next-line:jsx-no-lambda */} @@ -35,7 +36,7 @@ describe('Set Props', () => { }; const getInitialProps = () => ({ - count: 0 + count: 0, }); const SetPropsCounter = withSetProps(getInitialProps)(Counter); @@ -84,8 +85,8 @@ describe('Set Props', () => { expect(testStore.getState()).toEqual({ setPropsReducer: { - __secretKey: 'SET_PROPS_SECRET_KEY' - } + __secretKey: 'SET_PROPS_SECRET_KEY', + }, }); expect(Object.keys((testStore.getState() as any).setPropsReducer).length).toEqual(1); @@ -115,8 +116,8 @@ describe('Set Props', () => { expect(testStore.getState()).toEqual({ setPropsReducer: { - __secretKey: 'SET_PROPS_SECRET_KEY' - } + __secretKey: 'SET_PROPS_SECRET_KEY', + }, }); expect(Object.keys((testStore.getState() as any).setPropsReducer).length).toEqual(1); @@ -133,8 +134,8 @@ describe('Set Props', () => { expect(testStore.getState()).toEqual({ setPropsReducer: { - __secretKey: 'SET_PROPS_SECRET_KEY' - } + __secretKey: 'SET_PROPS_SECRET_KEY', + }, }); const props = (testStore.getState() as any).setPropsReducer; @@ -165,7 +166,7 @@ describe('Set Props', () => { state = setPropsReducer(undefined, {type: 'Unknown'} as any); expect(state).toEqual({ - __secretKey: 'SET_PROPS_SECRET_KEY' + __secretKey: 'SET_PROPS_SECRET_KEY', }); }); @@ -175,8 +176,8 @@ describe('Set Props', () => { expect(state).toEqual({ __secretKey: 'SET_PROPS_SECRET_KEY', id: { - foo: 'bar' - } + foo: 'bar', + }, }); state = setPropsReducer(state, setPropsAction('id2', {foo: 'bar'})); @@ -184,11 +185,11 @@ describe('Set Props', () => { expect(state).toEqual({ __secretKey: 'SET_PROPS_SECRET_KEY', id: { - foo: 'bar' + foo: 'bar', }, id2: { - foo: 'bar' - } + foo: 'bar', + }, }); }); @@ -199,11 +200,11 @@ describe('Set Props', () => { __secretKey: 'SET_PROPS_SECRET_KEY', id: { foo: undefined, - baz: 'foo' + baz: 'foo', }, id2: { - foo: 'bar' - } + foo: 'bar', + }, }); }); @@ -213,14 +214,14 @@ describe('Set Props', () => { expect(state).toEqual({ __secretKey: 'SET_PROPS_SECRET_KEY', id2: { - foo: 'bar' - } + foo: 'bar', + }, }); state = setPropsReducer(state, clearPropsAction('id2')); expect(state).toEqual({ - __secretKey: 'SET_PROPS_SECRET_KEY' + __secretKey: 'SET_PROPS_SECRET_KEY', }); });