Use static model factory methods

The `constructFromObject` factory methods should be class methods
(or "static" methods), not instance methods.

With this commit, ApiClient no longer calls the model constructors
directly. Instead, it calls the new static factory method to get the
new instance. If there is no data on the top level, null is returned.

It is still possible for users to call the model constructors
directly, of course.
This commit is contained in:
delenius
2016-02-10 13:35:24 -08:00
parent 847a8e1f3d
commit fa2333717a
15 changed files with 118 additions and 90 deletions

View File

@@ -250,8 +250,7 @@
default:
if (typeof type === 'function') {
// for model type like: User
var model = new type();
model.constructFromObject(data);
var model = type.constructFromObject(data);
return model;
} else if (Array.isArray(type)) {
// for array type like: ['String']