-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tobicrain
committed
Oct 17, 2022
1 parent
1be821c
commit f6483df
Showing
11 changed files
with
31 additions
and
219 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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
import * as recordsAction from './records'; | ||
import * as subscriptionsAction from './subscriptions'; | ||
import * as authAction from './auth'; | ||
|
||
export { recordsAction, subscriptionsAction, authAction }; | ||
export { recordsAction, subscriptionsAction }; |
This file was deleted.
Oops, something went wrong.
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,16 +1,10 @@ | ||
import { combineReducers } from 'redux'; | ||
import { records } from './records'; | ||
import { subscriptions } from './subscriptions'; | ||
import { auth } from './auth'; | ||
|
||
export const appReducer = combineReducers({ | ||
records: records, | ||
subscriptions: subscriptions, | ||
auth: auth, | ||
records, | ||
subscriptions, | ||
}); | ||
|
||
interface AppReducer { | ||
records: ReturnType<typeof appReducer>; | ||
} | ||
|
||
export type State = AppReducer; | ||
export type State = ReturnType<typeof appReducer>; |
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,46 +1,29 @@ | ||
import * as ReduxType from '../types'; | ||
|
||
export interface ReduxSubscriptions { | ||
subscriptions: string[]; | ||
} | ||
|
||
export type SubscriptionAction = { | ||
type: ReduxType.SubscriptionsTypes; | ||
payload: string | string[]; | ||
}; | ||
|
||
function appendSubscription(subscription: string, subscriptions: string[]): string[] { | ||
return [...subscriptions, subscription]; | ||
return subscriptions.includes(subscription) ? subscriptions : [...subscriptions, subscription]; | ||
} | ||
|
||
function deleteSubscription(subscription: string, subscriptions: string[]): string[] { | ||
return subscriptions.filter((sub) => sub !== subscription); | ||
} | ||
|
||
export const subscriptions = ( | ||
state: ReduxSubscriptions = { | ||
subscriptions: [], | ||
}, | ||
action: SubscriptionAction | ||
) => { | ||
const list = state.subscriptions; | ||
|
||
export const subscriptions = (state: string[] = [], action: SubscriptionAction) => { | ||
switch (action.type) { | ||
case ReduxType.SET_SUBSCRIPTIONS: | ||
if (Array.isArray(action.payload)) { | ||
return { | ||
subscriptions: action.payload, | ||
}; | ||
return action.payload as string[]; | ||
} | ||
case ReduxType.ADD_SUBSCRIPTION: | ||
return { | ||
subscriptions: appendSubscription(action.payload as string, list), | ||
}; | ||
return appendSubscription(action.payload as string, state) as string[]; | ||
case ReduxType.DELETE_SUBSCRIPTION: | ||
return { | ||
subscriptions: deleteSubscription(action.payload as string, list), | ||
}; | ||
return deleteSubscription(action.payload as string, state) as string[]; | ||
default: | ||
return state; | ||
return state as string[]; | ||
} | ||
}; |
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