Skip to content

Instantly share code, notes, and snippets.

@maciejsmolinski
Created February 20, 2015 09:06
Show Gist options
  • Save maciejsmolinski/3522ff919e95802004af to your computer and use it in GitHub Desktop.
Save maciejsmolinski/3522ff919e95802004af to your computer and use it in GitHub Desktop.
Wallet.js (PoC)
app.service('Wallet', function () {
function Wallet () {
this.total = 0;
}
Wallet.prototype.add = function (amount) {
this.total += Number(amount) || 0;
return this.total;
};
return Wallet;
});
app.service('WalletWithStorage', ['Wallet', function (Wallet) {
function WalletWithStorage () {
this.wallet = new Wallet();
}
WalletWithStorage.prototype.add = function (amount) {
this.wallet.add(amount);
localStorage.add(/* sth */);
return this.wallet.total;
};
return WalletWithStorage;
}]);
app.controller('WalletController', ['$scope', 'WalletWithStorage', function ($scope, WalletWithStorage) {
var wallet = new WalletWithStorage();
$scope.add = function () {
wallet.add(/* sth */);
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment