@@ -29,7 +29,7 @@ type Actions<T extends Detail = Detail, A extends string = string> =
2929 * @template T - The type of items in the picker.
3030 * @template A - The type representing the default action name.
3131 */
32- export type ItemPickerParams <
32+ export type PickerParams <
3333 T extends Detail = Detail ,
3434 A extends string = string ,
3535> = {
@@ -51,7 +51,7 @@ export type ItemPickerParams<
5151 * @template T - The type of items handled by the picker.
5252 * @template A - The type representing the default action name.
5353 */
54- export type DefineItemPickerFromSource = < T extends Detail , A extends string > (
54+ export type DefinePickerFromSource = < T extends Detail , A extends string > (
5555 name : string ,
5656 source : Derivable < Source < T > > ,
5757 params : {
@@ -74,7 +74,7 @@ export type DefineItemPickerFromSource = <T extends Detail, A extends string>(
7474 * @template T - The type of items handled by the picker.
7575 * @template A - The type representing the default action name.
7676 */
77- export type DefineItemPickerFromCurator = < T extends Detail , A extends string > (
77+ export type DefinePickerFromCurator = < T extends Detail , A extends string > (
7878 name : string ,
7979 curator : Derivable < Curator < T > > ,
8080 params : {
@@ -91,29 +91,17 @@ export type DefineItemPickerFromCurator = <T extends Detail, A extends string>(
9191/**
9292 * Builds a function to define an item picker based on a source and matchers with the given map.
9393 *
94- * @param itemPickerParamsMap - The map to store the defined item pickers.
94+ * @param pickerParamsMap - The map to store the defined item pickers.
9595 * @returns The function to define an item picker based on a source and matchers.
9696 */
97- export function buildDefineItemPickerFromSource (
98- itemPickerParamsMap : Map < string , ItemPickerParams < Detail > > ,
99- ) : DefineItemPickerFromSource {
100- function validatePickerName ( name : string ) : void {
101- if ( itemPickerParamsMap . has ( name ) ) {
102- throw new Error ( `Item picker "${ name } " is already defined.` ) ;
103- }
104- if ( name . startsWith ( "@" ) ) {
105- throw new Error ( `Name "${ name } " must not start with "@".` ) ;
106- }
107- }
97+ export function buildDefinePickerFromSource (
98+ pickerParamsMap : Map < string , PickerParams < Detail > > ,
99+ ) : DefinePickerFromSource {
108100 return (
109101 name ,
110102 source ,
111103 params ,
112104 ) => {
113- if ( itemPickerParamsMap . has ( name ) ) {
114- throw new Error ( `Item picker "${ name } " is already defined.` ) ;
115- }
116- validatePickerName ( name ) ;
117105 const derivedParams = omitUndefinedAttributes ( {
118106 actions : deriveMap ( params . actions ) as Actions ,
119107 defaultAction : params . defaultAction ,
@@ -126,38 +114,28 @@ export function buildDefineItemPickerFromSource(
126114 coordinator : derive ( params . coordinator ) ,
127115 theme : derive ( params . theme ) ,
128116 } ) ;
129- validateActions ( derivedParams . actions ) ;
130- itemPickerParamsMap . set ( name , {
117+ pickerParamsMap . set ( name , {
131118 ...derivedParams ,
132119 name,
133120 source : derive ( source ) ,
134- } as ItemPickerParams < Detail , string > ) ;
121+ } as PickerParams < Detail , string > ) ;
135122 } ;
136123}
137124
138125/**
139126 * Builds a function to define an item picker based on a curator with the given map.
140127 *
141- * @param itemPickerParamsMap - The map to store the defined item pickers.
128+ * @param pickerParamsMap - The map to store the defined item pickers.
142129 * @returns The function to define an item picker based on a curator.
143130 */
144- export function buildDefineItemPickerFromCurator (
145- itemPickerParamsMap : Map < string , ItemPickerParams < Detail > > ,
146- ) : DefineItemPickerFromCurator {
147- function validatePickerName ( name : string ) : void {
148- if ( itemPickerParamsMap . has ( name ) ) {
149- throw new Error ( `Item picker "${ name } " is already defined.` ) ;
150- }
151- if ( name . startsWith ( "@" ) ) {
152- throw new Error ( `Name "${ name } " must not start with "@".` ) ;
153- }
154- }
131+ export function buildDefinePickerFromCurator (
132+ pickerParamsMap : Map < string , PickerParams < Detail > > ,
133+ ) : DefinePickerFromCurator {
155134 return (
156135 name ,
157136 curator ,
158137 params ,
159138 ) => {
160- validatePickerName ( name ) ;
161139 const source = new CuratorSourceMatcher ( derive ( curator ) ) ;
162140 const derivedParams = omitUndefinedAttributes ( {
163141 actions : deriveMap ( params . actions ) as Actions ,
@@ -170,8 +148,7 @@ export function buildDefineItemPickerFromCurator(
170148 coordinator : derive ( params . coordinator ) ,
171149 theme : derive ( params . theme ) ,
172150 } ) ;
173- validateActions ( derivedParams . actions ) ;
174- itemPickerParamsMap . set ( name , {
151+ pickerParamsMap . set ( name , {
175152 ...derivedParams ,
176153 name,
177154 source,
@@ -231,11 +208,3 @@ function omitUndefinedAttributes<
231208 Object . entries ( map ) . filter ( ( [ , v ] ) => v !== undefined ) ,
232209 ) as R ;
233210}
234-
235- function validateActions ( actions : Record < string , Action > ) : void {
236- Object . entries ( actions ) . forEach ( ( [ name , _action ] ) => {
237- if ( name . startsWith ( "@" ) ) {
238- throw new Error ( `Action name "${ name } " must not start with "@".` ) ;
239- }
240- } ) ;
241- }
0 commit comments