#39 Adding A Portfolio Plan And Creating The Portfolio Vuex State
Sunday, March 1, 2020
Following up on our previous article were we created the portfolio category class we now need to create the portfolio plan class. This new class will be responsible for containing the grouping of categories that represent what a portfolio plan is. Once both classes are in place we can then create an initial portfolio state and add it to our overall vuex state.
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
portfolio-plan-model.ts (1:14)
import { PortfolioCategoryModel } from "@/store/portfolio-category-model";
export interface IPortfolioPlanConfig {
categories: PortfolioCategoryModel[];
id: number;
name: string;
}
export class PortfolioPlanModel {
private _categories: PortfolioCategoryModel[];
private _id: number;
private _name: string;
public get categories() {
return this._categories;
}
public set categories(categories: PortfolioCategoryModel[]) {
this._categories = categories;
}
public get id() {
return this._id;
}
public set id(id: number) {
this._id = id;
}
public get name() {
return this._name;
}
public set name(name: string) {
this._name = name;
}
constructor(config: IPortfolioPlanConfig) {
this._categories = config.categories;
this._id = config.id;
this._name = config.name;
}
}
portfolio-category-model.ts (4:47)
import { PortfolioPlanModel } from "@/store/portfolio-plan-model";
...
export class PortfolioCategoryModel {
...
private _portfolio: PortfolioPlanModel | null = null;
...
public get portfolio() {
return this._portfolio;
}
...
public setPortfolio(portfolio: PortfolioPlanModel) {
this._portfolio = portfolio;
}
}
store-constants.ts (6:30)
...
export const STATE_PORTFOLIO_CATEGORIES = "STATE_PORTFOLIO_CATEGORIES";
export const STATE_PORTFOLIO_PLANS = "STATE_PORTFOLIO_PLANS";
...
Advertisement
portfolio-types.ts (7:24)
import { STATE_PORTFOLIO_CATEGORIES, STATE_PORTFOLIO_PLANS } from "@/store/store-constants";
import { PortfolioCategoryModel } from "@/store/portfolio-category-model";
import { PortfolioPlanModel } from "@/store/portfolio-plan-model";
export interface IPortfolioCategoryModelState {
index: number;
items: PortfolioCategoryModel[];
}
export interface IPortfolioPlanModelState {
index: number;
items: PortfolioPlanModel[];
}
export interface IPortfolioState {
[STATE_PORTFOLIO_CATEGORIES]: IPortfolioCategoryModelState;
[STATE_PORTFOLIO_PLANS]: IPortfolioPlanModelState;
}
portfolio-initial-state.ts (9:54)
import { PortfolioCategoryModel } from "@/store/portfolio-category-model";
import { PortfolioPlanModel } from "@/store/portfolio-plan-model";
import { IPortfolioPlanModelState, IPortfolioCategoryModelState } from "@/store/portfolio-types";
import { initialState as securityCategoryInitialState } from "@/store/security-category-initial-state";
const categories: PortfolioCategoryModel[] = [];
const plans: PortfolioPlanModel[] = [];
if (process.env.NODE_ENV === "development") {
const growth = new PortfolioPlanModel({ categories, id: 1, name: "Growth" });
plans.push(growth);
const delc = securityCategoryInitialState.items.find((x) => x.id === 1)!;
const demc = securityCategoryInitialState.items.find((x) => x.id === 2)!;
const desc = securityCategoryInitialState.items.find((x) => x.id === 3)!;
const iedm = securityCategoryInitialState.items.find((x) => x.id === 4)!;
const ieem = securityCategoryInitialState.items.find((x) => x.id === 5)!;
const dfdm = securityCategoryInitialState.items.find((x) => x.id === 6)!;
const ifdm = securityCategoryInitialState.items.find((x) => x.id === 7)!;
const dsdm = securityCategoryInitialState.items.find((x) => x.id === 8)!;
const catDelc = new PortfolioCategoryModel({ categoryId: delc.id, id: 1, percent: 38, portfolioId: growth.id });
const catDemc = new PortfolioCategoryModel({ categoryId: demc.id, id: 2, percent: 12, portfolioId: growth.id });
const catDesc = new PortfolioCategoryModel({ categoryId: desc.id, id: 3, percent: 6, portfolioId: growth.id });
const catIedm = new PortfolioCategoryModel({ categoryId: iedm.id, id: 4, percent: 18, portfolioId: growth.id });
const catIeem = new PortfolioCategoryModel({ categoryId: ieem.id, id: 5, percent: 7, portfolioId: growth.id });
const catDfdm = new PortfolioCategoryModel({ categoryId: dfdm.id, id: 6, percent: 13, portfolioId: growth.id });
const catIfdm = new PortfolioCategoryModel({ categoryId: ifdm.id, id: 7, percent: 3, portfolioId: growth.id });
const catDsdm = new PortfolioCategoryModel({ categoryId: dsdm.id, id: 8, percent: 3, portfolioId: growth.id });
categories.push(catDelc);
categories.push(catDemc);
categories.push(catDesc);
categories.push(catIedm);
categories.push(catIeem);
categories.push(catDfdm);
categories.push(catIfdm);
categories.push(catDsdm);
}
export const categoryState: IPortfolioCategoryModelState = {
index: 9,
items: categories,
};
export const planState: IPortfolioPlanModelState = {
index: 2,
items: plans,
};
store-types.ts (16:53)
...
import { IPortfolioState } from "@/store/portfolio-types";
...
export interface IStoreState extends IAccountState, IPortfolioState, ISecurityState {
...
}
...
portfolio-module.ts
import { STATE_PORTFOLIO_CATEGORIES, STATE_PORTFOLIO_PLANS } from "@/store/store-constants";
import { categoryState, planState } from "@/store/portfolio-initial-state";
import { IPortfolioState } from "@/store/portfolio-types";
export const portfolioState: IPortfolioState = {
[STATE_PORTFOLIO_CATEGORIES]: categoryState,
[STATE_PORTFOLIO_PLANS]: planState,
};
store.ts (17:37)
...
import { portfolioState } from "@/store/portfolio-module";
...
const state: IStoreState = {
...
...portfolioState,
...
};
...
Exciton Interactive LLC