Skip to content

Instantly share code, notes, and snippets.

@plwalters
Last active August 29, 2017 02:45
Show Gist options
  • Save plwalters/0f2eb8344824602579d1f08661a3299b to your computer and use it in GitHub Desktop.
Save plwalters/0f2eb8344824602579d1f08661a3299b to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<table>
<thead>
<tr>
<th>Date</th>
<th>Price</th>
<th>Amount</th>
<th>Total</th>
<th>Profit</th>
</tr>
</thead>
<tbody>
<tr repeat.for="item of items">
<td>${item.date}</td>
<td>${item.price}</td>
<td>${item.amount}</td>
<td>${item.total}</td>
<td>${item.profit}</td>
</tr>
</tbody>
</table>
<h2>Total Current Value - ${totalCurrentValue}</h2>
<h2>Initial Investment - ${totalInvestment}</h2>
<h2>Total Profit - ${totalProfit}</h2>
<h2>Percent Profit - ${percentProfit}</h2>
</template>
import {values} from './values';
export class App {
totalProfit = 0;
totalInvestment = 0;
totalCurrentValue = 0;
percent = 0;
attached() {
this.items = [];
this.currentPrice = 62.52;
this.items = values.map(value => {
let total = value.buy.total.amount;
let amount = value.amount.amount;
let price = (total / amount);
let currentValue = (this.currentPrice * amount);
let profit = (currentValue - total);
this.totalProfit += profit;
this.totalInvestment += parseFloat(total);
this.totalCurrentValue += currentValue;
return {
date: value.created_at,
price: price,
amount: amount,
total: total,
currentValue: currentValue,
profit: profit
};
});
this.percentProfit = (this.totalCurrentValue / this.totalInvestment);
}
}
import {inject} from 'aurelia-dependency-injection'
export class Action1Dependency {}
export class Action2Dependency {}
export class ActionBase{
}
@inject(Action1Dependency)
export class Action1 extends ActionBase{
constructor(dep){
super();
this.dep = dep;
}
}
@inject(Action2Dependency)
export class Action2 extends ActionBase{
constructor(dep){
super();
this.dep = dep;
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.0/chartist.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export const values = [
{
"id": "40cc2961-7317-57b8-9a6a-92e0e7e80101",
"type": "buy",
"status": "completed",
"amount": {
"amount": "20.00000000",
"currency": "LTC"
},
"native_amount": {
"amount": "853.22",
"currency": "USD"
},
"description": null,
"created_at": "2017-07-25T20:45:51Z",
"updated_at": "2017-07-25T20:45:53Z",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/40cc2961-7317-57b8-9a6a-92e0e7e80101",
"instant_exchange": false,
"buy": {
"id": "c15d711c-4bf4-583b-ba00-61e9b2857bf7",
"status": "completed",
"payment_method": {
"id": "9e401028-321c-5dce-bf89-1e209ff39ade",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/9e401028-321c-5dce-bf89-1e209ff39ade"
},
"transaction": {
"id": "40cc2961-7317-57b8-9a6a-92e0e7e80101",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/40cc2961-7317-57b8-9a6a-92e0e7e80101"
},
"user_reference": "8XMF6T43",
"created_at": "2017-07-25T20:45:35Z",
"updated_at": "2017-07-25T20:45:53Z",
"resource": "buy",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/buys/c15d711c-4bf4-583b-ba00-61e9b2857bf7",
"fee": {
"amount": "32.74",
"currency": "USD"
},
"amount": {
"amount": "20.00000000",
"currency": "LTC"
},
"total": {
"amount": "853.22",
"currency": "USD"
},
"subtotal": {
"amount": "820.48",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-07-25T20:45:34Z",
"instant": true,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/58f8aec9a68baf0224f79bf4/transactions/5977adfff22383000198c227",
"details": {
"title": "Bought litecoin",
"subtitle": "using Visa debit ********8539",
"payment_method_name": "Visa debit ********8539"
}
},
{
"id": "a288cd1b-648f-5132-9ee8-e8f71f56faa7",
"type": "buy",
"status": "completed",
"amount": {
"amount": "5.00000000",
"currency": "LTC"
},
"native_amount": {
"amount": "223.55",
"currency": "USD"
},
"description": null,
"created_at": "2017-07-17T17:36:59Z",
"updated_at": "2017-07-17T17:37:02Z",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/a288cd1b-648f-5132-9ee8-e8f71f56faa7",
"instant_exchange": false,
"buy": {
"id": "8a505fa2-170e-55ff-bb18-df704a50994d",
"status": "completed",
"payment_method": {
"id": "9e401028-321c-5dce-bf89-1e209ff39ade",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/9e401028-321c-5dce-bf89-1e209ff39ade"
},
"transaction": {
"id": "a288cd1b-648f-5132-9ee8-e8f71f56faa7",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/a288cd1b-648f-5132-9ee8-e8f71f56faa7"
},
"user_reference": "52HTP7B8",
"created_at": "2017-07-17T17:36:56Z",
"updated_at": "2017-07-17T17:37:02Z",
"resource": "buy",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/buys/8a505fa2-170e-55ff-bb18-df704a50994d",
"fee": {
"amount": "8.58",
"currency": "USD"
},
"amount": {
"amount": "5.00000000",
"currency": "LTC"
},
"total": {
"amount": "223.55",
"currency": "USD"
},
"subtotal": {
"amount": "214.97",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-07-17T17:36:55Z",
"instant": true,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/58f8aec9a68baf0224f79bf4/transactions/596cf5bb8a4ad1000108e385",
"details": {
"title": "Bought litecoin",
"subtitle": "using Visa debit ********8539",
"payment_method_name": "Visa debit ********8539"
}
},
{
"id": "6921aff4-4e2c-57ec-aed0-00b815d04706",
"type": "buy",
"status": "completed",
"amount": {
"amount": "4.00000000",
"currency": "LTC"
},
"native_amount": {
"amount": "179.26",
"currency": "USD"
},
"description": null,
"created_at": "2017-07-11T06:16:05Z",
"updated_at": "2017-07-11T06:16:07Z",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/6921aff4-4e2c-57ec-aed0-00b815d04706",
"instant_exchange": false,
"buy": {
"id": "1400536d-9c7a-5c83-83aa-a56f0d7a2c4f",
"status": "completed",
"payment_method": {
"id": "9e401028-321c-5dce-bf89-1e209ff39ade",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/9e401028-321c-5dce-bf89-1e209ff39ade"
},
"transaction": {
"id": "6921aff4-4e2c-57ec-aed0-00b815d04706",
"resource": "transaction",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/transactions/6921aff4-4e2c-57ec-aed0-00b815d04706"
},
"user_reference": "Q4CRSU2J",
"created_at": "2017-07-11T06:15:58Z",
"updated_at": "2017-07-11T06:16:07Z",
"resource": "buy",
"resource_path": "/v2/accounts/b5917a71-cb64-5a51-b5ba-53f3f3bac595/buys/1400536d-9c7a-5c83-83aa-a56f0d7a2c4f",
"fee": {
"amount": "6.88",
"currency": "USD"
},
"amount": {
"amount": "4.00000000",
"currency": "LTC"
},
"total": {
"amount": "179.26",
"currency": "USD"
},
"subtotal": {
"amount": "172.38",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-07-11T06:15:57Z",
"instant": true,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/58f8aec9a68baf0224f79bf4/transactions/59646d25e1c2cf0001d161a8",
"details": {
"title": "Bought litecoin",
"subtitle": "using Visa debit ********8539",
"payment_method_name": "Visa debit ********8539"
}
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment