saml-dev / MMM-Traffic

This a module for the MagicMirror. It displays travel time between two locations, using the Mapbox directions API to factor in current traffic conditions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError

traveller255 opened this issue · comments

Uncaught (in promise) TypeError: this.shouldHide is not a function
at updateCommute (traffic.js:53)

Very bad coding! You're going to do something about it?

Lol, thanks for the review of my "coding". You're welcome to submit a PR to correct my very bad coding with your own very good coding.

Add more details to your issue, such as your MMM-Traffic config, and I can take a look when I have time.

Yah, is very frustrating but has nothing to do with my config, is about you code

	updateCommute: function () {
		var mode = this.config.mode == "driving" ? "driving-traffic" : this.config.mode;
        this.url = encodeURI("https://api.mapbox.com/directions/v5/mapbox/" + mode + "/" + this.config.originCoords + ";" + this.config.destinationCoords + "?access_token=" + this.config.accessToken);

		// only run getDom once at the start of a hidden period to remove the module from the screen, then just wait until time to unhide to run again
		if (this.shouldHide() && !this.hidden) {
		//  here I get Uncaught (in promise) TypeError: this.shouldHide is not a function
at updateCommute (traffic.js:53)
			console.log("Hiding Traffic");
			this.hidden = true;
			this.updateDom();
		} else if (!this.shouldHide()) {
			this.hidden = false;
			this.getCommute(this.url);
		}
		// no network requests are made when the module is hidden, so check every 30 seconds during hidden
		// period to see if it's time to unhide yet
		setTimeout(this.updateCommute, this.hidden ? 3000 : this.config.interval);
	},

I don't send a PR because I have my own module not a fork. here is my config anyway

		{
			module: "traffic",
			position: "top_left",
			classes: "parc",
			disabled: false,
			config: {
				loadingText: "Se încarcă...",
				firstLine: "Trafic până la parcul Titan: {duration} minute",
				accessToken: "...",
				originCoords: "26.173524,44.4102524",
				destinationCoords: "26.159527,44.4184522",
				days: [6, 7],
			}
		},
		{
			module: "traffic",
			position: "top_left",
			classes: "ikea",
			disabled: false,
			config: {
				loadingText: "Se încarcă...",
				firstLine: "Trafic până la Ikea Pallady: {duration} minute",
				accessToken: "...",
				originCoords: "26.173524,44.4102524",
				destinationCoords: "26.2039869,44.4065395",
				days: [6, 7],
			}
		},

I don't send a PR because I have my own module not a fork

What does this mean? have you altered the code at all? this.shouldHide gets called on every single update. Does your module fail out immediately when you start it up? Or does it work for a while and then fail?

I have not altered the code except isoWeekday() and module get this error when is trying to hide unused instance ex. days: [1, 2, 3, 4, 5],

Fixed with the latest push to master

thanks, you need only this line to solve the problem this.updateCommute = this.updateCommute.bind(this);

Yes, that is what fixed it