@@ -24,20 +24,37 @@ export function usePreviousIfDeeplyEqual<T>(val: T) {
2424}
2525
2626/**
27- * Calls method `setter ` on `box` with `value`, iff `value` is set & deeply
27+ * Calls method `method ` on `box` with `value`, iff `value` is set & deeply
2828 * different from before (and the box is alive)
2929 */
30- export function useSetter <
30+ export function useMethod <
3131 V ,
3232 S extends string ,
3333 T extends TalkObject & Record < S , ( val : V ) => any > ,
34- > ( box : T | undefined , value : V | undefined , setter : S ) {
34+ > ( box : T | undefined , value : V | undefined , method : S ) {
3535 value = usePreviousIfDeeplyEqual ( value ) ;
3636 useEffect ( ( ) => {
3737 if ( value !== undefined && box ?. isAlive ) {
38- box [ setter ] ( value ) ;
38+ box [ method ] ( value ) ;
3939 }
40- } , [ setter , box , value ] ) ;
40+ } , [ method , box , value ] ) ;
41+ }
42+
43+ /**
44+ * Like {@link useMethod}, except `args` is an array that gets spread into
45+ * the method call
46+ */
47+ export function useSpreadMethod <
48+ V extends any [ ] ,
49+ S extends string ,
50+ T extends TalkObject & Record < S , ( ...args : V ) => any > ,
51+ > ( box : T | undefined , args : V | undefined , method : S ) {
52+ args = usePreviousIfDeeplyEqual ( args ) ;
53+ useEffect ( ( ) => {
54+ if ( args !== undefined && box ?. isAlive ) {
55+ box [ method ] ( ...args ) ;
56+ }
57+ } , [ method , box , args ] ) ;
4158}
4259
4360/**
@@ -50,14 +67,20 @@ export function useConversation<T extends Talk.UIBox>(
5067 box : T | undefined ,
5168 syncConversation : ConversationProps [ "syncConversation" ] ,
5269 conversationId : ConversationProps [ "conversationId" ] ,
70+ asGuest : boolean | undefined ,
5371) {
5472 const conversation = useMemo ( ( ) => {
5573 if ( typeof syncConversation === "function" ) {
5674 return session ?. isAlive ? syncConversation ( session ) : undefined ;
5775 }
5876 return syncConversation ?? conversationId ;
5977 } , [ session , syncConversation , conversationId ] ) ;
60- useSetter ( box , conversation , "select" ) ;
78+
79+ const args = (
80+ conversation !== undefined ? [ conversation , { asGuest } ] : undefined
81+ ) as any ;
82+
83+ useSpreadMethod ( box , args , "select" ) ;
6184}
6285
6386// subset of Session to help TypeScript pick the right overloads
0 commit comments