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

SmartImpulse/foodchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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