|
|
|
@ -10,6 +10,7 @@ export default { |
|
|
|
initialize(models, opts = {}) { |
|
|
|
const { em } = opts; |
|
|
|
this.em = em; |
|
|
|
this.opts = opts; |
|
|
|
this.model = (attrs = {}, options = {}) => { |
|
|
|
let Model, View, type; |
|
|
|
|
|
|
|
@ -45,15 +46,12 @@ export default { |
|
|
|
for (let i = 0; i < types.length; i++) { |
|
|
|
const type = types[i]; |
|
|
|
let typeFound = type.isType(value); |
|
|
|
typeFound = |
|
|
|
typeof typeFound == 'boolean' && typeFound |
|
|
|
? { type: type.id } |
|
|
|
: typeFound; |
|
|
|
typeFound = typeof typeFound == 'boolean' && typeFound ? { type: type.id } : typeFound; |
|
|
|
|
|
|
|
if (typeFound) { |
|
|
|
return { |
|
|
|
type, |
|
|
|
attributes: typeFound |
|
|
|
attributes: typeFound, |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -61,7 +59,7 @@ export default { |
|
|
|
// If, for any reason, the type is not found it'll return the base one
|
|
|
|
return { |
|
|
|
type: this.getBaseType(), |
|
|
|
attributes: value |
|
|
|
attributes: value, |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
@ -117,14 +115,8 @@ export default { |
|
|
|
const ModelInst = type ? type.model : baseType.model; |
|
|
|
const ViewInst = type ? type.view : baseType.view; |
|
|
|
let { model, view, isType } = definition; |
|
|
|
model = |
|
|
|
model instanceof Model || isFunction(model) |
|
|
|
? model |
|
|
|
: ModelInst.extend(model || {}); |
|
|
|
view = |
|
|
|
view instanceof View || isFunction(view) |
|
|
|
? view |
|
|
|
: ViewInst.extend(view || {}); |
|
|
|
model = model instanceof Model || isFunction(model) ? model : ModelInst.extend(model || {}); |
|
|
|
view = view instanceof View || isFunction(view) ? view : ViewInst.extend(view || {}); |
|
|
|
|
|
|
|
// New API
|
|
|
|
if (this.extendViewApi && !definition.model && !definition.view) { |
|
|
|
@ -141,12 +133,12 @@ export default { |
|
|
|
definition.view = view; |
|
|
|
definition.isType = |
|
|
|
isType || |
|
|
|
function(value) { |
|
|
|
function (value) { |
|
|
|
if (value && value.type == id) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
}; |
|
|
|
this.getTypes().unshift(definition); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
|