@magicbell/react-headless
Version:
Hooks to build a notification inbox
21 lines • 913 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = setStoreProps;
const ramda_1 = require("ramda");
/**
* Function to set props on a notification store. The notifications are merged
* unless `options.reset` is true.
*
* @param store Notifications store
* @param props Props to set to the store
* @param options.reset Do not prepend notifications to the store
* @returns Store
*/
function setStoreProps(store, props, options = { reset: false }) {
const { notifications = [], ...meta } = props;
const allNotifications = options.reset
? notifications
: (0, ramda_1.uniqBy)((notification) => notification.id, options.prepend ? [...notifications, ...store.notifications] : [...store.notifications, ...notifications]);
return { context: store.context, notifications: allNotifications, ...meta };
}
//# sourceMappingURL=setStoreProps.js.map