Skip to content
This repository has been archived by the owner on Aug 10, 2018. It is now read-only.

Latest commit

 

History

History
26 lines (19 loc) · 528 Bytes

README.md

File metadata and controls

26 lines (19 loc) · 528 Bytes

foodchain

Usage

Call request just once.

const {request, define} = require('foodchain');

define('get:user', {
  shouldSaveResult: true,
  shouldUseResult: true,
  factory: ({userId}) => `user-${userId}`,
  request: ({userId}) => request.get(`/api/users/${userId}`),
});

const showUser = async userId => {
  const user = await foodchain('get:user', {userId: 'ae563h7e'});
  console.log(user);
};

With this setup: showUser will

  • fetch and log after first call and
  • only log after other calls