piyushmehta (13) [Avatar] Offline
Hi Mike,

The utilities listing 4.6 is missing explanations that you have inserted so beneficially in other places in the book.

Not sure if I got the point on all of those. Maybe in a future version??


setConfigMap = function ( arg_map ){
input_map = arg_map.input_map,
settable_map = arg_map.settable_map,
config_map = arg_map.config_map,
key_name, error;

here input_map was populated with arg_map, and so was config_map. Then what is the whole point of setting
config_map(key_name) = input_map(key_name);

in the following section

for ( key_name in input_map ){
if ( input_map.hasOwnProperty( key_name ) ){
if ( settable_map.hasOwnProperty( key_name ) ){
config_map[key_name] = input_map[key_name];

Thank you much for any tips.
michael.mikowski (247) [Avatar] Offline
Re: Listing 4.6 - where are the explanation bullets?
Hi Piyushmehta:

Sorry for the delay, but I have been on holiday.

The setConfigMap utility is used to set the configuration map values in a controlled way. Since this is a common requirements across many modules, we have made it a common utility.

spa.util.setConfigMap is called by nearly all modules that provide configuration options. When the developer using the API calls spa.chat.configModule({ slider_open_em : 18, slider_super_em : 26 }), the spa.chat module calls the utility to adjust configMap in a consistent manner.

The input_map is the map of settings the developer using the API wishes to set, { slider_open_em : 18, slider_super_em : 26 } in the above example.

The settable_map is used by the utility to determine which keys are acceptable. For example, settable_map = { slider_open_em : true }; Every module that uses this utility contains a list of allowable keys.

The config_map is a reference to the configMap data structure to be updated- spa.chat.configMap in this example.

Notice in our example the API user requested that spa.chat.configMap.slider_super_em be set to 26. However, that key is *not* in the settable_map and therefore will *not* be set.

I hope that helps!

Cheers, Mike

ps. One can extend this utility to not only check for keys but also against a schema. This is NOT shown directly in the book, but all the pieces to put this together are shown. For example, settable_map could use a JSON schema to ensure that only integers between 10 and 100 would be allowed for the slider_open_em parameter. One has to balance the cost of such checking with the benefits. I have written a module that does this form of checking but the downside is it's syntax is distinct from JSON schema. However, it is much easier to use and introduces significantly less overhead.
piyushmehta (13) [Avatar] Offline
Re: Listing 4.6 - where are the explanation bullets?

Thank you. Hope you come back relaxed.

I have a followup question related to this line:

config_map[key_name] = input_map[key_name];

why are you setting the key_name only? And not key_value?
don't you need both to be set on config_map??