Skip to content

Commit

Permalink
Fixed #12 and added 2 new methods: and
Browse files Browse the repository at this point in the history
  • Loading branch information
klederson committed Jul 6, 2013
1 parent 65ce09c commit 5953816
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,31 @@ Will return something like as a Javascript Object
}
```
### model.$reset()
> This cleanup the current model based on model.$mapping ( pre or post mapped )
```javascript
model.$reset()
```
or
```javascript
var myModel = model.$reset()
```
### model.$resetTo(data)
> This cleanup the current model and populate with given new one based on model.$mapping ( pre or post mapped )
```javascript
model.$resetTo({idUser : 2, name : "Klederson"});
```
or
```javascript
var myModel = model.$resetTo({idUser : 2, name : "Klederson"});
```
### model.$original()
> Return a raw object with all **ORIGINAL** data of the model even if there are changes.
Expand Down
23 changes: 20 additions & 3 deletions src/ModelCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,28 @@

$offline : false, //@TODO future implementation

$resetTo : function(data) {
var self = this;
data = !data || {};
for(i in self.$mapping) {
self.__proto__[i] = typeof data[i] !== "undefined" ? data[i] : null;
}

return self;
},

$reset : function() {
return this.$resetTo({});
},

$new : function(data) {
var self = this;

data = typeof data == "undefined" ? {} : data;
return new new ModelCore.newInstance(data,self);

var o = new new ModelCore.newInstance({},self);

return self.$resetTo(data);
},
/**
* Just an alias to the iterator next();
Expand Down Expand Up @@ -445,7 +463,6 @@
}

ModelCore.newInstance = function(data,model) {
angular.extend(data,model)
return ModelCore.instance(data,model);
}

Expand Down Expand Up @@ -507,7 +524,7 @@

//Exend original methods and properties
if(original)
angular.extend(self.prototype, original.__proto__)
angular.extend(self.prototype, original.__proto__);

//Apply custom methods and attributes
if (props) {
Expand Down

0 comments on commit 5953816

Please sign in to comment.