Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit ec33dce

Browse files
committed
Shorter code
1 parent a4711fb commit ec33dce

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

examples/angular/app.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,17 @@ wishlistApp.factory('wishlistData', function($rootScope) {
115115
// This piece of code uses ``$rootScope`` from closure, and forces dirty checking
116116
// when the *daybed.js* promises are resolved/rejected.
117117
Promise.prototype.thenApply = function (onFulfilled, onRejected) {
118-
Promise.prototype.then.call(this,
119-
function onSuccess() {
120-
if (!onFulfilled) return;
121-
var args = arguments;
122-
$rootScope.$apply(function() {
123-
onFulfilled.apply(this, args);
124-
});
125-
},
126-
function onError() {
127-
if (!onRejected) return;
118+
Promise.prototype.then.call(this, applied(onFulfilled), applied(onRejected));
119+
120+
function applied(cb) {
121+
return function () {
122+
if (!cb) return;
128123
var args = arguments;
129124
$rootScope.$apply(function() {
130-
onRejected.apply(this, args);
125+
cb.apply(this, args);
131126
});
132-
}
133-
);
127+
};
128+
}
134129
};
135130

136131

0 commit comments

Comments
 (0)