1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16export class BasicDataSource implements IDataSource { 17 private listeners: DataChangeListener[] = [] 18 19 public totalCount(): number { 20 return 0 21 } 22 23 public getData(index: number): any { 24 return undefined 25 } 26 27 registerDataChangeListener(listener: DataChangeListener): void { 28 if (this.listeners.indexOf(listener) < 0) { 29 this.listeners.push(listener) 30 } 31 } 32 33 unregisterDataChangeListener(listener: DataChangeListener): void { 34 const pos = this.listeners.indexOf(listener) 35 if (pos >= 0) { 36 this.listeners.splice(pos, 1) 37 } 38 } 39 40 notifyDataReload(): void { 41 this.listeners.forEach(listener => { 42 listener.onDataReloaded() 43 }) 44 } 45 46 notifyDataAdd(index: number): void { 47 this.listeners.forEach(listener => { 48 listener.onDataAdd(index) 49 }) 50 } 51 52 notifyDataChange(index: number): void { 53 this.listeners.forEach(listener => { 54 listener.onDataChange(index) 55 }) 56 } 57 58 notifyDataDelete(index: number): void { 59 this.listeners.forEach(listener => { 60 listener.onDataDelete(index) 61 }) 62 } 63 64 notifyDataMove(from: number, to: number): void { 65 this.listeners.forEach(listener => { 66 listener.onDataMove(from, to) 67 }) 68 } 69}