nicolium: remove unused code
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -2,15 +2,9 @@ import { create, type Immutable, type Draft } from 'mutative';
|
||||
|
||||
import { ENTITIES_IMPORT, ENTITIES_TRANSACTION, type EntityAction } from './actions';
|
||||
import { Entities } from './entities';
|
||||
import { createCache, createList, updateStore, updateList } from './utils';
|
||||
import { createCache, updateStore } from './utils';
|
||||
|
||||
import type {
|
||||
EntitiesTransaction,
|
||||
Entity,
|
||||
EntityCache,
|
||||
EntityListState,
|
||||
ImportPosition,
|
||||
} from './types';
|
||||
import type { EntitiesTransaction, Entity, EntityCache } from './types';
|
||||
|
||||
/** Entity reducer state. */
|
||||
type State = Immutable<{
|
||||
@ -18,34 +12,10 @@ type State = Immutable<{
|
||||
}>;
|
||||
|
||||
/** Import entities into the cache. */
|
||||
const importEntities = (
|
||||
draft: Draft<State>,
|
||||
entityType: Entities,
|
||||
entities: Entity[],
|
||||
listKey?: string,
|
||||
pos?: ImportPosition,
|
||||
newState?: EntityListState,
|
||||
overwrite = false,
|
||||
) => {
|
||||
const importEntities = (draft: Draft<State>, entityType: Entities, entities: Entity[]) => {
|
||||
const cache = draft[entityType] ?? createCache();
|
||||
cache.store = updateStore(cache.store, entities);
|
||||
|
||||
if (typeof listKey === 'string') {
|
||||
let list = cache.lists[listKey] ?? createList();
|
||||
|
||||
if (overwrite) {
|
||||
list.ids = new Set();
|
||||
}
|
||||
|
||||
list = updateList(list, entities, pos);
|
||||
|
||||
if (newState) {
|
||||
list.state = newState;
|
||||
}
|
||||
|
||||
cache.lists[listKey] = list;
|
||||
}
|
||||
|
||||
draft[entityType] = cache;
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import type { PaginatedResponse } from 'pl-api';
|
||||
|
||||
/** A Mastodon API entity. */
|
||||
interface Entity {
|
||||
/** Unique ID for the entity (usually the primary key in the database). */
|
||||
@ -11,36 +9,10 @@ interface EntityStore<TEntity extends Entity = Entity> {
|
||||
[id: string]: TEntity | undefined;
|
||||
}
|
||||
|
||||
/** List of entity IDs and fetch state. */
|
||||
interface EntityList {
|
||||
/** Set of entity IDs in this list. */
|
||||
ids: Set<string>;
|
||||
/** Server state for this entity list. */
|
||||
state: EntityListState;
|
||||
}
|
||||
|
||||
/** Fetch state for an entity list. */
|
||||
interface EntityListState {
|
||||
/** Next URL for pagination, if any. */
|
||||
next: (() => Promise<PaginatedResponse<any>>) | null;
|
||||
/** Previous URL for pagination, if any. */
|
||||
prev: (() => Promise<PaginatedResponse<any>>) | null;
|
||||
/** Error returned from the API, if any. */
|
||||
error: unknown;
|
||||
/** Whether data has already been fetched */
|
||||
fetched: boolean;
|
||||
/** Whether data for this list is currently being fetched. */
|
||||
fetching: boolean;
|
||||
}
|
||||
|
||||
/** Cache data pertaining to a paritcular entity type.. */
|
||||
/** Cache data pertaining to a paritcular entity type. */
|
||||
interface EntityCache<TEntity extends Entity = Entity> {
|
||||
/** Map of entities of this type. */
|
||||
store: EntityStore<TEntity>;
|
||||
/** Lists of entity IDs for a particular purpose. */
|
||||
lists: {
|
||||
[listKey: string]: EntityList | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
/** Whether to import items at the start or end of the list. */
|
||||
@ -53,12 +25,4 @@ interface EntitiesTransaction {
|
||||
};
|
||||
}
|
||||
|
||||
export type {
|
||||
Entity,
|
||||
EntityStore,
|
||||
EntityList,
|
||||
EntityListState,
|
||||
EntityCache,
|
||||
ImportPosition,
|
||||
EntitiesTransaction,
|
||||
};
|
||||
export type { Entity, EntityStore, EntityCache, ImportPosition, EntitiesTransaction };
|
||||
|
||||
@ -1,11 +1,4 @@
|
||||
import type {
|
||||
Entity,
|
||||
EntityStore,
|
||||
EntityList,
|
||||
EntityCache,
|
||||
EntityListState,
|
||||
ImportPosition,
|
||||
} from './types';
|
||||
import type { Entity, EntityStore, EntityCache } from './types';
|
||||
|
||||
/** Insert the entities into the store. */
|
||||
const updateStore = (store: EntityStore, entities: Entity[]): EntityStore =>
|
||||
@ -17,41 +10,9 @@ const updateStore = (store: EntityStore, entities: Entity[]): EntityStore =>
|
||||
{ ...store },
|
||||
);
|
||||
|
||||
/** Update the list with new entity IDs. */
|
||||
const updateList = (
|
||||
list: EntityList,
|
||||
entities: Entity[],
|
||||
pos: ImportPosition = 'end',
|
||||
): EntityList => {
|
||||
const newIds = entities.map((entity) => entity.id);
|
||||
const oldIds = Array.from(list.ids);
|
||||
const ids = new Set(pos === 'start' ? [...newIds, ...oldIds] : [...oldIds, ...newIds]);
|
||||
|
||||
return {
|
||||
...list,
|
||||
ids,
|
||||
};
|
||||
};
|
||||
|
||||
/** Create an empty entity cache. */
|
||||
const createCache = (): EntityCache => ({
|
||||
store: {},
|
||||
lists: {},
|
||||
});
|
||||
|
||||
/** Create an empty entity list. */
|
||||
const createList = (): EntityList => ({
|
||||
ids: new Set(),
|
||||
state: createListState(),
|
||||
});
|
||||
|
||||
/** Create an empty entity list state. */
|
||||
const createListState = (): EntityListState => ({
|
||||
next: null,
|
||||
prev: null,
|
||||
error: null,
|
||||
fetched: false,
|
||||
fetching: false,
|
||||
});
|
||||
|
||||
export { updateStore, updateList, createCache, createList };
|
||||
export { updateStore, createCache };
|
||||
|
||||
Reference in New Issue
Block a user