Skip to content

Commit

Permalink
Merge pull request #12 from pyoung213/develop
Browse files Browse the repository at this point in the history
Adds update with PATCH feature.
  • Loading branch information
pyoung213 committed Apr 13, 2016
2 parents 58c7b80 + 98e824b commit 9a21c1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 327 deletions.
38 changes: 30 additions & 8 deletions activeAngular.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
angular
.module('activeAngular', []);
.module('activeAngular', ["ngSanitize"]);
})();

angular
Expand Down Expand Up @@ -39,6 +39,7 @@ angular
self.$get = $get;
self.$query = $query;
self.$save = $save;
self.$update = $update;
self.$remove = $remove;
self.$create = $create;
self.$$http = $$http;
Expand Down Expand Up @@ -145,7 +146,7 @@ angular
var item = this;

if (!options) {
return;
options = item;
}

if (options && !options.id) {
Expand All @@ -162,6 +163,27 @@ angular
});
}

function $update(options) {
var item = this;

if (!options) {
return;
}

if (options && !options.id) {
options.id = item.id;
}

var oldCopy = angular.copy(item);
var savedChanges = _.extend(item, options);
self.$cache.set(savedChanges.id, savedChanges);

return self.$$http('PATCH', options)
.catch(function() {
self.$cache.set(oldCopy.id, oldCopy);
});
}

function $remove(options) {
var item = this;

Expand Down Expand Up @@ -250,12 +272,7 @@ angular
}

function _hydrateCollection(collection) {
var data = {};

_.forEach(collection[self._collectionKey], function(value, key) {
data[key] = value
});
return data;
return collection[self._collectionKey];
}

function _hideMetadata(ref, data) {
Expand Down Expand Up @@ -533,6 +550,11 @@ angular
value: instance.$save
});

Object.defineProperty(self, '$update', {
enumerable: false,
value: instance.$update
});

Object.defineProperty(self, '$edge', {
enumerable: false,
value: instance.$edge
Expand Down
Loading

0 comments on commit 9a21c1a

Please sign in to comment.