question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module config not merging in deep

See original GitHub issue

Hi, i have some problem when i create some module. this.defaults and this.config is not merged properly Object.assign() don’t do all job in deep So I create configMerge()

this is some test :

So I do some test and not worked without configMerge()

Module name : MMM-Freebox (in dev for new version) in MMM-Freebox.js:

  defaults: {
    updateDelay:  5 * 1000,
    token: "",
    activeOnly: false,
    showIcon: true,
    showButton: true,
    showBandWidth: true,
    showRate: true,
    showClient: true,
    showClientRate: true,
    showClientCnxType: true,
    showFreePlayer: true,
    showMissedCall: true,
    showVPNUsers: true,
    maxMissed: 3,
    showIP: true,
    showPing: true,
    pingAdress: "google.fr",
    textWidth: 250,
    excludeMac: [],
    sortBy: null,
    debug: false,
    verbose: false,
    dev: false,
    debitText: "Débit total utilisé : ",
    player : {
      showPlayerInfo: false,
      // depuis le firmware 4.2.3, problemes d'affichage des logos
      // essayez avec les ips :  "192.168.0.254" (l'ip du freebox server)
      //                         "mafreebox.free.fr" ou le resultat de l'ip de mafreebox.free.fr
      //                         "212.27.38.253" l'ip de mafreebox.free.fr (a voir si cela fonctionne pour vous)
      ServerIP: "212.27.38.253",
      UseEPGDayURL: true,
      EPGDelay: 2* 60 *60 *1000
    }
  },

I try to merge config with MMM-Freebox.js :

  start: function () {
    this.config = Object.assign({}, this.defaults, this.config)

I send config to node_helper.js with:

  notificationReceived: function (notification, payload) {
    switch(notification) {
      case "DOM_OBJECTS_CREATED":
        this.sendSocketNotification("INIT", this.config)
        break
    }
  },

module configuration in config.js:

{
  module: "MMM-Freebox",
  disabled: false,
  header: "INFO Freebox",
  position: "top_center",
  config: {
    token: "xxxx",
    updateDelay:  5 * 1000,
    activeOnly: false,
    sortBy: "type",
    showButton: true,
    debug: true,
    //dev: true,
    //verbose: true,
    showVPNUsers: true,
    textWidth: 250,
    player: {
      showPlayerInfo: true
    }
  }
},

result in node_helper.js:

[2020-08-10 16:53:52.705] [LOG]    {
  updateDelay: 5000,
  token: 'xxxx',
  activeOnly: false,
  showIcon: true,
  showButton: true,
  showBandWidth: true,
  showRate: true,
  showClient: true,
  showClientRate: true,
  showClientCnxType: true,
  showFreePlayer: true,
  showMissedCall: true,
  showVPNUsers: true,
  maxMissed: 3,
  showIP: true,
  showPing: true,
  pingAdress: 'google.fr',
  textWidth: 250,
  excludeMac: [],
  sortBy: 'type',
  debug: true,
  verbose: false,
  dev: false,
  debitText: 'Débit total utilisé : ',
  player: { showPlayerInfo: true }
}

so config is not merged !

now … Let’s try with configMerge() with SAME configuration just modify :

  start: function () {
    this.config = configMerge({}, this.defaults, this.config)

result in node_helper.js:

[2020-08-10 17:08:14.984] [LOG]    {
  updateDelay: 5000,
  token: 'xxxx',
  activeOnly: false,
  showIcon: true,
  showButton: true,
  showBandWidth: true,
  showRate: true,
  showClient: true,
  showClientRate: true,
  showClientCnxType: true,
  showFreePlayer: true,
  showMissedCall: true,
  showVPNUsers: true,
  maxMissed: 3,
  showIP: true,
  showPing: true,
  pingAdress: 'google.fr',
  textWidth: 250,
  excludeMac: [],
  sortBy: 'type',
  debug: true,
  verbose: false,
  dev: false,
  debitText: 'Débit total utilisé : ',
  player: {
    showPlayerInfo: true,
    ServerIP: '212.27.38.253',
    UseEPGDayURL: true,
    EPGDelay: 7200000
  }
}

You can’t see that player: {} value is now set and merged with default value

@MichMich :

in MM core js/module.js

	/* setConfig(config)
	 * Set the module config and combine it with the module defaults.
	 *
	 * argument config object - Module config.
	 */
	setConfig: function (config) {
		this.config = Object.assign({}, this.defaults, config);
	},

Can I send you a patch with configMerge() script for solve this developer (and users) issue (It take head !) ? I use it in all my module for merging and why not take place in MM core 😉

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
MichMichcommented, Sep 19, 2020

Mister @MichMich after 2 months your are alive … so don’t touch of this part of code …

@bugsounet keep in mind this is a side project for me. I have limited time to spent on this project and have managed to keep it maintained for the past 6 years.

I understand it can be frustrating when I won’t respond to all issues. But do my utmost best to review all PR’s and merge were possible.

Keep in mind that, although I love any community contribution in the form of modules, I’m not obligated to give support. That’s simply not possible. I have my day job. I have my family including two small kids, I have a house that needs a lot of work. And like everybody, I have my own struggles in this weird COVID time.

The way you handle your frustration isn’t helping anybody. It isn’t helping your users. It isn’t helping the community, it isn’t helping the project, it isn’t helping me and most of all it isn’t helping you.

Please calm down. Take some time off and return when you feel you can make a positive contribution to a community solely run by volunteers.

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Declaration Merging - TypeScript
For the purposes of this article, “declaration merging” means that the compiler merges two separate declarations declared with the same name into a...
Read more >
Merging yaml config files recursively with bash - Stack Overflow
The goal is an export shellscript that will merge all separate module folders' config files into big merged files. It's faster, efficient, and ......
Read more >
Config::Merge - load a configuration directory tree containing ...
DESCRIPTION. Config::Merge is a configuration module which has six goals: Flexible storage. Store all configuration in your format(s) of choice (YAML, JSON, ...
Read more >
Configuration Module Attributes - netsim-tools - Read the Docs
The deep merge process takes care of attribute specificity: Attributes specified on individual nodes are not overwritten with global- or device-specific ...
Read more >
Configuration Blocks and Attributes - Terragrunt
Note that in many cases, Terragrunt may not be able to deploy modules from the registry. ... For Terragrunt config, deep merge is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found