forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-ui-scroll-tests.ts
More file actions
93 lines (80 loc) · 2.96 KB
/
angular-ui-scroll-tests.ts
File metadata and controls
93 lines (80 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/// <reference path="angular-ui-scroll.d.ts" />
var myApp = angular.module('application', ['ui.scroll', 'ui.scroll.jqlite']);
module application {
interface IItem {
id: number;
content: string;
}
class DatasourceTest implements ng.ui.IScrollDatasource<IItem> {
get(index: number, count: number, success: (results: IItem[]) => void): void {
var ret = new Array<IItem>();
for (var i=0; i < count; i++) {
ret.push({id: i, content: 'item ' + i.toString()});
}
success(ret);
}
}
function factory(): any {
return DatasourceTest;
}
myApp.factory('DatasourceTest', factory);
// demo/examples/adapter
myApp.controller('mainController', ['$scope', 'DatasourceTest', function($scope: ng.IScope, datasource: DatasourceTest) {
var firstListAdapter: ng.ui.IScrollAdapter, secondListAdapter: ng.ui.IScrollAdapter;
$scope['datasource'] = datasource;
$scope['updateList1'] = (): void => {
firstListAdapter.applyUpdates( (item: IItem, scope: ng.IRepeatScope) => {
return item.content += ' *';
})
};
$scope['removeFromList1'] = (): void => {
firstListAdapter.applyUpdates( (item: IItem, scope: ng.IRepeatScope) => {
if (scope.$index % 2 === 0) {
return []
}
})
};
var idList1: number = 1000;
$scope['addToList1'] = (): void => {
firstListAdapter.applyUpdates((item: IItem, scope: ng.IRepeatScope) => {
var newItem: IItem;
newItem = void 0;
if (scope.$index === 2) {
newItem = {
id: idList1,
content: 'a new one #' + idList1
};
idList1++;
return [item, newItem];
}
});
};
$scope['updateList2'] = (): void => {
secondListAdapter.applyUpdates((item: IItem, scope: ng.IRepeatScope) => {
return item.content += ' *';
});
};
$scope['removeFromList2'] = (): void => {
secondListAdapter.applyUpdates((item: IItem, scope: ng.IRepeatScope) => {
if (scope.$index % 2 !== 0) {
return [];
}
});
};
var idList2: number = 2000;
$scope['addToList2'] = (): void => {
secondListAdapter.applyUpdates((item: IItem, scope: ng.IRepeatScope) => {
var newItem: IItem;
newItem = void 0;
if (scope.$index === 4) {
newItem = {
id: idList2,
content: 'a new one #' + idList1
};
idList2++;
return [item, newItem];
}
});
};
}]);
}