Skip to content

Commit

Permalink
feat: make the conditional order factory case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Dec 2, 2024
1 parent 5ad85a1 commit d8e9e4a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/composable/ConditionalOrderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@ import { ConditionalOrderParams } from './types'
export type FromParams<D, S> = (params: ConditionalOrderParams) => ConditionalOrder<D, S>
export type ConditionalOrderRegistry = Record<string, FromParams<unknown, unknown>>

/**
* Factory for conditional orders.
*
* It uses a registry to instantiate the correct conditional order based on the handler.
*
* Knowing the handler, the factory will instantiate the correct conditional order using the staticInput data.
*/
export class ConditionalOrderFactory {
public knownOrderTypes

constructor(registry: ConditionalOrderRegistry) {
this.knownOrderTypes = registry
// Normalize the keys to lowercase
this.knownOrderTypes = Object.entries(registry).reduce<ConditionalOrderRegistry>((acc, [key, value]) => {
acc[key.toLowerCase()] = value
return acc
}, {})
}

/**
* Get the conditional order factory from the conditional order parameters
*/
public fromParams(params: ConditionalOrderParams): ConditionalOrder<unknown, unknown> | undefined {
const { handler } = params

const factory = this.knownOrderTypes[handler]
const factory = this.knownOrderTypes[handler.toLocaleLowerCase()]
if (!factory) {
return undefined
}
Expand Down

0 comments on commit d8e9e4a

Please sign in to comment.