@magicbell/core
Version:
Official MagicBell API wrapper
64 lines (63 loc) • 2.01 kB
TypeScript
import Notification from '../models/Notification/index.js';
import NotificationRepository from '../models/Notification/NotificationRepository.js';
import RemoteStore from './RemoteStore.js';
export type NotificationStoreAttrs = {
items: Notification[] | any[];
total: number;
totalPages: number;
currentPage: number;
perPage: number;
unseenCount: number;
unreadCount: number;
};
/**
* A synced collection, or store, of notifications.
*
* @example
* const store = new NotificationStore()
*/
export default class NotificationStore extends RemoteStore<Notification> {
unseenCount: number;
unreadCount: number;
repo: NotificationRepository;
constructor(attrs?: {});
get notifications(): Notification[];
/**
* Create a notification, store it in the API server and add it to the store.
*
* @param data Data of the notification.
*/
create: (data: any) => Promise<Notification>;
/**
* Mark all notifications as read. Resets the `unreadCount` attribute.
*
* @param omitRequest Update notifications locally only.
*/
markAllAsRead: ({ omitRequest }?: {
omitRequest?: boolean;
}) => Promise<any>;
/**
* Mark all notifications as seen. Resets the `unseenCount` attribute.
*
* @param omitRequest Update notifications locally only.
* @param updateItems Mark all notifications as seen.
*/
markAllAsSeen: ({ omitRequest, updateItems }?: {
omitRequest?: boolean;
updateItems?: boolean;
}) => Promise<void>;
push(notification: Notification): boolean;
remove(notification: Notification): boolean;
incrementUnreadCount(): void;
decrementUnreadCount(): void;
incrementUnseenCount(): void;
decrementUnseenCount(): void;
set(json: any): void;
/**
* Append notifications to the store.
*
* @param items Object containing the pagination data
*/
setItems(items: any): this;
private createNotification;
}