@@ -166,6 +166,7 @@ export default class Model {
166
166
}
167
167
168
168
constructor ( attributes ?: Object ) {
169
+ this . _initializeAttributes ( ) ;
169
170
this . attributes = attributes ;
170
171
this . _originalAttributes = cloneDeep ( this . attributes ) ;
171
172
this . _originalRelationships = this . relationshipResourceIdentifiers ( Object . keys ( this . relationships ) ) ;
@@ -266,6 +267,10 @@ export default class Model {
266
267
return dc . checkRelation ( relationName , relatedModel ) ;
267
268
}
268
269
270
+ dup ( ) : Model {
271
+ return cloneDeep ( this ) ;
272
+ }
273
+
269
274
destroy ( ) : Promise < any > {
270
275
let url = this . klass . url ( this . id ) ;
271
276
let verb = 'delete' ;
@@ -297,6 +302,15 @@ export default class Model {
297
302
} ) ;
298
303
}
299
304
305
+ // Define getter/setters and set defaults
306
+ private _initializeAttributes ( ) {
307
+ for ( let key in this . klass . attributeList ) {
308
+ let attr = this . klass . attributeList [ key ] ;
309
+ Object . defineProperty ( this , attr . name , attr . descriptor ( ) ) ;
310
+ this [ key ] = this [ key ] ; // set defaults
311
+ }
312
+ }
313
+
300
314
private _writeRequest ( requestPromise : Promise < any > , callback : Function ) : Promise < any > {
301
315
return new Promise ( ( resolve , reject ) => {
302
316
requestPromise . catch ( ( e ) => { throw ( e ) } ) ;
0 commit comments