How to best go about making a Javascript Object in ASP.NET 4.5 Self-Calculating, unbound from the UI?

The goal is to replace our existing calculation engine which is very tied to the UI with a new one that can be used with or without the UI.

Attached are a couple of sections.  One explains when something changes in the voyage how that change is cascaded through the entire voyage.  The other is pseudo code of a possible solution, it has some downfalls but is feasible to accomplish in a reasonable amount of time.

Please review and see if you can come up with a better alternate solution.

-----SECTION 1

This section details the chain of effects when something changes, Δ, in the UI.
  Indicates whole collection will be updated not just the current record

Vessel Object
Δ Hire Rate > self >   Result Object

Offhire Object
Δ Offhire (Days) > self >   Result Object
Δ Other >   Result Object

Result Object
      Δ Days > self >   Expense Object

Cargo/Fixture Object
Δ Lay/Can > self >   Leg Object
Δ CP Qty, Overage, Grades > self
Δ Groups or Companies > self
Δ C/P, Voy #, Fix # > self
Δ Commission % > self >   Revenue Object
Δ Demurrage, Laytime, Time Bar, Other Time Bar > self
Δ Fixture Remark > self
Δ Bills of lading > self

Leg Object
Δ Regulation >   self this point forward >   Leg Consumption Object
Δ Speed Defaults >   self >   Leg Consumption Object
Δ Draft Fore, Draft Aft, FW Slops >   self
Δ Other >   self this point forward >   Leg Consumption Object

Bunkers Object
Δ Refill Price >   self >   Result Object
Δ Grades Available >   self >   Leg Consumption Object
Δ Stems >   self >   Leg Consumption Object
Δ Other >   self >   Result Object

Leg Consumption Object
Δ Heat, Clean, Inert, Adjustment Passage or Port >   self >   Result Object
Δ Other >    self >   Bunker Object

Revenue Object
Δ Other > self >   Result Object

Expense Object
Δ Other > self >   Result Object

Demurrage Object
Δ Other > self

Remark Object
Δ Other > self

----- SECTION - 2

function Calculate(voyageObject, action, index, isUpdateUi) {
      switch(action) {
            case "vessel":
            case "revenue":
            case "expense":
                  //Do everything!
      if(isUpdateUi)       {
            UpdateUi(voyageObject, action, index)
      //Could issue event when complete (still would we know one voyage from another)

function UpdateUi(voyageObject, action, index) {
      //Update main page
      //Detect update modals if they exists
Paul MaurielloSoftware Programmer Developer Analyst EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
And your question is?

When your question is about doing the calculation in JavaScript, then use callbacks (events) to update your UI and to execute async postbacks.

btw, I don't see the reason for your switch construct.
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
The main goal its to make the underlying object stand on its own so It doesn't necessary require UI input.

To enable calculations of a series of hypothetical scenarios unbound from the UI.

My question is, in creating one major calculate function to handle all possible calculation scenarios, would this be an efficient way to go?
ste5anSenior DeveloperCommented:
One calculate function may be faster when it is executed very often (100x or more). But for a single calculation run it doesn't matter. Here it's more important to write readable and testable code. Free after Don Knuth: Make it run, make it right, make it fast. So just get it right and decoupled. Optimization is the last step, when you have numbers proofing that you need to speed it up.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.