Skip to content

Commit

Permalink
fix: update comments
Browse files Browse the repository at this point in the history
and keep comments
  • Loading branch information
unional committed Apr 22, 2022
1 parent 2872716 commit 769ee64
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ node_modules
.idea

# project folders
cjs
dist*
esm
lib
out*
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 20 additions & 6 deletions ts/Emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Payload, Meta>(
event: TypedEvent<Payload, Meta> | 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)
Expand All @@ -37,17 +40,26 @@ export class Emitter {
}
return this.emitter.addListener(type, wrappedListener)
}
on<Payload, Meta>(event: TypedEvent<Payload, Meta> | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription {
on<Payload, Meta>(
event: TypedEvent<Payload, Meta> | string,
listener: (payload: Payload, meta: Meta, error: boolean) => void
): EventSubscription {
return this.addListener(event, listener)
}
once<Payload, Meta>(event: TypedEvent<Payload, Meta> | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription {
once<Payload, Meta>(
event: TypedEvent<Payload, Meta> | 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<Payload, Meta>(event: TypedEvent<Payload, Meta> | string, listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription {
queue<Payload, Meta>(
event: TypedEvent<Payload, Meta> | 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) => {
Expand Down Expand Up @@ -93,7 +105,9 @@ export class Emitter {
}
}

protected addErrorEventListener<Payload, Meta>(listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription {
protected addErrorEventListener<Payload, Meta>(
listener: (payload: Payload, meta: Meta, error: boolean) => void
): EventSubscription {
const wrappedListener = (payload: Payload, meta: Meta, error: boolean) => {
try {
listener(payload, meta, error)
Expand Down
4 changes: 3 additions & 1 deletion ts/TestEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export class TestEmitter extends Emitter {
return this.listenedToEventArray(keys.map(k => events[k]))
}

protected addErrorEventListener<Payload, Meta>(listener: (payload: Payload, meta: Meta, error: boolean) => void): EventSubscription {
protected addErrorEventListener<Payload, Meta>(
listener: (payload: Payload, meta: Meta, error: boolean) => void
): EventSubscription {
return this.emitter.addListener(errorEvent.type, listener)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ts/createEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 7 additions & 1 deletion ts/createEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export function createScopedCreateEvent(scope: string): typeof createEvent {
return (type) => createEvent(`${scope}/${type}`)
}

export function createEvent<Payload = undefined, Meta = undefined>(type: string, isError: ((payload: Payload) => boolean) | boolean = defaultIsErrorPredicate): Event<Payload, Meta> {
export function createEvent<
Payload = undefined,
Meta = undefined
>(
type: string,
isError: ((payload: Payload) => boolean) | boolean = defaultIsErrorPredicate
): Event<Payload, Meta> {
return Object.assign(
(payload: Payload, meta: Meta) => {
return isError && (typeof isError === 'boolean' || isError(payload)) ?
Expand Down
5 changes: 4 additions & 1 deletion ts/setupCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Command } from './Command'
import { Emitter } from './Emitter'
import { TestEmitter } from './TestEmitter'

export function setupCommandTest<Cmd extends Command, Args extends any[]>(Command: new (emitter: Emitter, ...args: Args) => Cmd, ...args: Args) {
export function setupCommandTest<Cmd extends Command, Args extends any[]>(
Command: new (emitter: Emitter, ...args: Args) => Cmd,
...args: Args
) {
const emitter = new TestEmitter()
const command = new Command(emitter, ...args)
return { emitter, command }
Expand Down
1 change: 0 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"newLine": "LF",
"noUnusedLocals": true,
"noUnusedParameters": false,
"removeComments": true,
"sourceMap": true,
"strict": true,
"stripInternal": true,
Expand Down
24 changes: 0 additions & 24 deletions tsconfig.build.json

This file was deleted.

0 comments on commit 769ee64

Please sign in to comment.