Skip to content

Instantly share code, notes, and snippets.

@plwalters
Last active August 29, 2017 02:49
Show Gist options
  • Save plwalters/38b29e75c3e979297e5a833c900b667b to your computer and use it in GitHub Desktop.
Save plwalters/38b29e75c3e979297e5a833c900b667b 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 = 4371.01;
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": "a6ef8bb7-82a8-5b41-9c8f-affb959b1194",
"type": "buy",
"status": "completed",
"amount": {
"amount": "1.00000000",
"currency": "BTC"
},
"native_amount": {
"amount": "3975.64",
"currency": "USD"
},
"description": null,
"created_at": "2017-08-22T02:25:07Z",
"updated_at": "2017-08-26T02:25:17Z",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/a6ef8bb7-82a8-5b41-9c8f-affb959b1194",
"instant_exchange": false,
"buy": {
"id": "72631f87-6a8d-5694-80c0-920ff8f55879",
"status": "completed",
"payment_method": {
"id": "9a8f76ca-4e43-58bf-bca8-bc866a686504",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/9a8f76ca-4e43-58bf-bca8-bc866a686504"
},
"transaction": {
"id": "a6ef8bb7-82a8-5b41-9c8f-affb959b1194",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/a6ef8bb7-82a8-5b41-9c8f-affb959b1194"
},
"user_reference": "LJT5BV6Y",
"created_at": "2017-08-22T02:24:54Z",
"updated_at": "2017-08-26T02:25:17Z",
"resource": "buy",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/buys/72631f87-6a8d-5694-80c0-920ff8f55879",
"fee": {
"amount": "58.37",
"currency": "USD"
},
"amount": {
"amount": "1.00000000",
"currency": "BTC"
},
"total": {
"amount": "3975.64",
"currency": "USD"
},
"subtotal": {
"amount": "3917.27",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-08-27T02:24:54Z",
"instant": false,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/57073c52b65638028d00025f/transactions/599b960311cf0600018dec48",
"details": {
"title": "Bought bitcoin",
"subtitle": "using Chase - TOTAL BUS CHK *****0037",
"payment_method_name": "Chase - TOTAL BUS CHK *****0037"
}
},
{
"id": "d55355e6-d91a-596a-adff-d499f1fdbf80",
"type": "buy",
"status": "completed",
"amount": {
"amount": "1.00000000",
"currency": "BTC"
},
"native_amount": {
"amount": "4080.38",
"currency": "USD"
},
"description": null,
"created_at": "2017-08-21T14:16:10Z",
"updated_at": "2017-08-25T14:17:26Z",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/d55355e6-d91a-596a-adff-d499f1fdbf80",
"instant_exchange": false,
"buy": {
"id": "3d4c77ba-1c18-5382-bbab-1262d422e3c2",
"status": "completed",
"payment_method": {
"id": "9a8f76ca-4e43-58bf-bca8-bc866a686504",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/9a8f76ca-4e43-58bf-bca8-bc866a686504"
},
"transaction": {
"id": "d55355e6-d91a-596a-adff-d499f1fdbf80",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/d55355e6-d91a-596a-adff-d499f1fdbf80"
},
"user_reference": "XFGQU497",
"created_at": "2017-08-21T14:16:07Z",
"updated_at": "2017-08-25T14:17:26Z",
"resource": "buy",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/buys/3d4c77ba-1c18-5382-bbab-1262d422e3c2",
"fee": {
"amount": "59.91",
"currency": "USD"
},
"amount": {
"amount": "1.00000000",
"currency": "BTC"
},
"total": {
"amount": "4080.38",
"currency": "USD"
},
"subtotal": {
"amount": "4020.47",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-08-26T14:16:07Z",
"instant": false,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/57073c52b65638028d00025f/transactions/599aeb2a491e0c0001cf7bfa",
"details": {
"title": "Bought bitcoin",
"subtitle": "using Chase - TOTAL BUS CHK *****0037",
"payment_method_name": "Chase - TOTAL BUS CHK *****0037"
}
},
{
"id": "6cd54356-6533-5b3e-8f28-7cf7e7a8ee48",
"type": "buy",
"status": "completed",
"amount": {
"amount": "0.23327946",
"currency": "BTC"
},
"native_amount": {
"amount": "519.95",
"currency": "USD"
},
"description": null,
"created_at": "2017-07-17T18:00:28Z",
"updated_at": "2017-07-17T18:00:31Z",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/6cd54356-6533-5b3e-8f28-7cf7e7a8ee48",
"instant_exchange": false,
"buy": {
"id": "11565347-c0af-58e1-83d2-406cb2d5771f",
"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": "6cd54356-6533-5b3e-8f28-7cf7e7a8ee48",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/6cd54356-6533-5b3e-8f28-7cf7e7a8ee48"
},
"user_reference": "Y3MQM22X",
"created_at": "2017-07-17T18:00:26Z",
"updated_at": "2017-07-17T18:00:31Z",
"resource": "buy",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/buys/11565347-c0af-58e1-83d2-406cb2d5771f",
"fee": {
"amount": "19.95",
"currency": "USD"
},
"amount": {
"amount": "0.23327946",
"currency": "BTC"
},
"total": {
"amount": "519.95",
"currency": "USD"
},
"subtotal": {
"amount": "500.00",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-07-17T18:00:25Z",
"instant": true,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/57073c52b65638028d00025f/transactions/596cfb3c51bdd1000108c256",
"details": {
"title": "Bought bitcoin",
"subtitle": "using Visa debit ********8539",
"payment_method_name": "Visa debit ********8539"
}
},
{
"id": "3776a7ce-bb6e-5d76-8ef3-aa630ffca08f",
"type": "buy",
"status": "completed",
"amount": {
"amount": "0.37071671",
"currency": "BTC"
},
"native_amount": {
"amount": "1000.00",
"currency": "USD"
},
"description": null,
"created_at": "2017-07-05T01:02:29Z",
"updated_at": "2017-07-05T01:02:31Z",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/3776a7ce-bb6e-5d76-8ef3-aa630ffca08f",
"instant_exchange": false,
"buy": {
"id": "8dac5aff-4932-5d54-b4f4-de3f983ba209",
"status": "completed",
"payment_method": {
"id": "ea0b942e-bb70-513c-a642-438c0d77ff4e",
"resource": "payment_method",
"resource_path": "/v2/payment-methods/ea0b942e-bb70-513c-a642-438c0d77ff4e"
},
"transaction": {
"id": "3776a7ce-bb6e-5d76-8ef3-aa630ffca08f",
"resource": "transaction",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/transactions/3776a7ce-bb6e-5d76-8ef3-aa630ffca08f"
},
"user_reference": "Z2E3MUTJ",
"created_at": "2017-07-05T01:02:18Z",
"updated_at": "2017-07-05T01:02:31Z",
"resource": "buy",
"resource_path": "/v2/accounts/c9f19131-b101-57c0-91c0-0811d2540a38/buys/8dac5aff-4932-5d54-b4f4-de3f983ba209",
"fee": {
"amount": "38.37",
"currency": "USD"
},
"amount": {
"amount": "0.37071671",
"currency": "BTC"
},
"total": {
"amount": "1000.00",
"currency": "USD"
},
"subtotal": {
"amount": "961.63",
"currency": "USD"
},
"committed": true,
"payout_at": "2017-07-05T01:02:17Z",
"instant": true,
"recurring_payment": null,
"requires_completion_step": false
},
"recurring_payment": null,
"resource_url": "/accounts/57073c52b65638028d00025f/transactions/595c3aa563e9650001849fe5",
"details": {
"title": "Bought bitcoin",
"subtitle": "using Visa debit ********0371",
"payment_method_name": "Visa debit ********0371"
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment