I currently have some code written that will call a function after a custom .trigger()
call. This is what is called:
function _visitAddTag(state, listener) {
if (state.properties.action = "RedoAddTag") contextMenu.unhide();
var $target = contextMenu.getContextMenuUI().tags; // Grab tag elements
var callback = function () {
if (listener) {
google.maps.event.removeListener(listener);
}
$target.off("tagIds-updated", callback);
contextMenu.hide();
next.call(contextMenu.getTargetLabel(), state.transition);
};
$target.on("tagIds-updated", callback());
}
The next.call()
line causes this method to be triggered:
function () { // 'this' is contextMenu.getTargetLabel(), as called in Onboarding.js/_visitAddTag()
tracker.push('Onboarding_Transition', {onboardingTransition: "tag-attribute-1"});
var tags = this.getProperty('tagIds');
return tags == [2] ? "adjust-heading-angle-1" : "redo-tag-attribute-1" // Where 2 is the tag_id of the "points into traffic" tag
}
Where a return value of "redo-tag-attribute-1"
will cause the whole thing to loop again.
I see the potential for recursion here, especially if the "tagIds-updated"
event is somehow triggered inside of the second function call. However, when I debug the code, that event is only triggered once. Does anyone have any ideas as to what is happening here? I'm a javascript newb so maybe I'm missing something obvious.