Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
martypdx committed Mar 23, 2024
1 parent 03f036a commit 7e2d9dd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
10 changes: 4 additions & 6 deletions packages/channels/branch.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions packages/channels/branch.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -118,7 +118,6 @@ describe('promise', () => {
<!--1-->,
]
`);

});

});
Expand Down
4 changes: 2 additions & 2 deletions packages/channels/channel.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/channels/consume.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ export function consume(asyncSource, ...actions) {
break;
case !!asyncSource[Symbol.asyncIterator]:
default:
throw new AsyncSourceTypeError(asyncSource);
throw new AsyncTypeError(asyncSource);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/channels/tee.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/channels/throw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export class AsyncSourceTypeError extends TypeError {
export class AsyncTypeError extends TypeError {
constructor(asyncProvider) {
let message = '';
if(!asyncProvider) {
Expand Down

0 comments on commit 7e2d9dd

Please sign in to comment.