4
4
* See License in the project root for license information.
5
5
* -------------------------------------------------------------------------------------------
6
6
*/
7
- import { type ParseNodeFactory , ParseNodeFactoryRegistry , type SerializationWriterFactory , SerializationWriterFactoryRegistry } from "./serialization" ;
8
- import { BackingStoreParseNodeFactory , BackingStoreSerializationWriterProxyFactory } from "./store" ;
7
+ import { ParseNodeFactoryRegistry , type SerializationWriterFactory , SerializationWriterFactoryRegistry } from "./serialization" ;
8
+ import { BackingStoreSerializationWriterProxyFactory } from "./store" ;
9
9
10
- /**
11
- * Registers the default serializer to the registry.
12
- * @param serializationWriterFactoryRegistry The registry to which the default serializer will be registered.
13
- * @param type the class of the factory to be registered.
14
- */
15
- export function registerDefaultSerializer ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , type : new ( ) => SerializationWriterFactory ) : void {
16
- if ( ! type ) throw new Error ( "Type is required" ) ;
17
- const serializer = new type ( ) ;
18
- serializationWriterFactoryRegistry . contentTypeAssociatedFactories . set ( serializer . getValidContentType ( ) , serializer ) ;
19
- }
20
- /**
21
- * Registers the default deserializer to the registry.
22
- * @param parseNodeFactoryRegistry The registry to which the default deserializer will be registered.
23
- * @param type the class of the factory to be registered.
24
- */
25
- export function registerDefaultDeserializer ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , type : new ( ) => ParseNodeFactory ) : void {
26
- if ( ! type ) throw new Error ( "Type is required" ) ;
27
- const deserializer = new type ( ) ;
28
- parseNodeFactoryRegistry . contentTypeAssociatedFactories . set ( deserializer . getValidContentType ( ) , deserializer ) ;
29
- }
30
10
/**
31
11
* Enables the backing store on default serialization writers and the given serialization writer.
32
12
* @param serializationWriterFactoryRegistry The serialization writer factory registry to enable the backing store on.
@@ -38,50 +18,11 @@ export function enableBackingStoreForSerializationWriterFactory(serializationWri
38
18
if ( ! original ) throw new Error ( "Original must be specified" ) ;
39
19
let result = original ;
40
20
if ( original instanceof SerializationWriterFactoryRegistry ) {
41
- enableBackingStoreForSerializationRegistry ( original ) ;
21
+ original . enableBackingStoreForSerializationRegistry ( ) ;
42
22
} else {
43
23
result = new BackingStoreSerializationWriterProxyFactory ( original ) ;
44
24
}
45
- enableBackingStoreForSerializationRegistry ( serializationWriterFactoryRegistry ) ;
46
- enableBackingStoreForParseNodeRegistry ( parseNodeFactoryRegistry ) ;
25
+ serializationWriterFactoryRegistry . enableBackingStoreForSerializationRegistry ( ) ;
26
+ parseNodeFactoryRegistry . enableBackingStoreForParseNodeRegistry ( ) ;
47
27
return result ;
48
28
}
49
- /**
50
- * Enables the backing store on default parse node factories and the given parse node factory.
51
- * @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
52
- * @param original The parse node factory to enable the backing store on.
53
- * @returns A new parse node factory with the backing store enabled.
54
- */
55
- export function enableBackingStoreForParseNodeFactory ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , original : ParseNodeFactory ) : ParseNodeFactory {
56
- if ( ! original ) throw new Error ( "Original must be specified" ) ;
57
- let result = original ;
58
- if ( original instanceof ParseNodeFactoryRegistry ) {
59
- enableBackingStoreForParseNodeRegistry ( original ) ;
60
- } else {
61
- result = new BackingStoreParseNodeFactory ( original ) ;
62
- }
63
- enableBackingStoreForParseNodeRegistry ( parseNodeFactoryRegistry ) ;
64
- return result ;
65
- }
66
- /**
67
- * Enables the backing store on the given parse node factory registry.
68
- * @param registry The parse node factory registry to enable the backing store on.
69
- */
70
- function enableBackingStoreForParseNodeRegistry ( registry : ParseNodeFactoryRegistry ) : void {
71
- for ( const [ k , v ] of registry . contentTypeAssociatedFactories ) {
72
- if ( ! ( v instanceof BackingStoreParseNodeFactory || v instanceof ParseNodeFactoryRegistry ) ) {
73
- registry . contentTypeAssociatedFactories . set ( k , new BackingStoreParseNodeFactory ( v ) ) ;
74
- }
75
- }
76
- }
77
- /**
78
- * Enables the backing store on the given serialization factory registry.
79
- * @param registry The serialization factory registry to enable the backing store on.
80
- */
81
- function enableBackingStoreForSerializationRegistry ( registry : SerializationWriterFactoryRegistry ) : void {
82
- for ( const [ k , v ] of registry . contentTypeAssociatedFactories ) {
83
- if ( ! ( v instanceof BackingStoreSerializationWriterProxyFactory || v instanceof SerializationWriterFactoryRegistry ) ) {
84
- registry . contentTypeAssociatedFactories . set ( k , new BackingStoreSerializationWriterProxyFactory ( v ) ) ;
85
- }
86
- }
87
- }
0 commit comments