UNPKG

2.33 kBTypeScriptView Raw
1/**
2 * - create_view and remove_view are default functions called when adding or removing views
3 * - create_view takes a model and an index and returns a view or a promise for a view for that model
4 * - remove_view takes a view and destroys it (including calling `view.remove()`)
5 * - each time the update() function is called with a new list, the create and remove
6 * callbacks will be called in an order so that if you append the views created in the
7 * create callback and remove the views in the remove callback, you will duplicate
8 * the order of the list.
9 * - the remove callback defaults to just removing the view (e.g., pass in null for the second parameter)
10 * - the context defaults to the created ViewList. If you pass another context, the create and remove
11 * will be called in that context.
12 */
13export declare class ViewList<T> {
14 constructor(create_view: (model: any, index: any) => T | Promise<T>, remove_view: (view: T) => void, context: any);
15 initialize(create_view: (model: any, index: any) => T | Promise<T>, remove_view: (view: T) => void, context: any): void;
16 /**
17 * the create_view, remove_view, and context arguments override the defaults
18 * specified when the list is created.
19 * after this function, the .views attribute is a list of promises for views
20 * if you want to perform some action on the list of views, do something like
21 * `Promise.all(myviewlist.views).then(function(views) {...});`
22 */
23 update(new_models: any[], create_view?: (model: any, index: any) => T | Promise<T>, remove_view?: (view: T) => void, context?: any): Promise<T[]>;
24 /**
25 * removes every view in the list; convenience function for `.update([])`
26 * that should be faster
27 * returns a promise that resolves after this removal is done
28 */
29 remove(): Promise<void>;
30 /**
31 * Dispose this viewlist.
32 *
33 * A synchronous function which just deletes references to child views. This
34 * function does not call .remove() on child views because that is
35 * asynchronous. Use this in cases where child views will be removed in
36 * another way.
37 */
38 dispose(): void;
39 _handler_context: any;
40 _models: any[];
41 views: Promise<T>[];
42 _create_view: (model: any, index: any) => T | Promise<T>;
43 _remove_view: (view: T) => void;
44}