Skip to content

add TypeScript typings #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 110 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
68a4f2b
Remove Style section
timdorr Aug 15, 2016
0fb9f7f
add typings
bbenezech Nov 7, 2016
3229d73
add typings
bbenezech Nov 7, 2016
14acd15
remove separated null constrained signature
bbenezech Nov 17, 2016
c0e9c26
export `connect` from TypeScript definitions file; add tests for defi…
aikoven Nov 21, 2016
8c140e8
Reimplementing connect() and extracting connectToStore() based on 're…
jimbolla Jun 16, 2016
39ede5e
Changes to fix failing tests (4 fails to go)
jimbolla Jun 16, 2016
a00635c
Change code to make tests for factory mapStateToProps/mapDispatchToPr…
jimbolla Jun 16, 2016
779a005
Adjust remaining 2 failing tests to account for slightly different be…
jimbolla Jun 16, 2016
02627e0
add dispatchable to the exported functions
jimbolla Jun 16, 2016
b2afa40
Replace string ref with function ref. Adjust test to match
jimbolla Jun 16, 2016
e5c49b3
Generalized a couple error messages
jimbolla Jun 16, 2016
11d07fc
make additional options passed to connect() fall through to connectTo…
jimbolla Jun 16, 2016
b8c51b6
rename connectToStore to connectAdvanced
jimbolla Jun 16, 2016
8242259
pull some utility functions out of connectAdvanced into their own uti…
jimbolla Jun 16, 2016
c0a116b
refactor connect + connectAdvanced
jimbolla Jun 16, 2016
a8ee839
remove dispatchable()... this probably doesn't need to be a part of r…
jimbolla Jun 16, 2016
cd7b51f
remove unneeded selector value on unmount
jimbolla Jun 16, 2016
d960b52
avoid excess verify() when using defaultMergeProps
jimbolla Jun 17, 2016
949b718
pull buildSelector out of connectAdvanced... less function nesting
jimbolla Jun 17, 2016
da25793
refactor connect() selector builders
jimbolla Jun 17, 2016
b9cd3ee
remove need for explicit factory flags
jimbolla Jun 17, 2016
43a3210
don't do shape verification in production ENV
jimbolla Jun 17, 2016
2ee8b1f
refactor to split init from trySubscribe
jimbolla Jun 17, 2016
62b61bf
Move subscribe from willMount to didMount to avoid serverside memory …
jimbolla Jun 17, 2016
5f6cb01
Remove extra createShallowEqualSelector file since it's not adding mu…
jimbolla Jun 17, 2016
0cd31c6
move ref/recomputationsProp setters into buildSelector... simplify re…
jimbolla Jun 17, 2016
03e770d
refactor + comment advancedConnect
jimbolla Jun 17, 2016
2e60c53
pull buildSelector func into own file
jimbolla Jun 17, 2016
c4f68ab
Make buildSelector injectable into connectAdvanced as another option
jimbolla Jun 17, 2016
2e7fd5e
refactor+comment connect.js
jimbolla Jun 18, 2016
d4ca722
Change the way nested connected components subscribe so that parent c…
jimbolla Jun 18, 2016
7016e39
Fix failing tests. Change the way nested components subscribe... inst…
jimbolla Jun 18, 2016
984ff0f
ensure nested subs are notified properly
jimbolla Jun 18, 2016
1b0d3d9
Eliminate extraneous tracking of recomputations count since we can ju…
jimbolla Jun 18, 2016
0487621
simplify nested subs code. no need for extra object wrappers
jimbolla Jun 18, 2016
9a71e39
rename shouldUseState to dependsOnState to make its meaning more clear
jimbolla Jun 18, 2016
0b2062e
prebind notifyNestedSubs to avoid extra lambda func
jimbolla Jun 18, 2016
8205566
Add WrappedComponent as one of the option params passed to buildSelec…
jimbolla Jun 18, 2016
6f40444
Extract Subscription class from connectAdvanced
jimbolla Jun 19, 2016
20c8504
Replace reselect with manual memoization in buildSelector. Faster!
jimbolla Jun 19, 2016
d92e98a
refactor buildSelector
jimbolla Jun 19, 2016
57efcdb
refactor connect()... extract selectors, replace reselect with hand-r…
jimbolla Jun 20, 2016
a7b1f76
Re-add isSubscribed() to reduce test delta
jimbolla Jun 20, 2016
7f2d817
refactor buildFactoryAwareSelector and remove extraneous selector ind…
jimbolla Jun 20, 2016
5e493bb
improve memoization perf
jimbolla Jun 20, 2016
a298e82
refactor connect + selectors for clarity
jimbolla Jun 21, 2016
d0539ee
refactor connect + selectors
jimbolla Jun 23, 2016
819cad5
pull apart buildSelector into its pieces and move them into getFinalP…
jimbolla Jun 23, 2016
4ea2ccb
Move where 'extra props' (ref and recomputations) are added to the fi…
jimbolla Jun 23, 2016
b9b9ad7
Refactor props memoization
jimbolla Jun 23, 2016
c6bc5ad
Move ownProps memoization into connectAdvanced to simplify selectors.
jimbolla Jun 23, 2016
3e3a9c4
utilize memoizeProps in createFactoryAwareSelector
jimbolla Jun 23, 2016
3711d13
rename recomputations to renderCount to make its intent clearer
jimbolla Jun 24, 2016
3033c3b
refactoring selectors + connect for clarity
jimbolla Jun 24, 2016
687635e
Hide connectAdvanced and advancedOptions
jimbolla Jun 24, 2016
74b25a4
fix nits
jimbolla Jun 26, 2016
284cb0e
fix messed up path
jimbolla Jun 26, 2016
ce18ada
Add guard for the case of a component causing its siblings to unsubsc…
jimbolla Jul 2, 2016
43b2691
Add comments to connect.js
jimbolla Jul 3, 2016
198749f
refactoring + some perf opimizations
jimbolla Jul 9, 2016
6b6cfff
refactoring+comments for clarity
jimbolla Jul 9, 2016
edb8b69
refactoring
jimbolla Jul 9, 2016
48067e7
Optimize Subscription subscribe/unsubscribe
jimbolla Jul 9, 2016
22aea19
comments
jimbolla Jul 9, 2016
4fe21c0
refactor selectors
jimbolla Jul 10, 2016
d721a32
rename files
jimbolla Jul 10, 2016
e64fcf3
Change Subscription to follow same subscribe/unsubscribe/notify mecha…
jimbolla Jul 11, 2016
4ee64cb
refactoring connect's selectors to move logic to determine what to re…
jimbolla Jul 11, 2016
688c49a
refactoring/optimizing connect+selectors
jimbolla Jul 12, 2016
1467a03
refactoring/optimizing connect+selectors
jimbolla Jul 13, 2016
eca5006
Merge selectors and connect.js into a connect folder
jimbolla Jul 14, 2016
5a92d83
comments
jimbolla Jul 14, 2016
5df333f
refactoring connect
jimbolla Jul 15, 2016
377562c
Optimize connectAdvanced to not create subscription if it shouldn't r…
jimbolla Jul 16, 2016
7b16141
Refactor - put dependsOnOwnProps right on the selector func instead o…
jimbolla Jul 16, 2016
a4c983c
Add test from #293 and uncomment now-passing expect in 'should pass s…
jimbolla Jul 16, 2016
03013b5
Added passing test from #395
jimbolla Jul 16, 2016
0bfd154
Add passing test from #429
jimbolla Jul 16, 2016
278ae8f
Add code + test for #436
jimbolla Jul 16, 2016
749962a
Extract buildConnectOptions out of connect()... will make testing easier
jimbolla Jul 16, 2016
4bc5abb
Remove eslint-config-rackt.
timdorr Aug 16, 2016
c260a9b
isparta is dead. And use Codecov.
timdorr Aug 16, 2016
bdeb326
bind proper store context in connectAdvanced and the Subscription util
vhmth Aug 18, 2016
5db1d44
add store context-preservation tests
vhmth Aug 18, 2016
fdd4a82
tests and fixes #457
jimbolla Aug 24, 2016
5cb358c
refactors out count variable in Subscription.js
jimbolla Aug 24, 2016
3b60a7f
refactors subscription to be slightly clearer
jimbolla Aug 25, 2016
c00f42e
exposes new features to the API
jimbolla Aug 27, 2016
c08eb7f
Add es2015 modules export from redux project (#501)
btd Sep 27, 2016
dfa32d7
Set displayName explicitly on Provider (#506)
roncohen Sep 28, 2016
d186b1f
warn on duplicate props (#508)
ynonp Oct 2, 2016
f05828a
Update API docs for v5 (#480)
jimbolla Oct 5, 2016
92e55b8
groups factories options and move *areEqual defaults into connect (#477)
jimbolla Oct 5, 2016
774f8a1
Whoops, didn't bump the version in git...
timdorr Oct 5, 2016
0e14a05
5.0.0-beta.2
timdorr Oct 5, 2016
aa28a3f
Revert "warn on duplicate props" (#511)
timdorr Oct 5, 2016
4462a20
5.0.0-beta.3
timdorr Oct 5, 2016
5074c81
Supress eslint error "react/display-name" at intentional omission.
jimbolla Oct 11, 2016
ad7a329
Fix error from clear() called during notify() (#517)
appden Oct 14, 2016
b3352bc
add typings
bbenezech Nov 7, 2016
01d164c
remove separated null constrained signature
bbenezech Nov 17, 2016
f4670f0
export `connect` from TypeScript definitions file; add tests for defi…
aikoven Nov 21, 2016
3fc661b
Merge remote-tracking branch 'origin/next' into next
aikoven Nov 21, 2016
6a7c8a4
Enable `noImplicitAny` for TypeScript definition tests
aikoven Nov 21, 2016
f695975
Merge branch 'ts-definitions' into next
aikoven Nov 21, 2016
303b7fe
Merge pull request #1 from aikoven/next
bbenezech Dec 1, 2016
8b5baee
cleanup tests noise
bbenezech Dec 1, 2016
e1ef01e
allow only for redux Action {type: any} or Thunked dispatchable Actio…
bbenezech Dec 1, 2016
7e84751
make sure TDispatchProps drives MapDispatchToPropsObject signature
bbenezech Dec 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ node_js:
script:
- npm run lint
- npm run test:cov
- npm run test:typescript
after_success:
- npm run coverage
67 changes: 67 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ComponentClass, Component, StatelessComponent } from 'react';
import { Store, Dispatch, ActionCreator, Action } from 'redux';

interface ComponentDecorator<TOriginalProps, TOwnProps> {
(component: StatelessComponent<TOriginalProps>|ComponentClass<TOriginalProps>): ComponentClass<TOwnProps>;
}

/**
* Following 5 functions cover all possible ways connect could be invoked
*
* - State: Redux state interface (the same one used by Store<S>)
* - TOwnProps: Props passed to the wrapping component
* - TStateProps: Result of MapStateToProps
* - TDispatchProps: Result of MapDispatchToProps
*/
export function connect<State, TOwnProps>(): ComponentDecorator<{ dispatch: Dispatch<State> } & TOwnProps, TOwnProps>;

export function connect<State, TOwnProps, TStateProps>(
mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>>,
): ComponentDecorator<TStateProps & { dispatch: Dispatch<State> } & TOwnProps, TOwnProps>;

export function connect<State, TOwnProps, TStateProps, TDispatchProps>(
mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>> | null,
mapDispatchToProps: FuncOrSelf<MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> | MapDispatchToPropsObject & TDispatchProps>
): ComponentDecorator<TStateProps & TDispatchProps & TOwnProps, TOwnProps>;

export function connect<State, TOwnProps, TStateProps, TDispatchProps, TMergeProps>(
mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>> | null,
mapDispatchToProps: FuncOrSelf<MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> | MapDispatchToPropsObject & TDispatchProps>|null,
mergeProps: MergeProps<TOwnProps, TStateProps, TDispatchProps, TMergeProps> | null,
options?: Options
): ComponentDecorator<TMergeProps, TOwnProps>;

interface MapDispatchToPropsObject {
[name: string]: ActionCreator<Action> | ThunkedActionCreator;
}

type ThunkedActionCreator = (...args: any[]) => (dispatch: Dispatch<any>) => void

interface MapStateToProps<State, TOwnProps, TStateProps> {
(state: State, ownProps: TOwnProps): TStateProps;
}

interface MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> {
(dispatch: Dispatch<State>, ownProps: TOwnProps): TDispatchProps;
}

interface MergeProps<TOwnProps, TStateProps, TDispatchProps, TMergeProps> {
(stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TMergeProps;
}

interface Options {
pure?: boolean;
withRef?: boolean;
}

type FuncOrSelf<T> = T | (() => T);

/**
* Typescript does not support generic components in tsx yet in an intuïtive way which is the reason we avoid a
* generic parameter in Store here by using any as the type
*/
export interface ProviderProps {
store: Store<any>;
}

export class Provider extends Component<ProviderProps, {}> { }
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"typings": "./index.d.ts",
"scripts": {
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
Expand All @@ -17,6 +18,7 @@
"test": "cross-env BABEL_ENV=commonjs NODE_ENV=test mocha --compilers js:babel-register --recursive --require ./test/setup.js",
"test:watch": "npm test -- --watch",
"test:cov": "cross-env NODE_ENV=test nyc npm test",
"test:typescript": "typings-tester --dir test/typescript",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
},
"repository": {
Expand All @@ -27,7 +29,8 @@
"dist",
"lib",
"src",
"es"
"es",
"index.d.ts"
],
"keywords": [
"react",
Expand All @@ -47,6 +50,7 @@
},
"homepage": "https://github.com/gaearon/react-redux",
"devDependencies": {
"@types/react": "^0.14.49",
"babel-cli": "^6.3.17",
"babel-core": "^6.3.26",
"babel-eslint": "^6.1.2",
Expand Down Expand Up @@ -93,6 +97,8 @@
"react-dom": "^0.14.0",
"redux": "^3.0.0",
"rimraf": "^2.3.4",
"typescript": "^2.0.10",
"typings-tester": "^0.2.0",
"webpack": "^1.11.0"
},
"dependencies": {
Expand Down
Loading