Hi,
we have something like the following code:
QueryDataAdapter = function(query) {
this.query = query;
};
// QueryDataAdapter.prototype.getCount
// QueryDataAdapter.prototype.itemsFromIndex
QueryDataAdapter.prototype.setNotificationHandler = function(notificationHandler) {
return this.query.addEventListener('change', function(event) {
return notificationHandler.reload();
});
};
QueryDataSource = WinJS.Class.derive(WinJS.UI.VirtualizedDataSource, function(query) {
return this._baseDataSourceConstructor(new QueryDataAdapter(query));
});
We implemented a custom IListDataAdapter, to bind a ListView to a custom data source. The adapter has a custom query object that is used to fetch the actual data. It also adds an event listener to the query that will call notificationHandler.reload() when
the query changes.
Now there is one problem: The lifetime of the query object is not limited to the lifetime of the adapter. Therefore, even when the ListDataSource that uses the adapter is no longer used in a ListView, notificationHandler.reload() is still called. So, we
are wondering if there is an elegant way to remove the event listener once the data source is no longer used by any ListView. Or should it just work if we only keep a copy of the original query object? Would the adapter and query then be released once the
data source is no longer used, and would the event listener be implicitly removed by releasing the query?
Thanks,
Guido