Module config not merging in deep
See original GitHub issueHi, 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
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:
- Created 3 years ago
- Comments:24 (16 by maintainers)
@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.
could also use lodash.merge
see https://stackoverflow.com/questions/19965844/lodash-difference-between-extend-assign-and-merge