Skip to content

Commit

Permalink
feat: add key getter to UseCase
Browse files Browse the repository at this point in the history
  • Loading branch information
achamorro-dev committed Nov 28, 2022
1 parent 79b1ed6 commit 495f34a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/arch/src/use-case/use-case.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CacheKey } from '../cache/cache-key'
import { USE_CASE_KEY } from '../cache/use-case-key'
import { Runner } from '../runner/runner'
import { ExecutionOptions } from './execution-options'

Expand All @@ -10,6 +12,12 @@ export abstract class UseCase<Result = void, Param = void> {
private static currentId = 0
private subscriptions = new Map<Id, Fn<Result, Param>>()

get key(): CacheKey {
return (
this.constructor.prototype?.[USE_CASE_KEY] ?? this.constructor.prototype?.[USE_CASE_KEY] ?? this.constructor.name
)
}

subscribe(fn: Fn<Result, Param>): Id {
const id = UseCase.currentId++
this.subscriptions.set(id, fn)
Expand Down

0 comments on commit 495f34a

Please sign in to comment.