Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bs-dataloader

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs-dataloader

This is a rewrite in reasonml of https://github.com/facebook/dataloader/blob/master/src/index.js

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

bs-dataloader

CircleCI

This is a rewrite of dataloader js lib in reasonml for use with BuckleScript. I have a goal to make it work with native OCaml in the future but I still rely on some JavaScript structures.

Usage

module UserLoaderImpl = {
  type value = user;
  type key = userId;

  /* The batchLoadFun needs to wrap the returned values in Js.Result.t so that we can reject each promise instead of all */
  let batchLoadFun = userIds => batchGetUsers(userIds);
  let options: options = {batch: true, maxBatchSize: 256, cache: true};
};

module UserLoader = DataLoader.Make(UserLoaderImpl);

UserLoader.load("1")
|> Js.Promise.then_(
  user => {
    displayUser user;
    Js.Promise.resolve ();
  }
);

/* elsewhere in your app */

UserLoader.load("2")
|> Js.Promise.then_(
  user => {
    interactWithUser user;
    Js.Promsie.resolve();
  }
);

The example above will load both users at the same time with 1 request. If we later need one of the loaded users again we will get a cached version of the promise, if you need a new version from the server you can clear the key.

updateUser(~userId, ~userPatch)
|> Js.Promise.then_(_ => Js.Promise.resolve(UserLoader.clear userId))
|> Js.Promise.then_(_ => UserLoader.load("1"))
|> Js.Promise.then_(user => {
  displayUser user;
  Js.Promise.resolve ();
});

Development

Build

npm run build

Build + Watch

npm run watch

Test

npm run test

Editor

If you use vscode, Press Windows + Shift + B it will build automatically

Keywords

FAQs

Package last updated on 23 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc