(
cls: SerializableConstructor<T>, pkg?: string, name?: string)
| 232 | * @doc {heading: 'Models', subheading: 'Serialization', ignoreCI: true} |
| 233 | */ |
| 234 | export function registerClass<T extends Serializable>( |
| 235 | cls: SerializableConstructor<T>, pkg?: string, name?: string) { |
| 236 | assert( |
| 237 | cls.className != null, |
| 238 | () => `Class being registered does not have the static className ` + |
| 239 | `property defined.`); |
| 240 | assert( |
| 241 | typeof cls.className === 'string', |
| 242 | () => `className is required to be a string, but got type ` + |
| 243 | typeof cls.className); |
| 244 | assert( |
| 245 | cls.className.length > 0, |
| 246 | () => `Class being registered has an empty-string as its className, ` + |
| 247 | `which is disallowed.`); |
| 248 | |
| 249 | if (typeof pkg === 'undefined') { |
| 250 | pkg = 'Custom'; |
| 251 | } |
| 252 | |
| 253 | if (typeof name === 'undefined') { |
| 254 | name = cls.className; |
| 255 | } |
| 256 | |
| 257 | const className = name; |
| 258 | const registerName = pkg + '>' + className; |
| 259 | |
| 260 | SerializationMap.register(cls); |
| 261 | GLOBAL_CUSTOM_OBJECT.set(registerName, cls); |
| 262 | GLOBAL_CUSTOM_NAMES.set(cls, registerName); |
| 263 | |
| 264 | return cls; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Get the registered name of a class. If the class has not been registered, |
no test coverage detected
searching dependent graphs…