@@ -166,6 +166,7 @@ export default class Model {
166166 }
167167
168168 constructor ( attributes ?: Object ) {
169+ this . _initializeAttributes ( ) ;
169170 this . attributes = attributes ;
170171 this . _originalAttributes = cloneDeep ( this . attributes ) ;
171172 this . _originalRelationships = this . relationshipResourceIdentifiers ( Object . keys ( this . relationships ) ) ;
@@ -266,6 +267,10 @@ export default class Model {
266267 return dc . checkRelation ( relationName , relatedModel ) ;
267268 }
268269
270+ dup ( ) : Model {
271+ return cloneDeep ( this ) ;
272+ }
273+
269274 destroy ( ) : Promise < any > {
270275 let url = this . klass . url ( this . id ) ;
271276 let verb = 'delete' ;
@@ -297,6 +302,15 @@ export default class Model {
297302 } ) ;
298303 }
299304
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+
300314 private _writeRequest ( requestPromise : Promise < any > , callback : Function ) : Promise < any > {
301315 return new Promise ( ( resolve , reject ) => {
302316 requestPromise . catch ( ( e ) => { throw ( e ) } ) ;
0 commit comments