Last active
November 10, 2018 21:10
-
-
Save kasper573/03e36681a5b3fde50e94e704baf5bdde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {getDefaultModelSchema, object, PropSchema} from 'serializr'; | |
/** | |
* A custom serializr schema that behaves like object() but requires the model later, allowing circular references. | |
*/ | |
export function fnObject<T> (getModel: () => new (...args: any[]) => T): PropSchema { | |
const getSchema = () => getDefaultModelSchema(getModel()); | |
return { | |
serializer: (...args: any[]) => (object(getSchema()).serializer as any)(...args), | |
deserializer: (...args: any[]) => (object(getModel()).deserializer as any)(...args) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@serializable(alias('mediakits', onlyIn(list(fnObject(() => require('./MediaKit').AnonymousMediaKit)))))
mediaKits: MediaKit[] = [];