bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

INFO_CONFIG and info.js customization


From: Per Bothner
Subject: INFO_CONFIG and info.js customization
Date: Sat, 7 Nov 2020 15:43:30 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

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
per@bothner.com   http://per.bothner.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]