Skip to content
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

Bump the redux group with 3 updates #6003

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"postcss": "^8.0.3",
"preact": "^10.4.0",
"prettier": "3.1.1",
"redux": "^4.0.1",
"redux-thunk": "^2.1.0",
"reselect": "^4.0.0",
"redux": "^5.0.0",
"redux-thunk": "^3.1.0",
"reselect": "^5.0.1",
"retry": "^0.13.1",
"rollup": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar/store/create-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global process */
import * as redux from 'redux';
import thunk from 'redux-thunk';
import { thunk } from 'redux-thunk';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the thunk named export now has the right types and redux-thunk/extend-redux is no longer needed (in fact it is no longer included)


import { immutable } from '../util/immutable';
import type { OmitFirstArg, TupleToIntersection } from './type-utils';
Expand Down
7 changes: 5 additions & 2 deletions src/sidebar/store/modules/drafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The drafts store provides temporary storage for unsaved edits to new or
* existing annotations.
*/
import type { Dispatch } from 'redux';
import type { ThunkDispatch } from 'redux-thunk';
import { createSelector } from 'reselect';

import type { Annotation } from '../../../types/api';
Expand Down Expand Up @@ -105,7 +105,10 @@ function createDraft(annotation: AnnotationID, changes: DraftChanges) {
* An empty draft has no text and no reference tags.
*/
function deleteNewAndEmptyDrafts() {
return (dispatch: Dispatch, getState: () => { drafts: State }) => {
return (
dispatch: ThunkDispatch<{ drafts: State }, void, any>,
Copy link
Contributor

@acelaya acelaya Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The any at the end represents the actions that dispatch can be called with. It's either a regular action, or the return type of an async thunk callback. In this case we need both.

I could not define an action type that didn't make one of the dispatch(...) calls trigger a type error, so I defined it as ´any´ for now, but we might want to revisit this.

For references, this is ThunkDispatch type definition and docs:

/**
 * The dispatch method as modified by React-Thunk; overloaded so that you can
 * dispatch:
 *   - standard (object) actions: `dispatch()` returns the action itself
 *   - thunk actions: `dispatch()` returns the thunk's return value
 *
 * @template State The redux state
 * @template ExtraThunkArg The extra argument passed to the inner function of
 * thunks (if specified when setting up the Thunk middleware)
 * @template BasicAction The (non-thunk) actions that can be dispatched.
 */
interface ThunkDispatch<State, ExtraThunkArg, BasicAction extends Action> {
    /** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */
    <ReturnType>(thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): ReturnType;
    /** Accepts a standard action object, and returns that action object */
    <Action extends BasicAction>(action: Action): Action;
    /** A union of the other two overloads for TS inference purposes */
    <ReturnType, Action extends BasicAction>(action: Action | ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): Action | ReturnType;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is pragmatic for now.

getState: () => { drafts: State },
) => {
const newDrafts = getState().drafts.drafts.filter(draft => {
return (
!draft.annotation.id &&
Expand Down
21 changes: 15 additions & 6 deletions src/sidebar/store/modules/frames.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
createSelector,
createSelectorCreator,
defaultMemoize,
} from 'reselect';
import { createSelector, createSelectorCreator, lruMemoize } from 'reselect';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultMemoize has been renamed to lruMemoize, as it's no longer the default: https://github.com/reduxjs/reselect/releases/tag/v5.0.1

import shallowEqual from 'shallowequal';

import type {
Expand Down Expand Up @@ -197,7 +193,7 @@ function searchUrisForFrame(frame: Frame): string[] {

// "selector creator" that uses `shallowEqual` instead of `===` for memoization
const createShallowEqualSelector = createSelectorCreator(
defaultMemoize,
lruMemoize,
shallowEqual,
);

Expand All @@ -212,6 +208,19 @@ const searchUris = createShallowEqualSelector(
[],
),
uris => uris,
{
// This selector does the actual work in its "input" functions and then
// relies on Reselect not to call the identity result function if the
// result of the input function is value-equal to the previous result.
//
// This is not really how Reselect is supposed to be used, but it works.
//
// What we want to achieve is that the output doesn't change if the result
// is value-equal to the previous result (ie. the `state.frames` might
// have changed, but if the search URL array produced from them hasn't
// changed, the output reference should stay the same).
devModeChecks: { identityFunctionCheck: 'never' },
},
);

function getContentInfo(state: State) {
Expand Down
5 changes: 3 additions & 2 deletions src/sidebar/store/modules/real-time-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ function pendingDeletions(state: State) {
* Return a total count of pending updates and deletions.
*/
const pendingUpdateCount = createSelector(
(state: State) => [state.pendingUpdates, state.pendingDeletions],
([pendingUpdates, pendingDeletions]) =>
(state: State) => state.pendingUpdates,
(state: State) => state.pendingDeletions,
(pendingUpdates, pendingDeletions) =>
Object.keys(pendingUpdates).length + Object.keys(pendingDeletions).length,
);

Expand Down
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// Prevent automatic inclusion of global variables defined in `@types/<name>` packages.
// This prevents eg. Node globals from `@types/node` being included when writing
// code for the browser.
"types": ["redux-thunk/extend-redux"]
"types": []
},
"include": ["**/*.js", "**/*.ts", "**/*.tsx", "types/*.d.ts"],
"exclude": [
Expand Down
36 changes: 17 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.9.2":
"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.8.4":
version: 7.20.7
resolution: "@babel/runtime@npm:7.20.7"
dependencies:
Expand Down Expand Up @@ -7816,9 +7816,9 @@ __metadata:
postcss: ^8.0.3
preact: ^10.4.0
prettier: 3.1.1
redux: ^4.0.1
redux-thunk: ^2.1.0
reselect: ^4.0.0
redux: ^5.0.0
redux-thunk: ^3.1.0
reselect: ^5.0.1
retry: ^0.13.1
rollup: ^4.0.2
rollup-plugin-string: ^3.0.0
Expand Down Expand Up @@ -11477,21 +11477,19 @@ __metadata:
languageName: node
linkType: hard

"redux-thunk@npm:^2.1.0":
version: 2.4.2
resolution: "redux-thunk@npm:2.4.2"
"redux-thunk@npm:^3.1.0":
version: 3.1.0
resolution: "redux-thunk@npm:3.1.0"
peerDependencies:
redux: ^4
checksum: c7f757f6c383b8ec26152c113e20087818d18ed3edf438aaad43539e9a6b77b427ade755c9595c4a163b6ad3063adf3497e5fe6a36c68884eb1f1cfb6f049a5c
redux: ^5.0.0
checksum: bea96f8233975aad4c9f24ca1ffd08ac7ec91eaefc26e7ba9935544dc55d7f09ba2aa726676dab53dc79d0c91e8071f9729cddfea927f4c41839757d2ade0f50
languageName: node
linkType: hard

"redux@npm:^4.0.1":
version: 4.2.1
resolution: "redux@npm:4.2.1"
dependencies:
"@babel/runtime": ^7.9.2
checksum: f63b9060c3a1d930ae775252bb6e579b42415aee7a23c4114e21a0b4ba7ec12f0ec76936c00f546893f06e139819f0e2855e0d55ebfce34ca9c026241a6950dd
"redux@npm:^5.0.0":
version: 5.0.0
resolution: "redux@npm:5.0.0"
checksum: be49160d4bd01e10108c425ade999f1b456204895c4bdd0c7825ab09efffded51955c5c242847406a7b3f273e9011a9c102848c512a099a75617b97b13d2cca8
languageName: node
linkType: hard

Expand Down Expand Up @@ -11752,10 +11750,10 @@ __metadata:
languageName: node
linkType: hard

"reselect@npm:^4.0.0":
version: 4.1.8
resolution: "reselect@npm:4.1.8"
checksum: a4ac87cedab198769a29be92bc221c32da76cfdad6911eda67b4d3e7136dca86208c3b210e31632eae31ebd2cded18596f0dd230d3ccc9e978df22f233b5583e
"reselect@npm:^5.0.1":
version: 5.0.1
resolution: "reselect@npm:5.0.1"
checksum: 7663b4c28a0e908e74dc25262e1d813d028b9c2ee96160cb0f40a16f09c5ac632fa16af6bafede7eb0ff16ab2d5bea2cd8814d9a9488e0262b8317fef90b1dc0
languageName: node
linkType: hard

Expand Down