samedi 2 décembre 2017

Entities inside redux store and proper file structure for utils functions

Problem

Inside redux store there are many entities and each entity can have different path to it. From time to time I need to pick them, mix them and for example get total cash allocated to account including connected to it securities.

expamle what i mean

app.current.accounts = [...] 
app.current.actualAccount.account = {...}
app.current.actualAccount.securities = [...]
app.validated.accounts = []
app.validated.holdings = []
app.navigation.actualSelectedAccountId = ...

etc...

Question

What should be proper file/directory structure in this case? Because I would like to have components only for rendering view(not calculations) and also I need to use same function on different pages.

My solution

I know that after some time there will be a lot of those functions because number of entities will grow. So I was thinking the best approach will be to create directory "ReduxEntityHelper" and Then naming convention for each file would be name of parameters of functions sorted alphabetically.

Example

  1. ReduxEntityModel/AccountsSecurities.js

    export function getSummaryCash(Account, Securities){...}

    export function checkIfValid(Account, Securities){...}

  2. ReduxEntityModel/AccountsSecuritiesHoldings.js

    export function getTotalCashInStock(holdings, account, securities){...}

  3. ReduxEntityModel/Accounts.js

    export function getNextAccount(actualAccountId, accounts){...}

Final questions

  1. What you think about this approach?
  2. What is your approach?

Criteria:

  • Scalable

  • Good maintenance and some order

  • Comfortable to use

  • There will be a lot of entities and combinations between them

  • Entities are related to many components and pages

  • Those are just static functions (no need to remember anything inside them, just take data, mix it, get new data)

Hope this will be nice riddle ;)

Aucun commentaire:

Enregistrer un commentaire