From 7e2d9dd1cffa3b20cac5c005e962175945cd6a3e Mon Sep 17 00:00:00 2001 From: Marty Nelson Date: Sat, 23 Mar 2024 14:46:19 -0700 Subject: [PATCH] refactoring --- packages/channels/branch.js | 10 ++++------ packages/channels/branch.test.jsx | 3 +-- packages/channels/channel.js | 4 ++-- packages/channels/consume.js | 4 ++-- packages/channels/tee.js | 4 ++-- packages/channels/throw.js | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/channels/branch.js b/packages/channels/branch.js index 44c7d35..7713114 100644 --- a/packages/channels/branch.js +++ b/packages/channels/branch.js @@ -1,5 +1,5 @@ import { Multicast } from './generators.js'; -import { AsyncSourceTypeError } from './throw.js'; +import { AsyncTypeError } from './throw.js'; import { channel } from './channel.js'; export function branch(async, ...transforms) { @@ -9,14 +9,13 @@ export function branch(async, ...transforms) { case !!async?.[Symbol.asyncIterator]: return branchAsyncIterator(async, transforms); default: - throw new AsyncSourceTypeError(async); + throw new AsyncTypeError(async); } } function branchPromise(promise, transforms) { return transforms.map(transform => { - if(Array.isArray(transform)) { - // #[transform, options] + if(Array.isArray(transform)) { // #[transform, options] return channel(promise, transform[0], transform[1]); } return channel(promise, transform); @@ -26,8 +25,7 @@ function branchPromise(promise, transforms) { function branchAsyncIterator(iterator, transforms) { const multicast = new Multicast(iterator); return transforms.map(transform => { - if(Array.isArray(transform)) { - // #[transform, options]; + if(Array.isArray(transform)) { // #[transform, options]; return multicast.subscriber(transform[0], transform[1]); } return multicast.subscriber(transform); diff --git a/packages/channels/branch.test.jsx b/packages/channels/branch.test.jsx index 27539ab..6265dbf 100644 --- a/packages/channels/branch.test.jsx +++ b/packages/channels/branch.test.jsx @@ -3,7 +3,7 @@ import './with-resolvers-polyfill.js'; import { fixtureSetup } from 'test-utils/fixtures'; import { subject } from './generators.js'; import { branch } from './branch.js'; -import { Cat, CatCount, CatList, CatNames } from './test-cats.jsx'; +import { Cat, CatCount, CatNames } from './test-cats.jsx'; beforeEach(fixtureSetup); @@ -118,7 +118,6 @@ describe('promise', () => { , ] `); - }); }); diff --git a/packages/channels/channel.js b/packages/channels/channel.js index bcb1529..d901a61 100644 --- a/packages/channels/channel.js +++ b/packages/channels/channel.js @@ -1,6 +1,6 @@ import { Sync } from '../maya/compose/compose.js'; import { resolveArgs } from './resolve-args.js'; -import { AsyncSourceTypeError, InitOptionWithSyncWrappedAsyncProviderError, OptionMissingFunctionArgumentError } from './throw.js'; +import { AsyncTypeError, InitOptionWithSyncWrappedAsyncProviderError, OptionMissingFunctionArgumentError } from './throw.js'; export function channel(async, transformArg, options) { const { @@ -45,7 +45,7 @@ function makeChannel(asyncSource, transform, map, onDeck) { case !!asyncSource[Symbol.asyncIterator]: return fromAsyncIterator(asyncSource, transform, map, onDeck); default: - throw new AsyncSourceTypeError(asyncSource); + throw new AsyncTypeError(asyncSource); } } diff --git a/packages/channels/consume.js b/packages/channels/consume.js index 00b8e55..51d7cfa 100644 --- a/packages/channels/consume.js +++ b/packages/channels/consume.js @@ -1,5 +1,5 @@ import { Multicast } from './generators.js'; -import { AsyncSourceTypeError } from './throw.js'; +import { AsyncTypeError } from './throw.js'; export function consume(asyncSource, ...actions) { const type = typeof asyncSource; @@ -12,7 +12,7 @@ export function consume(asyncSource, ...actions) { break; case !!asyncSource[Symbol.asyncIterator]: default: - throw new AsyncSourceTypeError(asyncSource); + throw new AsyncTypeError(asyncSource); } } diff --git a/packages/channels/tee.js b/packages/channels/tee.js index 675cd1c..4a5c07d 100644 --- a/packages/channels/tee.js +++ b/packages/channels/tee.js @@ -1,6 +1,6 @@ import { Sync } from '../maya/compose/compose.js'; import { Multicast } from './generators.js'; -import { AsyncSourceTypeError, BadTeeCountArgumentError } from './throw.js'; +import { AsyncTypeError, BadTeeCountArgumentError } from './throw.js'; export function tee(async, count = 2) { const repeat = parseInt(count); @@ -26,7 +26,7 @@ function makeTee(asyncProvider, count, init) { case !!asyncProvider?.[Symbol.asyncIterator]: return teeAsyncIterator(asyncProvider, count, init); default: - throw new AsyncSourceTypeError(asyncProvider); + throw new AsyncTypeError(asyncProvider); } } diff --git a/packages/channels/throw.js b/packages/channels/throw.js index 72cb72c..425004e 100644 --- a/packages/channels/throw.js +++ b/packages/channels/throw.js @@ -1,5 +1,5 @@ -export class AsyncSourceTypeError extends TypeError { +export class AsyncTypeError extends TypeError { constructor(asyncProvider) { let message = ''; if(!asyncProvider) {