UNPKG

backbone-fractal

Version:

Lightweight composite views for Backbone

65 lines (64 loc) 2.67 kB
/// <reference types="jquery" /> import { View, Model } from 'backbone'; export declare type Result<T> = T | { (): T; }; export declare type Selector = NonNullable<string>; export declare type NoSelector = false; export declare type FallbackSelector = Selector | NoSelector; export declare type JQElement = JQuery<Element>; export declare type SafeInsertionMethod = 'append' | 'prepend'; export declare type RiskyInsertionMethod = 'after' | 'before' | 'replaceWith'; export declare type InsertionMethod = SafeInsertionMethod | RiskyInsertionMethod; export interface RootSubViewDton { view: string | Result<View>; selector?: Result<NoSelector>; method?: Result<SafeInsertionMethod>; place?: string | Result<boolean>; } export interface SelectorSubViewDton { view: string | Result<View>; selector: Result<Selector>; method?: Result<InsertionMethod>; place?: string | Result<boolean>; } export declare type SubViewDescription = RootSubViewDton | SelectorSubViewDton; export declare type SubView = string | Result<View | SubViewDescription>; export interface SubViewIterator { (view: View, selector: JQElement, method: InsertionMethod): void; } export interface IterationOptions { placeOnly?: boolean; reverse?: boolean; } export declare type _NormalizedSubView = [View, JQElement, InsertionMethod]; interface ContainerMap { [selector: string]: JQElement; } export default class CompositeView<TModel extends Model = Model> extends View<TModel> { defaultPlacement: SafeInsertionMethod; _containers: ContainerMap; render(): this; beforeRender(): this; renderContainer(): this; afterRender(): this; remove(): this; /** * Invariant: each subview must appear at most once in this list. */ subviews(): SubView[]; clearSubviews(): this; detachSubviews(): this; placeSubviews(): this; forEachSubview(iteratee: SubViewIterator, options?: IterationOptions): this; _resetContainer(): this; _getSubviews(applyChecks: boolean): _NormalizedSubView[]; _normalizeSubview(applyChecks: boolean, sv: SubView): _NormalizedSubView | void; _normalizeRootSubview(view: View, method: Result<SafeInsertionMethod>): _NormalizedSubView; _normalizeSelectorSubview(view: View, selector: Selector, method: Result<InsertionMethod>): _NormalizedSubView; _resolve<T>(handle: string | Result<T>): T; } export declare function _removeSubview<V extends View>(view: V): void; export declare function _detachSubview<V extends View>(view: V): void; export declare function _placeSubview<V extends View>(subview: V, container: JQElement, method: InsertionMethod): void; export {};