import { ArSyncStore, Request } from './ArSyncStore';
import ConnectionAdapter from './ConnectionAdapter';
declare type Path = Readonly<(string | number)[]>;
interface Change {
path: Path;
value: any;
}
declare type ChangeCallback = (change: Change) => void;
declare type LoadCallback = () => void;
declare type ConnectionCallback = (status: boolean) => void;
declare type SubscriptionType = 'load' | 'change' | 'connection' | 'destroy';
declare type SubscriptionCallback = ChangeCallback | LoadCallback | ConnectionCallback;
declare type ArSyncModelRef = {
key: string;
count: number;
timer: number | null;
model: ArSyncStore;
};
declare type PathFirst
> = ((...args: P) => void) extends (first: infer First, ...other: any) => void ? First : never;
declare type PathRest = U extends Readonly ? ((...args: U) => any) extends (head: any, ...args: infer T) => any ? U extends Readonly<[any, any, ...any[]]> ? T : never : never : never;
declare type DigResult> = Data extends null | undefined ? Data : PathFirst extends never ? Data : PathFirst
extends keyof Data ? (Data extends Readonly ? undefined : never) | {
0: Data[PathFirst];
1: DigResult], PathRest>;
}[PathRest
extends never ? 0 : 1] : undefined;
export default class ArSyncModel {
private _ref;
private _listenerSerial;
private _listeners;
complete: boolean;
notfound?: boolean;
destroyed: boolean;
connected: boolean;
data: T | null;
static _cache: {
[key: string]: {
key: string;
count: number;
timer: number | null;
model: any;
};
};
static cacheTimeout: number;
constructor(request: Request, option?: {
immutable: boolean;
});
onload(callback: LoadCallback): void;
subscribeOnce(event: SubscriptionType, callback: SubscriptionCallback): {
unsubscribe: () => void;
};
dig(path: P): DigResult | null;
static digData(data: Data, path: P): DigResult;
subscribe(event: SubscriptionType, callback: SubscriptionCallback): {
unsubscribe: () => void;
};
release(): void;
static retrieveRef(request: Request, option?: {
immutable: boolean;
}): ArSyncModelRef;
static _detach(ref: any): void;
private static _attach;
static setConnectionAdapter(adapter: ConnectionAdapter): void;
static waitForLoad(...models: ArSyncModel<{}>[]): Promise;
}
export {};