From 769ee64d2e31a157d2d7fab9dc1b4a83141c6ccc Mon Sep 17 00:00:00 2001 From: unional Date: Thu, 21 Apr 2022 21:36:12 -0700 Subject: [PATCH] fix: update comments and keep comments --- .gitignore | 2 ++ package.json | 2 +- ts/Emitter.ts | 26 ++++++++++++++++++++------ ts/TestEmitter.ts | 4 +++- ts/createEvent.spec.ts | 4 ++-- ts/createEvent.ts | 8 +++++++- ts/setupCommandTest.ts | 5 ++++- tsconfig.base.json | 1 - tsconfig.build.json | 24 ------------------------ 9 files changed, 39 insertions(+), 37 deletions(-) delete mode 100755 tsconfig.build.json diff --git a/.gitignore b/.gitignore index a121e32..96df5c1 100755 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,8 @@ node_modules .idea # project folders +cjs dist* +esm lib out* diff --git a/package.json b/package.json index 29da630..5127e94 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "depcheck": "yarn dependency-check", "dependency-check": "run-p dependency-check:unused dependency-check:missing", "dependency-check:missing": "dependency-check . --missing --no-dev", - "dependency-check:unused": "dependency-check . --unused --no-dev -i typescript", + "dependency-check:unused": "dependency-check . --unused --no-dev -i flux-standard-action -i @types/fbemitter -i type-plus", "lint": "eslint --ext=ts,js .", "nuke": "yarn clean && rimraf node_modules", "release": "npx semantic-release", diff --git a/ts/Emitter.ts b/ts/Emitter.ts index cdad037..f31a238 100644 --- a/ts/Emitter.ts +++ b/ts/Emitter.ts @@ -19,10 +19,13 @@ export class Emitter { if (this.listenMisses.length > 0 && this.emitter.listeners(type).length === 0) this.listenMisses.forEach(l => l({ type, payload, meta, error })) } - + /** + * @param event TypedEvent created from `createEvent` or the event type in string. + */ addListener( event: TypedEvent | string, - listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { const type = typeof event === 'string' ? event : event.type if (type === errorEvent.type) return this.addErrorEventListener(listener) @@ -37,17 +40,26 @@ export class Emitter { } return this.emitter.addListener(type, wrappedListener) } - on(event: TypedEvent | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + on( + event: TypedEvent | string, + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { return this.addListener(event, listener) } - once(event: TypedEvent | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + once( + event: TypedEvent | string, + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { const type = typeof event === 'string' ? event : event.type return this.emitter.once(type, listener) } /** * Gets into a queue and listen to one event. */ - queue(event: TypedEvent | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + queue( + event: TypedEvent | string, + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { const type = typeof event === 'string' ? event : event.type const queue = this.eventQueues[type] = this.eventQueues[type] || [] const wrap = (payload: Payload, meta: Meta, error: boolean) => { @@ -93,7 +105,9 @@ export class Emitter { } } - protected addErrorEventListener(listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + protected addErrorEventListener( + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { const wrappedListener = (payload: Payload, meta: Meta, error: boolean) => { try { listener(payload, meta, error) diff --git a/ts/TestEmitter.ts b/ts/TestEmitter.ts index 0ab1ed6..e1b3c43 100644 --- a/ts/TestEmitter.ts +++ b/ts/TestEmitter.ts @@ -68,7 +68,9 @@ export class TestEmitter extends Emitter { return this.listenedToEventArray(keys.map(k => events[k])) } - protected addErrorEventListener(listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription { + protected addErrorEventListener( + listener: (payload: Payload, meta: Meta, error: boolean) => void + ): EventSubscription { return this.emitter.addListener(errorEvent.type, listener) } } diff --git a/ts/createEvent.spec.ts b/ts/createEvent.spec.ts index 19e8110..bfbbeb8 100644 --- a/ts/createEvent.spec.ts +++ b/ts/createEvent.spec.ts @@ -4,11 +4,11 @@ import { isFSA, isError } from 'flux-standard-action' import { createEvent, createScopedCreateEvent } from './index' test('empty eventCreator creates FSA compliant action', () => { - const blip = createEvent('blip') + const beep = createEvent('beep') // want undefined parameters optional // waiting for https://github.com/Microsoft/TypeScript/issues/12400 - t(isFSA(blip(undefined, undefined))) + t(isFSA(beep(undefined, undefined))) }) test('eventCreator with payload creates FSA compliant action', () => { diff --git a/ts/createEvent.ts b/ts/createEvent.ts index 913a208..de5a266 100644 --- a/ts/createEvent.ts +++ b/ts/createEvent.ts @@ -15,7 +15,13 @@ export function createScopedCreateEvent(scope: string): typeof createEvent { return (type) => createEvent(`${scope}/${type}`) } -export function createEvent(type: string, isError: ((payload: Payload) => boolean) | boolean = defaultIsErrorPredicate): Event { +export function createEvent< + Payload = undefined, + Meta = undefined +>( + type: string, + isError: ((payload: Payload) => boolean) | boolean = defaultIsErrorPredicate +): Event { return Object.assign( (payload: Payload, meta: Meta) => { return isError && (typeof isError === 'boolean' || isError(payload)) ? diff --git a/ts/setupCommandTest.ts b/ts/setupCommandTest.ts index 6c06f94..a2ababa 100644 --- a/ts/setupCommandTest.ts +++ b/ts/setupCommandTest.ts @@ -2,7 +2,10 @@ import { Command } from './Command' import { Emitter } from './Emitter' import { TestEmitter } from './TestEmitter' -export function setupCommandTest(Command: new (emitter: Emitter, ...args: Args) => Cmd, ...args: Args) { +export function setupCommandTest( + Command: new (emitter: Emitter, ...args: Args) => Cmd, + ...args: Args +) { const emitter = new TestEmitter() const command = new Command(emitter, ...args) return { emitter, command } diff --git a/tsconfig.base.json b/tsconfig.base.json index 0b152ca..d376d5a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -8,7 +8,6 @@ "newLine": "LF", "noUnusedLocals": true, "noUnusedParameters": false, - "removeComments": true, "sourceMap": true, "strict": true, "stripInternal": true, diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100755 index ee48fb0..0000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "esModuleInterop": true, - "lib": [ - "es2015" - ], - "module": "commonjs", - "moduleResolution": "node", - "newLine": "LF", - "noUnusedLocals": true, - "noUnusedParameters": false, - "outDir": "lib", - "removeComments": false, - "sourceMap": true, - "strict": true - }, - "include": [ - "typings" - ], - "files": [ - "src/index.ts" - ] -}