Skip to content

Commit

Permalink
Fix isAction hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Sep 7, 2024
1 parent 7fe279a commit d6ed59f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/renderer/lib/config-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { isAction } from './helpers';
export const configMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in config: ' + JSON.stringify(action)
);
}
switch (action.type) {
case 'SET_INITIAL_TOKEN':
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/lib/electron-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function scrollToTopNotification() {
export const electronMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in electron: ' + JSON.stringify(action)
);
}
switch (action.type) {
case 'OPEN_URL':
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/lib/github-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function createGitHubMiddleware(): Middleware<{}, AppReduxState> {

return (store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in github controls: ' +
JSON.stringify(action)
);
}
switch (action.type) {
case 'MARK_NOTE_READ': {
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/lib/gitnews-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ let currentDemoNotifications = createDemoNotifications();
export function createFetcher(): Middleware<{}, AppReduxState> {
const fetcher: Middleware<object, AppReduxState> =
(store) => (next) => (action) => {
if (!isAction(action) || !isDispatch(next)) {
throw new Error('Invalid action dispatched');
if (!isAction(action)) {
throw new Error(
'Invalid action dispatched in fetcher: ' + JSON.stringify(action)
);
}
if (!isDispatch(next)) {
throw new Error('Invalid dispatcher in fetcher');
}
if (action.type === 'MARK_NOTE_READ' && store.getState().isDemoMode) {
currentDemoNotifications = currentDemoNotifications.map((note) => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function getSecondsUntilNextFetch(

export function isAction(action: unknown): action is AppReduxAction {
const typedAction = action as AppReduxAction;
if (!('type' in typedAction) || !('token' in typedAction)) {
if (!('type' in typedAction)) {
return false;
}
return true;
Expand Down

0 comments on commit d6ed59f

Please sign in to comment.