MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

module.js


  • Module Developer

    hide: function (speed, callback, options) {
    	if (typeof callback === "object") {
    		options = callback;
    		callback = function () {};
    	}
    
    	callback = callback || function () {};
    	options = options || {};
    
    	var self = this;
    	MM.hideModule(
    		self,              -------------- should be 'this' ?
    		speed,
    		function () {
    			self.suspend();
    			callback();
    		},
    		options
    	);
    },
    
    show: function (speed, callback, options) {
    	if (typeof callback === "object") {
    		options = callback;
    		callback = function () {};
    	}
    
    	callback = callback || function () {};
    	options = options || {};
    
    	var self = this;
    	MM.showModule(
    		this,
    		speed,
    		function () {
    			self.resume();
    			callback;       -------------- should be 'callback()' ?
    		},
    		options
    	);
    }


  • @hango no… the MM functions locate modules

    then u have the module object and call hide on it
    from my SleepWake module

    MM.getModules().enumerate((module) => {
    				// if the module is already hidden
    				if(module.hidden==true)
    					// save it for wake up
    					{self.previously_hidden.push(module.identifier);}
    				else
    					// hide this module
    					{module.hide(1000);}
    			});
    

    https://docs.magicmirror.builders/development/helper-methods.html#module-selection


  • Module Developer

    I only ask if it is an error or bug in the core module.js
    look at differences between hide function and show function



  • @hango from main.js

    var showModule = function (module, speed, callback, options) {
    var hideModule = function (module, speed, callback, options) {

  • Module Developer

    to be more clear, at hide function there is “self,” instead of “this,” as it is in show function,
    then in show function there is “callback;” instead of “callback();” as it is in hide function.
    both or which one is correct?



  • @hango before the call to hideModule
    there is a variable self set
    self is used to avoid the ambiguity of ‘this’, as inside callbacks ‘this’ can point to the caller, NOT the context where it was intended.

    	var self = this;     < ----- self is initialized to the current 'this' context
    	MM.hideModule(
    		self,              < -------------- should be 'this' ?
    		speed,
    

    so its the same
    and in the call there is a required function (the callback), in this case created inline

    		function () {
    			self.suspend();   // < --- make sure to use the right module context when this function is called
                                                      // the compiler remembers that self was defined above 
    			callback();         // call the routine defined as callback
    		},
    

  • Module Developer

    OK. Thank you very much.


Log in to reply