UNPKG

4.23 kBPlain TextView Raw
1/* eslint-disable @typescript-eslint/no-unused-vars */
2import { View } from 'aurelia-templating';
3
4/**
5* An abstract base class for elements and attributes that repeat
6* views.
7*/
8export class AbstractRepeater {
9 constructor(options) {
10 Object.assign(this, {
11 local: 'items',
12 viewsRequireLifecycle: true
13 }, options);
14 }
15
16 /**
17 * Returns the number of views the repeater knows about.
18 *
19 * @return the number of views.
20 */
21 viewCount(): number {
22 throw new Error('subclass must implement `viewCount`');
23 }
24
25 /**
26 * Returns all of the repeaters views as an array.
27 *
28 * @return The repeater's array of views;
29 */
30 views(): any[] {
31 throw new Error('subclass must implement `views`');
32 }
33
34 /**
35 * Returns a single view from the repeater at the provided index.
36 *
37 * @param index The index of the requested view.
38 * @return {View|ViewSlot} The requested view.
39 */
40 view(index: number): any {
41 throw new Error('subclass must implement `view`');
42 }
43
44 /**
45 * Returns the matcher function to be used by the repeater, or null if strict matching is to be performed.
46 *
47 * @return The requested matcher function.
48 */
49 matcher(): Function | null {
50 throw new Error('subclass must implement `matcher`');
51 }
52
53 /**
54 * Adds a view to the repeater, binding the view to the
55 * provided contexts.
56 *
57 * @param {Object} bindingContext The binding context to bind the new view to.
58 * @param {Object} overrideContext A secondary binding context that can override the primary context.
59 */
60 addView(bindingContext, overrideContext): any {
61 throw new Error('subclass must implement `addView`');
62 }
63
64 /**
65 * Inserts a view to the repeater at a specific index, binding the view to the
66 * provided contexts.
67 *
68 * @param {Number} index The index at which to create the new view at.
69 * @param {Object} bindingContext The binding context to bind the new view to.
70 * @param {Object} overrideContext A secondary binding context that can override the primary context.
71 */
72 insertView(index, bindingContext, overrideContext): any {
73 throw new Error('subclass must implement `insertView`');
74 }
75
76 /**
77 * Moves a view across the repeater.
78 *
79 * @param {Number} sourceIndex The index of the view to be moved.
80 * @param {Number} sourceIndex The index where the view should be placed at.
81 */
82 moveView(sourceIndex, targetIndex): any {
83 throw new Error('subclass must implement `moveView`');
84 }
85
86 /**
87 * Removes all views from the repeater.
88 * @param {Boolean} returnToCache Should the view be returned to the view cache?
89 * @param {Boolean} skipAnimation Should the removal animation be skipped?
90 * @return {Promise|null}
91 */
92 removeAllViews(returnToCache?: boolean, skipAnimation?: boolean): any {
93 throw new Error('subclass must implement `removeAllViews`');
94 }
95
96 /**
97 * Removes an array of Views from the repeater.
98 *
99 * @param {Array} viewsToRemove The array of views to be removed.
100 * @param {Boolean} returnToCache Should the view be returned to the view cache?
101 * @param {Boolean} skipAnimation Should the removal animation be skipped?
102 */
103 removeViews(viewsToRemove: Array<View>, returnToCache?: boolean, skipAnimation?: boolean): any {
104 throw new Error('subclass must implement `removeView`');
105 }
106
107 /**
108 * Removes a view from the repeater at a specific index.
109 *
110 * @param {Number} index The index of the view to be removed.
111 * @param {Boolean} returnToCache Should the view be returned to the view cache?
112 * @param {Boolean} skipAnimation Should the removal animation be skipped?
113 */
114 removeView(index: number, returnToCache?: boolean, skipAnimation?: boolean): any {
115 throw new Error('subclass must implement `removeView`');
116 }
117
118 /**
119 * Forces a particular view to update it's bindings, called as part of
120 * an in-place processing of items for better performance
121 *
122 * @param {Object} view the target view for bindings updates
123 */
124 updateBindings(view: View) {
125 throw new Error('subclass must implement `updateBindings`');
126 }
127}