-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update types to use generics & add a TS test for react-redux (#80)
* Add a test for react-redux's useSelector hook * Separate react-redux test from main usage test * Fix types, use generics
- Loading branch information
Showing
5 changed files
with
795 additions
and
642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Changelog | ||
|
||
## Unreleased | ||
|
||
- [#80](https://github.com/FormidableLabs/react-fast-compare/pull/80). Update types to use generic `any`s. | ||
- [#77](https://github.com/FormidableLabs/react-fast-compare/pull/77). Add tests for our TypeScript type definitions. | ||
|
||
## 3.1.0 (2020-05-08) | ||
|
||
- [#76](https://github.com/FormidableLabs/react-fast-compare/pull/76). Add support for preact/compat. | ||
|
@@ -17,6 +22,7 @@ | |
## 3.0.0 (2020-01-05) | ||
|
||
**Features:** | ||
|
||
- [#36](https://github.com/FormidableLabs/react-fast-compare/pull/36). Update to `[email protected]` with modified support for ES.next data types: `Map`, `Set`, `ArrayBuffer`. | ||
- [#57](https://github.com/FormidableLabs/react-fast-compare/pull/57). Minor refactoring to reduce min+gz size. | ||
- [#59](https://github.com/FormidableLabs/react-fast-compare/pull/59). Rename exported to `isEqual` for TypeScript users. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
declare function isEqual(a: any, b: any): boolean; | ||
declare namespace isEqual {} | ||
declare function isEqual<A = any, B = any>(a: A, b: B): boolean; | ||
export = isEqual; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This file exists to test our types against sample user code | ||
// This is compiled using `tsc` in our `test-ts-usage` script | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Provider, useSelector } from 'react-redux'; | ||
import { createStore } from 'redux'; | ||
|
||
import equal from '../../index.js'; | ||
|
||
type IState = { | ||
items: string[]; | ||
}; | ||
|
||
type IAction = { | ||
type: string; | ||
payload: any; | ||
}; | ||
|
||
const initialState: IState = { | ||
items: [], | ||
}; | ||
|
||
const reducer = (state: IState, action: IAction) => { | ||
return state; | ||
}; | ||
|
||
const lengthSelector = (state: IState): number => state.items.length; | ||
|
||
const store = createStore(reducer, initialState); | ||
|
||
function Test() { | ||
const length = useSelector(lengthSelector, equal); | ||
return ( | ||
<div> | ||
Testing react-redux useSelector. There are | ||
{length.toExponential()} items. | ||
</div> | ||
); | ||
} | ||
|
||
ReactDOM.render( | ||
<Provider store={store}> | ||
<Test /> | ||
</Provider>, | ||
document.getElementById('root') | ||
); |
Oops, something went wrong.