From aa4d767204d4ece9ccc1960de68212feac7f659d Mon Sep 17 00:00:00 2001 From: Raghu-Ch Date: Tue, 14 Feb 2017 00:32:39 -0800 Subject: [PATCH] Understanding promises --- build/app.bundle.js | 156 +++++++++++++++++++++++++++++++++ build/app.bundle.js.map | 1 + build/ratefinder.bundle.js | 94 ++++++++++++++++++++ build/ratefinder.bundle.js.map | 1 + js/rate-service-mock.js | 20 +++++ js/ratefinder.js | 10 +++ ratefinder.html | 13 +++ webpack.config.js | 7 +- 8 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 build/app.bundle.js create mode 100644 build/app.bundle.js.map create mode 100644 build/ratefinder.bundle.js create mode 100644 build/ratefinder.bundle.js.map create mode 100644 js/rate-service-mock.js create mode 100644 js/ratefinder.js create mode 100644 ratefinder.html diff --git a/build/app.bundle.js b/build/app.bundle.js new file mode 100644 index 0000000..fee1df9 --- /dev/null +++ b/build/app.bundle.js @@ -0,0 +1,156 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 1); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Mortgage = function () { + function Mortgage(principal, years, rate) { + _classCallCheck(this, Mortgage); + + this.principal = principal; + this.years = years; + this.rate = rate; + } + + _createClass(Mortgage, [{ + key: "monthlyPayment", + get: function get() { + var monthlyRate = this.rate / 100 / 12; + return this.principal * monthlyRate / (1 - Math.pow(1 / (1 + monthlyRate), this.years * 12)); + } + }, { + key: "amortization", + get: function get() { + var monthlyPayment = this.monthlyPayment; + var monthlyRate = this.rate / 100 / 12; + var balance = this.principal; + var amortization = []; + for (var y = 0; y < this.years; y++) { + var interestY = 0; + var principalY = 0; + for (var m = 0; m < 12; m++) { + var interestM = balance * monthlyRate; + var principalM = monthlyPayment - interestM; + interestY = interestY + interestM; + principalY = principalY + principalM; + balance = balance - principalM; + } + amortization.push({ principalY: principalY, interestY: interestY, balance: balance }); + } + return amortization; + } + }]); + + return Mortgage; +}(); + +exports.default = Mortgage; + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var _mortgage = __webpack_require__(0); + +var _mortgage2 = _interopRequireDefault(_mortgage); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +document.getElementById('calcBtn').addEventListener('click', function () { + var principal = document.getElementById("principal").value; + var years = document.getElementById("years").value; + var rate = document.getElementById("rate").value; + var mortgage = new _mortgage2.default(principal, years, rate); + document.getElementById("monthlyPayment").innerHTML = mortgage.monthlyPayment.toFixed(2); + document.getElementById("monthlyRate").innerHTML = (rate / 12).toFixed(2); + var html = ""; + mortgage.amortization.forEach(function (year, index) { + return html += '\n \n ' + (index + 1) + '\n ' + Math.round(year.principalY) + '\n \n
\n
\n
\n
\n
\n
\n \n ' + Math.round(year.interestY) + '\n ' + Math.round(year.balance) + '\n \n '; + }); + document.getElementById("amortization").innerHTML = html; +}); + +/***/ }) +/******/ ]); +//# sourceMappingURL=app.bundle.js.map \ No newline at end of file diff --git a/build/app.bundle.js.map b/build/app.bundle.js.map new file mode 100644 index 0000000..8d9c245 --- /dev/null +++ b/build/app.bundle.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap 71264ee56fb5fabb88c9","webpack:///./js/mortgage2.js","webpack:///./js/main.js"],"names":["Mortgage","principal","years","rate","monthlyRate","Math","pow","monthlyPayment","balance","amortization","y","interestY","principalY","m","interestM","principalM","push","document","getElementById","addEventListener","value","mortgage","innerHTML","toFixed","html","forEach","year","index","round"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA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[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 71264ee56fb5fabb88c9","export default class Mortgage {\r\n constructor(principal, years, rate) {\r\n this.principal = principal;\r\n this.years = years;\r\n this.rate = rate;\r\n }\r\n\r\n get monthlyPayment() {\r\n let monthlyRate = this.rate / 100 / 12;\r\n return this.principal * monthlyRate / (1 - (Math.pow(1/(1 + monthlyRate),\r\n this.years * 12)));\r\n }\r\n\r\n get amortization() {\r\n let monthlyPayment = this.monthlyPayment;\r\n let monthlyRate = this.rate / 100 / 12;\r\n let balance = this.principal;\r\n let amortization = [];\r\n for (let y=0; y {\r\n let principal = document.getElementById(\"principal\").value;\r\n let years = document.getElementById(\"years\").value;\r\n let rate = document.getElementById(\"rate\").value;\r\n let mortgage = new Mortgage(principal, years, rate);\r\n document.getElementById(\"monthlyPayment\").innerHTML = mortgage.monthlyPayment.toFixed(2);\r\n document.getElementById(\"monthlyRate\").innerHTML = (rate / 12).toFixed(2);\r\n let html = \"\";\r\n mortgage.amortization.forEach((year, index) => html += `\r\n \r\n ${index + 1}\r\n ${Math.round(year.principalY)}\r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n \r\n ${Math.round(year.interestY)}\r\n ${Math.round(year.balance)}\r\n \r\n `);\r\n document.getElementById(\"amortization\").innerHTML = html;\r\n\r\n});\r\n\n\n\n// WEBPACK FOOTER //\n// ./js/main.js"],"sourceRoot":""} \ No newline at end of file diff --git a/build/ratefinder.bundle.js b/build/ratefinder.bundle.js new file mode 100644 index 0000000..de69011 --- /dev/null +++ b/build/ratefinder.bundle.js @@ -0,0 +1,94 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 2); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ 2: +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var url = "rates.json"; + +fetch(url).then(function (response) { + return response.json(); +}).then(function (rates) { + var html = ''; + rates.forEach(function (rate) { + return html += "" + rate.name + "" + rate.years + "" + rate.rate + "%"; + }); + document.getElementById("rates").innerHTML = html; +}).catch(function (e) { + return console.log(e); +}); + +/***/ }) + +/******/ }); +//# sourceMappingURL=ratefinder.bundle.js.map \ No newline at end of file diff --git a/build/ratefinder.bundle.js.map b/build/ratefinder.bundle.js.map new file mode 100644 index 0000000..aa11e90 --- /dev/null +++ b/build/ratefinder.bundle.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap 71264ee56fb5fabb88c9?9f3c","webpack:///./js/ratefinder.js"],"names":["url","fetch","then","response","json","html","rates","forEach","rate","name","years","document","getElementById","innerHTML","catch","console","log","e"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;AChEA,IAAIA,MAAM,YAAV;;AAEAC,MAAMD,GAAN,EACKE,IADL,CACU;AAAA,SAAYC,SAASC,IAAT,EAAZ;AAAA,CADV,EAEKF,IAFL,CAEU,iBAAS;AACb,MAAIG,OAAO,EAAX;AACAC,QAAMC,OAAN,CAAc;AAAA,WAAQF,qBAAmBG,KAAKC,IAAxB,iBAAwCD,KAAKE,KAA7C,iBAA8DF,KAAKA,IAAnE,gBAAR;AAAA,GAAd;AACAG,WAASC,cAAT,CAAwB,OAAxB,EAAiCC,SAAjC,GAA6CR,IAA7C;AACD,CANL,EAOKS,KAPL,CAOW;AAAA,SAAKC,QAAQC,GAAR,CAAYC,CAAZ,CAAL;AAAA,CAPX,E","file":"ratefinder.bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 71264ee56fb5fabb88c9","let url = \"rates.json\";\r\n\r\nfetch(url)\r\n .then(response => response.json())\r\n .then(rates => {\r\n let html = '';\r\n rates.forEach(rate => html += `${rate.name}${rate.years}${rate.rate}%`);\r\n document.getElementById(\"rates\").innerHTML = html;\r\n })\r\n .catch(e => console.log(e));\r\n\n\n\n// WEBPACK FOOTER //\n// ./js/ratefinder.js"],"sourceRoot":""} \ No newline at end of file diff --git a/js/rate-service-mock.js b/js/rate-service-mock.js new file mode 100644 index 0000000..39a9bba --- /dev/null +++ b/js/rate-service-mock.js @@ -0,0 +1,20 @@ +let rates = [ + { + "name": "30 years fixed", + "rate": "13", + "years": "30" + }, + { + "name": "20 years fixed", + "rate": "2.8", + "years": "20" + } +]; + +export let findAll = () => new Promise((resolve, reject) => { + if (rates) { + resolve(rates); + } else { + reject("No rates"); + } +}); diff --git a/js/ratefinder.js b/js/ratefinder.js new file mode 100644 index 0000000..2943400 --- /dev/null +++ b/js/ratefinder.js @@ -0,0 +1,10 @@ +let url = "rates.json"; + +fetch(url) + .then(response => response.json()) + .then(rates => { + let html = ''; + rates.forEach(rate => html += `${rate.name}${rate.years}${rate.rate}%`); + document.getElementById("rates").innerHTML = html; + }) + .catch(e => console.log(e)); diff --git a/ratefinder.html b/ratefinder.html new file mode 100644 index 0000000..d4ff113 --- /dev/null +++ b/ratefinder.html @@ -0,0 +1,13 @@ + + + + + + + RateFinder + + +
+ + + diff --git a/webpack.config.js b/webpack.config.js index fc314e7..88245c2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,10 +2,13 @@ var path = require('path'); var webpack = require('webpack'); module.exports = { - entry: './js/main.js', + entry: { + app: './js/main.js', + ratefinder: './js/ratefinder.js' + }, output: { path: path.resolve(__dirname, 'build'), - filename: 'main.bundle.js' + filename: '[name].bundle.js' }, module: { loaders: [