Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const model = classDecorator((
Class,
name = Class.name,
options = {auto: false},
) => {
if (is.obj(name)) {
options = merge(options, name)
name = Class.name
}
const {preProcessSnapshot, postProcessSnapshot} = Class
// TS class property initializers and defaults from constructor
const values = new Class()
const {onSnapshot, onPatch, onAction} = values
let props = extractTaggedProps(Class, PropsKey)
props = pipe(
rdMap(args => args[0]),
convertValuesToMst,
)(props)
const propKeys = Object.keys(props)
const viewKeys = Object.keys(extractTaggedProps(Class, ViewsKey))
Model = Model.preProcessSnapshot(snapshot => {
snapshot = preProcessSnapshot ? preProcessSnapshot(snapshot) : snapshot
if (!is.obj(snapshot)) {
if (!options.auto) return snapshot
snapshot = {}
}
return merge(values, snapshot)
})