denostack / superserial

A comprehensive Serializer/Deserializer that can handle any data type.
MIT License
35 stars 3 forks source link

Lazy class linking #4

Closed wan2land closed 1 year ago

wan2land commented 1 year ago

tIn the process of deserialization, if a class cannot be found, a warning is issued to the console.
Replace it with a function.

deserialize("...", {
  loadClass: (name: string): ConstructorType | null | undefined => {
    /* find class name */
    const class = findClass(name)
    if (!class) {
      console.warn(`Class ${name} is not defined. It will be ignored.`);
    }
    return class
  }
})

default loadClass

const defaultLoadClass = (name: string): ConstructorType | null | undefined => {
  console.warn(`Class ${name} is not defined. It will be ignored.`);
}