| Index: chrome/third_party/mock4js/examples/PriceService.js
|
| diff --git a/chrome/third_party/mock4js/examples/PriceService.js b/chrome/third_party/mock4js/examples/PriceService.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f20aa9394c53dfd3f35f04e934951d2e2df212b4
|
| --- /dev/null
|
| +++ b/chrome/third_party/mock4js/examples/PriceService.js
|
| @@ -0,0 +1,43 @@
|
| +/**
|
| + * PriceCache
|
| + */
|
| +function PriceCache() {
|
| +}
|
| +
|
| +PriceCache.prototype = {
|
| + getCachedPrice: function(instrumentId) {
|
| + },
|
| + setCachedPrice: function(instrumentId, price) {
|
| + }
|
| +}
|
| +
|
| +/**
|
| + * PriceFetcher
|
| + */
|
| +function PriceFetcher() {
|
| +}
|
| +
|
| +PriceFetcher.prototype = {
|
| + getPriceFromServer: function(instrumentId) {
|
| + }
|
| +}
|
| +
|
| +
|
| +/**
|
| + * PriceService
|
| + */
|
| +function PriceService(priceFetcher, priceCache) {
|
| + this._priceFetcher = priceFetcher;
|
| + this._priceCache = priceCache;
|
| +}
|
| +
|
| +PriceService.prototype = {
|
| + getPrice: function(instrumentId) {
|
| + var price = this._priceCache.getCachedPrice(instrumentId);
|
| + if(price==null) {
|
| + price = this._priceFetcher.getPriceFromServer(instrumentId);
|
| + this._priceCache.setCachedPrice(instrumentId, price);
|
| + }
|
| + return price;
|
| + }
|
| +}
|
|
|