UNPKG

@magicbell/react-headless

Version:

Hooks to build a notification inbox

33 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.objMatchesContext = objMatchesContext; const ramda_1 = require("ramda"); function eq(value, other) { return value === other || (value !== value && other !== other); } /** * Check if a notification satisfies all conditions of the given `context`. It * Uses equal to compare. * * @param notification Notification to test * @param context Set of rules to test the notification against * @param comparator Function used to compare notification attributes and context values */ function objMatchesContext(notification, context, comparator = eq) { const diff = []; // backend defaults to unarchived notifications, so we need to do the same context = { archived: false, ...context }; Object.keys(context).forEach((attr) => { const condition = context[attr]; if ((attr === 'read' && !comparator(!(0, ramda_1.isNil)(notification.readAt), condition)) || (attr === 'seen' && !comparator(!(0, ramda_1.isNil)(notification.seenAt), condition)) || (attr === 'archived' && !comparator(!(0, ramda_1.isNil)(notification.archivedAt), condition)) || (attr === 'category' && !comparator(notification.category, condition)) || (attr === 'topic' && !comparator(notification.topic, condition)) || (Object.hasOwnProperty.call(notification, attr) && !comparator(notification[attr], condition))) { diff.push(attr); } }); return { result: diff.length === 0, delta: diff }; } //# sourceMappingURL=strategies.js.map