All files / utils attributeStore.js

0% Statements 0/18
0% Branches 0/14
0% Functions 0/8
0% Lines 0/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                                             
import Attribute from './attribute';
 
const AttributeStore = (attrs) => {
  let list = [];
  if (attrs && attrs.length) {
    list = attrs
      .filter(a => a && a.dates)
      .map((a, i) => Attribute({
        key: a.key || i.toString(),
        order: a.order || 0,
        ...a,
      }));
  }
  return {
    // Return a sorted array of objects consisting of
    // ...the attribute
    // ...and the first matching date info
    find(dayInfo) {
      return list
        .map(attribute => ({
          ...attribute,
          targetDate: attribute.includesDay(dayInfo),
        }))
        .filter(a => a.targetDate)
        .sort((a, b) => a.targetDate.compare(b.targetDate));
    },
  };
};
 
export default AttributeStore;