-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add redirect to main page on login
- Loading branch information
Showing
5 changed files
with
40 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import type { Action, State } from './reducer.ts'; | ||
import type { ReduxStore } from './types'; | ||
import type { UserInterface } from '../types/interfaces.ts'; | ||
import type { State } from './reducer.ts'; | ||
|
||
function observeStore<T>( | ||
store: ReduxStore<State, Action>, | ||
select: (state: State) => T, | ||
onChange: (selectedState: T) => void, | ||
): VoidFunction { | ||
let currentState = select(store.getState()); | ||
import getStore from './Store.ts'; | ||
|
||
function observeStore<T>(select: (state: State) => T, onChange: (selectedState: T) => void): VoidFunction { | ||
let currentState = select(getStore().getState()); | ||
|
||
function handleChange(): void { | ||
const nextState = select(store.getState()); | ||
const nextState = select(getStore().getState()); | ||
if (nextState !== currentState) { | ||
currentState = nextState; | ||
onChange(currentState); | ||
} | ||
} | ||
|
||
const unsubscribe = store.subscribe(handleChange); | ||
const unsubscribe = getStore().subscribe(handleChange); | ||
return unsubscribe; | ||
} | ||
|
||
export const selectCurrentUser = (state: State): UserInterface | null => state.currentUser; | ||
|
||
export default observeStore; |
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