batchloader
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -0,1 +1,2 @@ | ||
import { Cache, CacheLoader } from './cacheloader'; | ||
import { MappedBatchLoader } from './mappedbatchloader'; | ||
@@ -16,2 +17,3 @@ import { IBatchLoader } from './types'; | ||
mapLoader<MappedValue>(mapFn: (value: Value) => MappedValue): MappedBatchLoader<Key, Value, MappedValue>; | ||
cacheLoader(cache?: Cache<Key, Value>): CacheLoader<Key, Value>; | ||
protected triggerBatch(): Promise<Value[]>; | ||
@@ -18,0 +20,0 @@ protected runBatchNow(): Promise<Value[]>; |
@@ -11,2 +11,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cacheloader_1 = require("./cacheloader"); | ||
const mappedbatchloader_1 = require("./mappedbatchloader"); | ||
@@ -44,2 +45,5 @@ const sleep = (ms) => new Promise((resolve) => { | ||
} | ||
cacheLoader(cache) { | ||
return new cacheloader_1.CacheLoader(this, cache); | ||
} | ||
triggerBatch() { | ||
@@ -57,5 +61,2 @@ return (this.batchPromise || | ||
const { queuedKeys, keyToUniqueId } = this; | ||
if (!queuedKeys.length) { | ||
return []; | ||
} | ||
this.queuedKeys = []; | ||
@@ -62,0 +63,0 @@ if (keyToUniqueId) { |
{ | ||
"name": "batchloader", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "BatchLoader is a utility for data fetching layer to reduce requests via batching written in TypeScript. Inspired by Facebook's DataLoader", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -22,2 +22,3 @@ import { BatchLoader } from './batchloader'; | ||
expect(await loader.loadMany([])).toEqual([]); | ||
expect(await loader.loadMany([])).toEqual([]); | ||
expect(await loader.loadMany([1, 2, 3])).toEqual([2, 4, 6]); | ||
@@ -33,2 +34,3 @@ expect(await loader.loadMany([1, 2, 3, 2, 3, 2, 1])).toEqual([ | ||
]); | ||
expect(await loader.loadMany([])).toEqual([]); | ||
@@ -35,0 +37,0 @@ expect( |
@@ -0,1 +1,2 @@ | ||
import { Cache, CacheLoader } from 'src/cacheloader'; | ||
import { MappedBatchLoader } from 'src/mappedbatchloader'; | ||
@@ -56,2 +57,6 @@ import { IBatchLoader, MaybePromise } from 'src/types'; | ||
public cacheLoader(cache?: Cache<Key, Value>): CacheLoader<Key, Value> { | ||
return new CacheLoader(this, cache); | ||
} | ||
protected triggerBatch(): Promise<Value[]> { | ||
@@ -73,6 +78,2 @@ return ( | ||
const { queuedKeys, keyToUniqueId } = this; | ||
if (!queuedKeys.length) { | ||
return []; | ||
} | ||
this.queuedKeys = []; | ||
@@ -79,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44674
27
898