File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -372,6 +372,31 @@ Will return something like as a Javascript Object
372372}
373373` ` `
374374
375+ ### model.$reset()
376+ > This cleanup the current model based on model.$mapping ( pre or post mapped )
377+
378+ ` ` ` javascript
379+ model .$reset ()
380+ ` ` `
381+
382+ or
383+
384+ ` ` ` javascript
385+ var myModel = model .$reset ()
386+ ` ` `
387+
388+ ### model.$resetTo(data)
389+ > This cleanup the current model and populate with given new one based on model.$mapping ( pre or post mapped )
390+
391+ ` ` ` javascript
392+ model .$resetTo ({idUser : 2 , name : " Klederson" });
393+ ` ` `
394+
395+ or
396+
397+ ` ` ` javascript
398+ var myModel = model .$resetTo ({idUser : 2 , name : " Klederson" });
399+ ` ` `
375400
376401### model.$original()
377402> Return a raw object with all **ORIGINAL** data of the model even if there are changes.
Original file line number Diff line number Diff line change 8080
8181 $offline : false , //@TODO future implementation
8282
83+ $resetTo : function ( data ) {
84+ var self = this ;
85+ data = ! data || { } ;
86+ for ( i in self . $mapping ) {
87+ self . __proto__ [ i ] = typeof data [ i ] !== "undefined" ? data [ i ] : null ;
88+ }
89+
90+ return self ;
91+ } ,
92+
93+ $reset : function ( ) {
94+ return this . $resetTo ( { } ) ;
95+ } ,
96+
8397 $new : function ( data ) {
8498 var self = this ;
99+
85100 data = typeof data == "undefined" ? { } : data ;
86- return new new ModelCore . newInstance ( data , self ) ;
101+
102+ var o = new new ModelCore . newInstance ( { } , self ) ;
103+
104+ return self . $resetTo ( data ) ;
87105 } ,
88106 /**
89107 * Just an alias to the iterator next();
445463 }
446464
447465 ModelCore . newInstance = function ( data , model ) {
448- angular . extend ( data , model )
449466 return ModelCore . instance ( data , model ) ;
450467 }
451468
507524
508525 //Exend original methods and properties
509526 if ( original )
510- angular . extend ( self . prototype , original . __proto__ )
527+ angular . extend ( self . prototype , original . __proto__ ) ;
511528
512529 //Apply custom methods and attributes
513530 if ( props ) {
You can’t perform that action at this time.
0 commit comments