11import { $ , componentQrl , noSerialize } from '@qwik.dev/core' ;
22import { describe , expect , it , vi } from 'vitest' ;
3- import { _createDeserializeContainer } from './serdes.public' ;
4- import { _dumpState } from './dump-state' ;
5- import { createSerializationContext } from './serialization-context' ;
6- import { _typeIdNames } from './constants' ;
7- import { TypeIds } from './constants' ;
83import { _fnSignal , _wrapProp } from '../../internal' ;
4+ import type { SerializerSignalImpl } from '../../reactive-primitives/impl/serializer-signal-impl' ;
95import { type SignalImpl } from '../../reactive-primitives/impl/signal-impl' ;
106import { createStore } from '../../reactive-primitives/impl/store' ;
117import { createAsyncComputedSignal } from '../../reactive-primitives/signal-api' ;
128import {
139 createComputedQrl ,
14- createSerializerQrl ,
10+ createSerializer$ ,
1511 createSignal ,
1612 isSignal ,
1713} from '../../reactive-primitives/signal.public' ;
@@ -29,9 +25,12 @@ import { createQRL, type QRLInternal } from '../qrl/qrl-class';
2925import { isQrl } from '../qrl/qrl-utils' ;
3026import { EMPTY_ARRAY , EMPTY_OBJ } from '../utils/flyweight' ;
3127import { retryOnPromise } from '../utils/promises' ;
32- import { NoSerializeSymbol , SerializerSymbol , verifySerializable } from './verify' ;
33- import { _constants } from './constants' ;
28+ import { _constants , _typeIdNames , TypeIds } from './constants' ;
29+ import { _dumpState } from './dump-state' ;
30+ import { _createDeserializeContainer } from './serdes.public' ;
31+ import { createSerializationContext } from './serialization-context' ;
3432import { _serializationWeakRef } from './serialize' ;
33+ import { NoSerializeSymbol , SerializerSymbol , verifySerializable } from './verify' ;
3534
3635const DEBUG = false ;
3736
@@ -561,37 +560,65 @@ describe('shared-serialization', () => {
561560 ` ) ;
562561 } ) ;
563562 it ( title ( TypeIds . SerializerSignal ) , async ( ) => {
564- const custom = createSerializerQrl (
565- inlinedQrl < {
566- serialize : ( data : any | undefined ) => any ;
567- deserialize : ( data : any ) => any ;
568- initial ?: any ;
569- } > (
570- {
571- deserialize : ( n ?: number ) => new MyCustomSerializable ( n || 3 ) ,
572- serialize : ( obj ) => obj . n ,
573- } ,
574- 'custom_createSerializer_qrl'
575- )
576- ) ;
563+ const plain = createSerializer$ ( {
564+ deserialize : ( n ?: number ) => new MyCustomSerializable ( n || 3 ) ,
565+ serialize : ( obj ) => obj . n ,
566+ } ) ;
577567 // Force the value to be created
578- custom . value . inc ( ) ;
579- const objs = await serialize ( custom ) ;
568+ plain . value . inc ( ) ;
569+ const unread = createSerializer$ ( {
570+ deserialize : ( n ?: number ) => new MyCustomSerializable ( n || 3 ) ,
571+ serialize : ( obj ) => obj . n ,
572+ } ) ;
573+ const thunked = createSerializer$ ( ( ) => ( {
574+ deserialize : ( n ?: number ) => new MyCustomSerializable ( n || 3 ) ,
575+ serialize : ( obj ) => obj . n ,
576+ } ) ) ;
577+ const promised = createSerializer$ ( ( ) => ( {
578+ deserialize : ( n ?: number ) => new MyCustomSerializable ( n || 3 ) ,
579+ serialize : ( obj ) => obj . n ,
580+ } ) ) as any as SerializerSignalImpl < number , MyCustomSerializable > ;
581+ promised . $computeQrl$ . resolved = Promise . resolve ( promised . $computeQrl$ . resolved ) as any ;
582+
583+ const objs = await serialize ( [ plain , unread , thunked , promised ] ) ;
580584 expect ( _dumpState ( objs ) ) . toMatchInlineSnapshot ( `
581585 "
582- 0 ForwardRef 0
583- 1 PreloadQRL "2 3"
584- 2 {string} "mock-chunk"
585- 3 {string} "custom_createSerializer_qrl"
586- 4 SerializerSignal [
587- RootRef 1
586+ 0 Array [
587+ SerializerSignal [
588+ RootRef 1
589+ Constant undefined
590+ {number} 4
591+ ]
592+ SerializerSignal [
593+ RootRef 2
594+ Constant undefined
595+ Constant NEEDS_COMPUTATION
596+ ]
597+ SerializerSignal [
598+ RootRef 3
599+ Constant undefined
600+ Constant NEEDS_COMPUTATION
601+ ]
602+ ForwardRef 0
603+ ]
604+ 1 PreloadQRL "5 6"
605+ 2 PreloadQRL "5 7"
606+ 3 PreloadQRL "5 8"
607+ 4 PreloadQRL "5 9"
608+ 5 {string} "mock-chunk"
609+ 6 {string} "describe_describe_it_plain_createSerializer_IrZN04alftE"
610+ 7 {string} "describe_describe_it_unread_createSerializer_oYdaCRjw9Q0"
611+ 8 {string} "describe_describe_it_thunked_createSerializer_ufw7hr9vFDo"
612+ 9 {string} "describe_describe_it_promised_createSerializer_YCkDOYPyCO0"
613+ 10 SerializerSignal [
614+ RootRef 4
588615 Constant undefined
589- {number} 4
616+ Constant NEEDS_COMPUTATION
590617 ]
591- 5 ForwardRefs [
592- 4
618+ 11 ForwardRefs [
619+ 10
593620 ]
594- (85 chars)"
621+ (382 chars)"
595622 ` ) ;
596623 } ) ;
597624 it ( title ( TypeIds . AsyncComputedSignal ) , async ( ) => {
0 commit comments