Skip to content

Commit 1730698

Browse files
committed
Add better warnings in custom event functions
1 parent 04ba29a commit 1730698

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/default.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,22 +946,26 @@
946946

947947
var eventIsFunction = isFunction(event);
948948
var callback = isFunction(callbackRaw) ? callbackRaw : function () {};
949+
var eventType = typeof event;
949950

950-
if (validTypes.indexOf(typeof event) < 0 && !eventIsFunction) {
951-
warn(eventText + " isn't a string: " + event);
951+
if (validTypes.indexOf(eventType) < 0 && !eventIsFunction) {
952+
warnInFunction(eventFunctionName, eventText + " can't be " + eventType);
952953
return callback();
953954
}
954955

955956
try {
956957
if (eventIsFunction) {
957-
event = event();
958-
if (validTypes.indexOf(typeof event) < 0) {
959-
warn(eventText + " function output isn't a string: " + event);
958+
var eventOutput = event();
959+
if (validTypes.indexOf(typeof eventOutput) < 0) {
960+
warnInFunction(
961+
eventFunctionName,
962+
event + " returns no string: " + eventOutput
963+
);
960964
return callback();
961965
}
962966
}
963967
} catch (error) {
964-
warn(errorText + " in your event function: " + error);
968+
warnInFunction(eventFunctionName, error);
965969
return callback();
966970
}
967971

0 commit comments

Comments
 (0)