#36 Encapsulating The Transferring Of Elements Between Accounts
Sunday, February 9, 2020
In this article we will encapsulate the ability to transfer elements from one account to another that we have previous created in order to transfer deposits. This encapsulation will give us the ability to transfer other elements in a DRY way which we will immediately make use of for the account securities.
Parts
- Part 45: Adjusting Shares
- Part 44: Plan Percentages
- Part 43: Home Securities
- Part 42: Updating Plans
- Part 41: Plan Details View
- Part 40: Portfolio Getters
- Part 39: Portfolio Plan
- Part 38: Portfolio Category
- Part 37: Account Securities
- Part 36: Account Transfer
- Part 35: View Account Security
- Part 34: Updating Deposit
- Part 33: View Account Deposit
- Part 32: Display Account Details
- Part 31: Account Getters
- Part 30: Deposits And Securities
- Part 29: Add Accounts Details
- Part 28: Refactoring Accounts
- Part 27: Add Security Models
- Part 26: Edit Security Details
- Part 25: View Security Details
- Part 24: Navigating To Details
- Part 23: Getters Validation
- Part 22: Query Parameters
- Part 21: Tab Entries
- Part 20: Tab Header
- Part 19: List View
- Part 18: Vuex Getters
- Part 17: End Domain Model
- Part 16: Start Domain Model
- Part 15: Pop Routes
- Part 14: Push Routes
- Part 13: Removing Accounts
- Part 12: Vuex (Decorators)
- Part 11: Vuex (Accounts)
- Part 10: The App Bar (Settings)
- Part 9: Remove Consumer Rxjs
- Part 8: The App Bar (Back)
- Part 7: Structuring Our App
- Part 6: Animation Between Views
- Part 5: Navigation Fade
- Part 4: Navigation Requests
- Part 3: Fade Animations (cont.)
- Part 2: Fade Animations
- Part 1: Splash Screen
Code Snippets
AccountTransfer.vue (2:04)
<template lang="pug">
div Account Transfer
</template>
AccountsDeposit.vue (2:30)
<script lang="ts">
...
import AccountTransfer from "@/components/AccountTransfer.vue";
...
@Component({
components: {
AccountTransfer,
...
},
})
export default class AccountsDeposit extends Vue {
...
}
</script>
AccountsDeposit.vue (3:00)
<template lang="pug">
form
div.inputs
h1 Deposit
AccountTransfer/
...
...
</template>
AccountTransfer.vue (12:40)
<template lang="pug">
div
label
span Account
small
a(
href=""
v-on:click.prevent="toggleTransfer")
span(v-if="!transfer") Transfer
span(v-if="transfer") Cancel
div.transfer-inputs
div.transfer-from
label(v-if="transfer") From
div.input {{accountName}}
div.transfer-to(v-if="transfer")
label To
select(
v-model="accountId"
v-on:change="change")
option(
v-for="account in accounts"
v-bind:key="account.id"
v-bind:value="account.id") {{account.name}}
</template>
AccountTransfer.vue (4:46)
<script lang="ts">
import { Component, Emit, Prop, Vue } from "vue-property-decorator";
import { AccountModel, Getter, GetterAccount, GETTER_ACCOUNT, GETTER_ACCOUNTS } from "@/store";
@Component
export default class AccountTransfer extends Vue {
@Getter(GETTER_ACCOUNT) private readonly getterAccount!: GetterAccount;
@Getter(GETTER_ACCOUNTS) private readonly accounts!: AccountModel[];
@Prop() private readonly id!: number;
private created() {
this.accountId = this.id;
const account = this.getterAccount(this.accountId);
this.accountName = account.name;
}
private accountId = 0;
private accountName = "";
private transfer = false;
@Emit()
private change(e: Event) {
e.preventDefault();
return this.accountId;
}
private toggleTransfer() {
this.transfer = !this.transfer;
}
}
</script>
Advertisement
AccountsDeposit.vue (9:26)
<template lang="pug">
form
div.inputs
h1 Deposit
AccountTransfer(
v-bind:id="accountId"
v-on:change="accountChange")/
...
...
</template>
AccountsDeposit.vue (9:50)
<script lang="ts">
...
import {
...
AccountModel, // <-- Remove
...
GETTER_ACCOUNT, // <-- Remove
GETTER_ACCOUNTS, // <-- Remove
...
GetterAccount, // <-- Remove
...
} from "@/store";
...
export default class AccountsDeposit extends Vue {
...
@Getter(GETTER_ACCOUNT) private readonly getterAccount!: GetterAccount; // <-- Remove
...
@Getter(GETTER_ACCOUNTS) private readonly accounts!: AccountModel[]; // <-- Remove
...
private accountName = ""; // <-- Remove
...
private transfer = false; // <-- Remove
...
private accountChange(id: number) {
this.accountId = id;
}
private created() {
...
const account = this.getterAccount(this.accountId); // <-- Remove
this.accountName = account.name; // <-- Remove
...
}
...
private toggleTransfer() { // <-- Remove
this.transfer = !this.transfer;
}
}
</script>
AccountsSecurity.vue (12:33)
<script lang="ts">
...
import AccountTransfer from "@/components/AccountTransfer.vue";
...
import {
...
GETTER_ACCOUNT, // <-- Remove
...
GetterAccount, // <-- Remove
...
} from "@/store";
...
@Component({
components: {
AccountTransfer,
...
},
})
export default class AccountsSecurity extends Vue {
...
@Getter(GETTER_ACCOUNT) private readonly getterAccount!: GetterAccount; // <-- Remove
...
private accountName = ""; // <-- Remove
...
private accountChange(id: number) {
this.accountId = id;
}
private created() {
...
const account = this.getterAccount(this.accountId); // <-- Remove
this.accountName = account.name; // <-- Remove
...
}
...
private save() {
console.log("save");
console.log(this.accountId);
}
}
</script>
AccountsSecurity.vue (14:02)
<template lang="pug">
form
div.inputs
h1 Security
AccountTransfer(
v-bind:id="accountId"
v-on:change="accountChange")/
...
...
</template>
Exciton Interactive LLC