mirror: A tiny/fast dataloader implementation
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: we should be using a `TypeError`

`TypeError` extends the `Error` object. But semantiaclly more accurate
in this case.

MDN describes this as:

"The TypeError object represents an error when an operation could not be
performed, typically (but not exclusively) when a value is not of the
expected type."

As the length of the array of values does not equal that of the request,
it is actually better to throw this `TypeError`.

Marais Rossouw (Oct 23, 2023, 10:16 AM +1000) 8403ff6a 4a896869

+4 -4
+3 -3
src/index.test.ts
··· 242 242 assert.instance(loader.results[0], Promise); 243 243 assert.equal(await loader.results[0], ['a']); 244 244 245 - assert.instance(items[0].error, Error); 246 - assert.instance(items[1].error, Error); 247 - assert.instance(items[2].error, Error); 245 + assert.instance(items[0].error, TypeError); 246 + assert.instance(items[1].error, TypeError); 247 + assert.instance(items[2].error, TypeError); 248 248 }); 249 249 250 250 errors('reject load if loader rejects that key', async () => {
+1 -1
src/index.ts
··· 26 26 27 27 loadFn(keys).then(function (values) { 28 28 if (values.length !== tasks.length) 29 - return reject(new Error('loader value length mismatch')); 29 + return reject(new TypeError('same length mismatch')); 30 30 31 31 for (; (tmp = values[i++]), i <= values.length; 32 32 tmp instanceof Error