The info.js file has a 'config' structure that can be overridden
by setting an INFO_CONFIG variable. The default config object
is merged with the value of window["INFO_CONFIG"] (by default
undefined) thus:
config = Object.assign (config, user_config);
A minor problem is that Object.assign only does a top-level merge/copy,
but the config structure has a 2-level structure:
var config = {
EXT: ".html",
INDEX_NAME: "index.html",
INDEX_ID: "index",
MAIN_ANCHORS: ["Top", "SEC_Contents"],
WARNING_TIMEOUT: 3000,
SCREEN_MIN_WIDTH: 700,
hooks: {
/** Define a function called after 'DOMContentLoaded' event in
the INDEX_NAME context.
@type {function (): void}*/
on_main_load: null,
/** Define a function called after 'DOMContentLoaded' event in
the iframe context.
@type {(function (): void)} */
on_iframe_load: null
}
};
The problem is the 'hooks' field. The Object.assign call will
not merge hooks from the user_config and the default. Consider:
var INFO_CONFIG = {
hooks: {
on_main_load: my_main_load_hook
}
};
After merging, the result is:
config = {
EXT: ".html",
INDEX_NAME: "index.html",
INDEX_ID: "index",
MAIN_ANCHORS: ["Top", "SEC_Contents"],
WARNING_TIMEOUT: 3000,
SCREEN_MIN_WIDTH: 700,
hooks: {
on_main_load: my_main_load_hook
}
};
There is no config.hooks.on_iframe_load.
Now this doesn't actually matter, since whether
config.hooks.on_iframe_load is undefined or null is false either way.
However, it will break if a new hook is added with an actual non-null default.
My suggestion is to flatten the config structure:
var config = {
EXT: ".html",
INDEX_NAME: "index.html",
INDEX_ID: "index",
MAIN_ANCHORS: ["Top", "SEC_Contents"],
WARNING_TIMEOUT: 3000,
SCREEN_MIN_WIDTH: 700,
// hooks:
/** Define a function called after 'DOMContentLoaded' event in
the INDEX_NAME context.
@type {function (): void}*/
on_main_load: null,
/** Define a function called after 'DOMContentLoaded' event in
the iframe context.
@type {(function (): void)} */
on_iframe_load: null
};
Alternatively, we can replace the Object.assign call with something
that will also merge the hooks field.
--
--Per Bothner
[email protected] http://per.bothner.com/