naja
Version:
Modern AJAX library for Nette Framework
57 lines (56 loc) • 2.05 kB
TypeScript
import { Naja, Options } from '../Naja';
import { HistoryState } from './HistoryHandler';
import { SnippetHandler } from './SnippetHandler';
import { TypedEventListener } from '../utils';
declare module '../Naja' {
interface Options {
snippetCache?: boolean | SnippetCacheStorageType;
}
}
declare module './HistoryHandler' {
interface HistoryState {
snippets?: {
readonly storage: SnippetCacheStorageType;
readonly key: SnippetCacheKey;
};
}
}
export declare class SnippetCache extends EventTarget {
private readonly naja;
private readonly storages;
private currentSnippets;
private static parser;
constructor(naja: Naja);
private resolveStorage;
private static shouldCacheSnippet;
private initializeIndex;
private updateIndex;
private configureCache;
private buildHistoryState;
private restoreHistoryState;
addEventListener: <K extends keyof SnippetCacheEventMap | string>(type: K, listener: TypedEventListener<SnippetHandler, K extends keyof SnippetCacheEventMap ? SnippetCacheEventMap[K] : CustomEvent>, options?: boolean | AddEventListenerOptions) => void;
removeEventListener: <K extends keyof SnippetCacheEventMap | string>(type: K, listener: TypedEventListener<SnippetHandler, K extends keyof SnippetCacheEventMap ? SnippetCacheEventMap[K] : CustomEvent>, options?: boolean | AddEventListenerOptions) => void;
}
export type StoreEvent = CustomEvent<{
snippets: CachedSnippets;
state: HistoryState;
options: Options;
}>;
export type FetchEvent = CustomEvent<{
state: HistoryState;
options: Options;
}>;
export type RestoreEvent = CustomEvent<{
snippets: CachedSnippets;
state: HistoryState;
options: Options;
}>;
interface SnippetCacheEventMap {
store: StoreEvent;
fetch: FetchEvent;
restore: RestoreEvent;
}
type CachedSnippets = Record<string, string>;
type SnippetCacheKey = CachedSnippets | string | null;
type SnippetCacheStorageType = 'off' | 'history' | 'session';
export {};