From 43b4de7cbbd212734611acc46e635d2cbb4185da Mon Sep 17 00:00:00 2001 From: "adrian.flood" Date: Fri, 24 Mar 2017 16:26:29 +0000 Subject: [PATCH 1/2] Fixed "reduce is not a function" errors. --- src/calendar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 7ac3056..84669fe 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -70,7 +70,7 @@ angular.module('ui.calendar', []) this.allEvents = function () { return Array.prototype.concat.apply( [], - (sources || []).reduce( + (Array.from(sources) || []).reduce( function (previous, source) { if (angular.isArray(source)) { previous.push(source); @@ -108,7 +108,7 @@ angular.module('ui.calendar', []) var self; var getTokens = function () { - return ((angular.isFunction(arraySource) ? arraySource() : arraySource) || []).reduce( + return (Array.from(angular.isFunction(arraySource) ? arraySource() : arraySource) || []).reduce( function (rslt, el) { var token = tokenFn(el); map[token] = el; From 2e0b162a77359bf4784026580124efc399ed2fa9 Mon Sep 17 00:00:00 2001 From: "adrian.flood" Date: Mon, 5 Jun 2017 13:51:14 +0100 Subject: [PATCH 2/2] Set sensible defaults to prevent errors from doing Array.from(undefined). --- src/calendar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 84669fe..c53ffb1 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -16,7 +16,7 @@ angular.module('ui.calendar', []) .controller('uiCalendarCtrl', ['$scope', '$locale', function ($scope, $locale) { - var sources = $scope.eventSources; + var sources = typeof ($scope.eventSources) !== "undefined" && $scope.eventSources !== null ? $scope.eventSources : []; var extraEventSignature = $scope.calendarWatchEvent ? $scope.calendarWatchEvent : angular.noop; var wrapFunctionWithScopeApply = function (functionToWrap) { @@ -240,7 +240,7 @@ angular.module('ui.calendar', []) }, controller : 'uiCalendarCtrl', link : function (scope, elm, attrs, controller) { - var sources = scope.eventSources; + var sources = typeof (scope.eventSources) !== "undefined" && scope.eventSources !== null ? scope.eventSources : []; var sourcesChanged = false; var calendar; var eventSourcesWatcher = controller.changeWatcher(sources, controller.sourceFingerprint); @@ -362,4 +362,4 @@ angular.module('ui.calendar', []) }; } ] -); + );