Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm mostly looking for ideas, here.

I have a main control with tabs and several child controls. I have done this A: to simplify the main control and B: because I will need to turn some features on / off and so not render some of these child controls.

It now turns out that I will be populating these controls client-side via javascript.

Currently, my main control gets the data then checks that each control exists, checks that each control's populateMe() function exists, then passes that object to that control.

To avoid confusion with the child control populateMe() function names (I didn't actually call any of my functions populateMe()), I instead create an array of functions that each control pushes it's own populateMe() function to.
IE:
JavaScript
//Main control:
var AgentPortalPopulateDetailFunctions = [];
function populateChildren(data){
    $.each(AgentPortalPopulateDetailFunctions,function(){
        this(data);
    });
}

JavaScript
//a child control:
$(function () {
  AgentPortalPopulateDetailFunctions.push(function(data){
     //populate me
  });
});


This means that my main control has no idea what info the control needs so it passes the whole object each time. It's not a massive object but it's not small and this process will happen almost as fast as the user can click :S

Q1: Is passing this large object from one function to another problematic?
Q2: Is there another way I can do this that still keeps each child-control separate?

Any ideas would be useful :)

Thanks ^_^
Andy
Posted
Updated 18-Aug-15 6:23am
v2

1 solution

There is no such problem, whatsoever. In terms of passing objects to methods, there is no such thing as "large" object, because the references to the objects are passed, there is no object cloning, unless you specifically develop such mechanism. Of course, the object will be shared through the referenced passed to different places of code.

As to the "another way", I could advise one if you explained the exact ultimate goal of what you are trying to achieve. Anyway, and array of "populate" methods sounds weird, because you say that you have a separate "populate" function for each control. Then you should simply use the functions. A function can be a property of any object, including the jQuery wrapper around an HTML element. The key here: where is the knowledge on each specific control and its population and how it can be expressed in a clear way.

—SA
 
Share this answer
 
Comments
Andy Lanng 19-Aug-15 4:07am    
good. At least I know that passing the object around is no issue.

I have a goal of keeping the solution as generic as possible. This is the first web app I have built from a blank page but I intent to use the framework for future contracts. If all goes well, I will have a team of juniors who will be using the framework. This is the only reason I want to keep the whole solution as generic as possible.
Sergey Alexandrovich Kryukov 19-Aug-15 9:04am    
Good, but it keeps the issue of keeping controls separate as vague as the idea of keeping the solution generic. :-)
I guess, to discuss it, something more essential is needed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900