Skip to content

Commit

Permalink
Merge pull request #284 from fleur-js/fix-breaking-change-in-use-store
Browse files Browse the repository at this point in the history
Accept null in `useStore(_, <here>)` for prevent to v3.2.0 likes update behaviour
  • Loading branch information
hanakla authored Aug 21, 2020
2 parents 2c5bb82 + 9e66752 commit 6deffe4
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/di/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"jest": "25.1.0",
"ts-jest": "25.2.1",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"sideEffects": false
}
2 changes: 1 addition & 1 deletion packages/fleur/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"tslib": "1.11.1",
"tslint": "6.1.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"dependencies": {
"immer": "^5.0.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/fleur/src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export function actions<T extends ActionMap>(
value: `${namePrefix}${separator}${key}`,
})
} else {
actions(`${namePrefix}${separator}${key}`, actionMap[key], '.')
actions(
`${namePrefix}${separator}${key}`,
actionMap[key] as ActionMap,
'.',
)
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@types/serialize-javascript": "1.5.0",
"next": "^9.5.2",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"peerDependencies": {
"next": "^9.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"rollup-plugin-typescript2": "0.25.2",
"ts-jest": "25.2.1",
"tslib": "1.11.1",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"sideEffects": false
}
4 changes: 2 additions & 2 deletions packages/react/src/connectToStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { WithRef } from './WithRef'
type StoreToPropMapper<P, T> = (getStore: StoreGetter, props: P) => T

type ConnectedComponent<Props, MappedProps> = React.ComponentType<
WithRef<Pick<Props, Exclude<keyof Props, keyof MappedProps>>>
Pick<Props, Exclude<keyof Props, keyof MappedProps>> & {}
>

export const connectToStores = <Props, MappedProps = {}>(
mapStoresToProps: StoreToPropMapper<Props, MappedProps>,
) => <ComponentProps extends object>(
Component: React.ComponentType<ComponentProps>,
): ConnectedComponent<ComponentProps, MappedProps> => {
): ConnectedComponent<WithRef<ComponentProps>, MappedProps> => {
return React.forwardRef((props: any, ref) => {
const mappedProps = useStore(getStore => mapStoresToProps(getStore, props))

Expand Down
12 changes: 7 additions & 5 deletions packages/react/src/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ const isEqual = (prev: any, next: any) => {

export const useStore = <Mapper extends StoreToPropMapper>(
mapStoresToProps: Mapper,
checkEquality: (
prev: Readonly<ReturnType<Mapper>>,
next: Readonly<ReturnType<Mapper>>,
) => boolean = isEqual,
checkEquality:
| ((
prev: Readonly<ReturnType<Mapper>>,
next: Readonly<ReturnType<Mapper>>,
) => boolean)
| null = isEqual,
): ReturnType<Mapper> => {
const {
context: { getStore },
Expand Down Expand Up @@ -108,7 +110,7 @@ export const useStore = <Mapper extends StoreToPropMapper>(

const handleStoreMutation = useCallback(() => {
const nextState = mapStoresToProps(getStoreInspector)
if (checkEquality(latestState.current!, nextState)) return
if (checkEquality?.(latestState.current!, nextState)) return
latestState.current = nextState
rerender()
}, [mapStoresToProps, getStoreInspector])
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/withFleurContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ExcludeContextProp<P extends ContextProp> = Pick<

export const withFleurContext = <Props extends ContextProp>(
Component: React.ComponentType<Props>,
): React.ComponentType<WithRef<ExcludeContextProp<Props>>> => {
): React.ComponentType<ExcludeContextProp<WithRef<Props>>> => {
return React.forwardRef((props: any, ref) => {
const { getStore, executeOperation, depend } = useFleurContext()

Expand Down
2 changes: 1 addition & 1 deletion packages/route-store-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jest": "25.1.0",
"react-test-renderer": "16.13.1",
"ts-jest": "25.2.1",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"sideEffects": false
}
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@testing-library/react": "9.4.1",
"jest": "25.1.0",
"ts-jest": "25.2.1",
"typescript": "3.7.4"
"typescript": "3.9.7"
},
"dependencies": {
"immer": "^5.0.0"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10859,6 +10859,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==

[email protected]:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

unicode-canonical-property-names-ecmascript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"
Expand Down

0 comments on commit 6deffe4

Please sign in to comment.