Created
February 20, 2015 09:06
-
-
Save maciejsmolinski/3522ff919e95802004af to your computer and use it in GitHub Desktop.
Wallet.js (PoC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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