I have the code but I want to be pseudo as possible so I learn from other ways as much as possible.
So what I am building is web based tool and in one section we have a table.
This table renders lines of data given it matches conditions.
So the way it works is user enters a number and based on that we out specific lines in the front end.
E.g
If(one) return lineA
If(two) return lineB . ...
You can see I already I need a minimum of two views but let's say there 20 separate conditions that means 20 separate views.
Then because it's accounting calculations these could be a combo of any, many or all.
The way I've currently done is as follows:
Calcs
If(one) return lineA
If(two) return lineB
If(one and two) return lineA + lineB
Delegation
If(one) return viewA
If(two) return viewA
If(one and two) return viewA + viewB
Views
viewA()
viewB()
Obviously you can see I'm going down spaghetti lane.
Is there anyway to make this work with few conditions as possible?
It would help if you've coded such tools before.
Do I/should I stop coding and draw a large matrix of all possible combos first?
I think these two are irrelevant here but: If it helps this is all done in JS and Angular.
If it helps this is for a accounting/finance tool.
{ condition, thingToShow }
, then you create a bunch of these objects with different conditions (which are just functions that return a bool), and stick them in a list, and then you filter them so that you take only those wherecondition(yourInput)
returns true. Then you combine the all the differentthingToShow
of the remaining objects, and you render that. 2/2 – Filip Milovanović Jan 28 '23 at 12:25return lineA + lineB
is unreachable after the early returns above it. Move this line to the top if you ever want to give it a chance to be called. – candied_orange Jan 28 '23 at 22:40