| 44 | |
| 45 | @singleton() |
| 46 | export class NotificationService |
| 47 | extends Component<INotification> |
| 48 | implements INotificationService |
| 49 | { |
| 50 | protected state: INotification; |
| 51 | |
| 52 | constructor() { |
| 53 | super(); |
| 54 | this.state = container.resolve(NotificationModel); |
| 55 | } |
| 56 | |
| 57 | public toggleNotification(): void { |
| 58 | const next = cloneDeep(this.state); |
| 59 | next.showNotifications = !this.state.showNotifications; |
| 60 | this.setState(next); |
| 61 | } |
| 62 | |
| 63 | public update<T>(item: INotificationItem<T>): INotificationItem<T> | null { |
| 64 | const { data = [] } = this.state; |
| 65 | if (data.length) { |
| 66 | const index = data.findIndex(searchById(item.id)); |
| 67 | if (index > -1) { |
| 68 | const original = data[index]; |
| 69 | data[index] = Object.assign(original, item); |
| 70 | this.setState({ |
| 71 | ...this.state, |
| 72 | data: [...data], |
| 73 | }); |
| 74 | return data[index]; |
| 75 | } else { |
| 76 | logger.error( |
| 77 | 'There is no notification be found, please check the id' |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | public remove(id: UniqueId): void { |
| 85 | const { data = [] } = this.state; |
| 86 | if (data.length) { |
| 87 | const index = data.findIndex(searchById(id)); |
| 88 | if (index > -1) { |
| 89 | data.splice(index, 1); |
| 90 | this.setState({ |
| 91 | ...this.state, |
| 92 | data: [...data], |
| 93 | }); |
| 94 | } else { |
| 95 | logger.error( |
| 96 | 'There is no notification be found, please check the id' |
| 97 | ); |
| 98 | } |
| 99 | } else { |
| 100 | logger.error( |
| 101 | "You can't remove notification because there is no notifications in data." |
| 102 | ); |
| 103 | } |
nothing calls this directly
no outgoing calls
no test coverage detected