mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-27 13:34:28 -04:00
![renovate[bot]](/assets/img/avatar_default.png)
* Update dependency eslint-plugin-import to v2.25.2 Signed-off-by: Renovate Bot <bot@renovateapp.com> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> * Make type imports more explicit Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> * Enforce use of type imports Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import type { Reducer } from 'redux'
|
|
import type { HistoryActions, HistoryEntry } from './types'
|
|
import { HistoryActionType } from './types'
|
|
|
|
// Q: Why is the reducer initialized with an empty array instead of the actual history entries like in the config reducer?
|
|
// A: The history reducer will be created without entries because of async entry retrieval.
|
|
// Entries will be added after reducer initialization.
|
|
|
|
export const HistoryReducer: Reducer<HistoryEntry[], HistoryActions> = (
|
|
state: HistoryEntry[] = [],
|
|
action: HistoryActions
|
|
) => {
|
|
switch (action.type) {
|
|
case HistoryActionType.SET_ENTRIES:
|
|
return action.entries
|
|
case HistoryActionType.UPDATE_ENTRY:
|
|
return [...state.filter((entry) => entry.identifier !== action.noteId), action.newEntry]
|
|
case HistoryActionType.REMOVE_ENTRY:
|
|
return state.filter((entry) => entry.identifier !== action.noteId)
|
|
default:
|
|
return state
|
|
}
|
|
}
|