recoil#selector JavaScript Examples

The following examples show how to use recoil#selector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: selectors.js    From recoil-paint with MIT License 6 votes vote down vote up
function itemsSelector(key, state) {
  return selector({
    key,
    get: ({ get }) => {
      const ids = get(state);
      if (!ids.length) {
        return [];
      }

      return ids.map(id => get(itemWithId(id)));
    },
    set: ({ set }, newValue) => {
      newValue.forEach(item => {
        let id = item.id;
        set(itemWithId(id), item);
      });
    }
  });
}
Example #2
Source File: selectors.js    From recoil-paint with MIT License 6 votes vote down vote up
itemWithId = memoize(id => selector({
  key: `item${id}`,
  get: ({ get }) => {
    const state = get(privateItemStateWithId(id));
    return applyConstraints(state);
  },
  set: ({ set }, newValue) => {
    const state = privateItemStateWithId(id);
    set(state, newValue);
  }
}))
Example #3
Source File: LocationPage.js    From app-personium-trails with Apache License 2.0 6 votes vote down vote up
locationResults = selector({
  key: 'searchLocationResult',
  get: async ({ get }) => {
    const query = get(locationQuery);
    if (query.year === null || query.month === null || query.day === null) {
      console.log('null');
      return await [];
    }

    const { year, month, day } = query;

    const queryDate = new Date(year, month - 1, day);
    return await Promise.all([
      adapter.getStaysByDate(queryDate),
      adapter.getMovesByDate(queryDate),
      adapter.getTimelineByDate(queryDate),
    ])
      .then(([stayDat, moveDat, stat]) => {
        console.log(stat);
        const _results = [].concat(stayDat, moveDat).map(item => {
          // resolve filename
          const timems = parseInt(item.startTime.match(/\/Date\((\d+)\)\//)[1]);
          const filename = `${'placeId' in item ? 's' : 'm'}_${timems}.json`;
          const folder = `${authState.boxUrl}locations/${getYMD(timems)}/`;
          const filepath = `${folder}${filename}`;
          console.log({ item, stat: stat.get(filepath) });
          return {
            timestampms: timems,
            dat: item,
          };
        });
        return _results;
      })
      .then(results => results.sort((a, b) => a.timestampms - b.timestampms))
      .then(results => results.map(item => item.dat));
  },
})
Example #4
Source File: selectors.js    From recoil-paint with MIT License 5 votes vote down vote up
statisticsQuery = memoize(id => selector({
  key: `Statistics${id}`,
  get: async ({ get }) => {
    let statistics = await loadStatistics(id);
    return statistics;
  },
}))
Example #5
Source File: selectors.js    From recoil-paint with MIT License 5 votes vote down vote up
selectionBoundingBox = selector({
  key: 'selectionBoundingBox',
  get: ({ get }) => computeBoundingBox(get(selectedItemsSelector))
})