Skip to content

Commit

Permalink
V8: Angular Divorce: isFunction (#7861)
Browse files Browse the repository at this point in the history
* Bye bye angular.isFunction & use Utilities.isFunction

* Utilities.js is not available on first load - replace isFunction detection with underscore equivalent

* found a stray isFunction

Co-authored-by: Kenn Jacobsen <[email protected]>
Co-authored-by: Nathan Woulfe <[email protected]>
  • Loading branch information
3 people authored Jan 19, 2021
1 parent 0822f0c commit 9601dea
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Umbraco.Web.UI.Client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ angular.module("umbraco.viewcache", [])
// be able to configure angular values in the Default.cshtml
// view which is much easier to do that configuring values by injecting them in the back office controller
// to follow through to the js initialization stuff
if (angular.isFunction(document.angularReady)) {
if (_.isFunction(document.angularReady)) {
document.angularReady.apply(this, [app]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
//load the tree
loadTree().then(function () {
//because angular doesn't return a promise for the resolve method, we need to resort to some hackery, else
//like normal JS promises we could do resolve(...).then()
if (args && args.onLoaded && angular.isFunction(args.onLoaded)) {
//like normal JS promises we could do resolve(...).then()
if (args && args.onLoaded && Utilities.isFunction(args.onLoaded)) {
args.onLoaded();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
if (Utilities.isDefined(opts.firstLineNumber)) {
if (Utilities.isNumber(opts.firstLineNumber)) {
session.setOption('firstLineNumber', opts.firstLineNumber);
} else if (angular.isFunction(opts.firstLineNumber)) {
} else if (Utilities.isFunction(opts.firstLineNumber)) {
session.setOption('firstLineNumber', opts.firstLineNumber());
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@

// onLoad callbacks
angular.forEach(opts.callbacks, function(cb) {
if (angular.isFunction(cb)) {
if (Utilities.isFunction(cb)) {
cb(acee);
}
});
Expand Down Expand Up @@ -208,7 +208,7 @@

if (Utilities.isDefined(callback)) {
scope.$evalAsync(function() {
if (angular.isFunction(callback)) {
if (Utilities.isFunction(callback)) {
callback(args);
} else {
throw new Error('ui-ace use a function as callback.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

// advanced item filtering is handled here
if (scope.entityTypeFilter && scope.entityTypeFilter.filter && scope.entityTypeFilter.filterAdvanced) {
var filtered = angular.isFunction(scope.entityTypeFilter.filter)
var filtered = Utilities.isFunction(scope.entityTypeFilter.filter)
? _.filter(miniListView.children, scope.entityTypeFilter.filter)
: _.where(miniListView.children, scope.entityTypeFilter.filter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function valPropertyValidator(serverValidationManager) {

var modelCtrl = ctrls[0];
var propCtrl = ctrls.length > 1 ? ctrls[1] : null;
// Check whether the scope has a valPropertyValidator method
if (!scope.valPropertyValidator || !angular.isFunction(scope.valPropertyValidator)) {

// Check whether the scope has a valPropertyValidator method
if (!scope.valPropertyValidator || !Utilities.isFunction(scope.valPropertyValidator)) {
throw new Error('val-property-validator directive must specify a function to call');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ function angularHelper($q) {
*/
safeApply: function (scope, fn) {
if (scope.$$phase || (scope.$root && scope.$root.$$phase)) {
if (angular.isFunction(fn)) {
if (Utilities.isFunction(fn)) {
fn();
}
}
else {
if (angular.isFunction(fn)) {
if (Utilities.isFunction(fn)) {
scope.$apply(fn);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
//instead of having a property editor $watch their expression to check if it has
// been updated, instead we'll check for the existence of a special method on their model
// and just call it.
if (angular.isFunction(origProp.onValueChanged)) {
if (Utilities.isFunction(origProp.onValueChanged)) {
//send the newVal + oldVal
origProp.onValueChanged(origProp.value, origVal);
}
Expand Down Expand Up @@ -643,7 +643,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
// soft-redirecting which means the URL will change but the route wont (i.e. creating content).

// In this case we need to detect what properties have changed and re-bind them with the server data.
if (args.rebindCallback && angular.isFunction(args.rebindCallback)) {
if (args.rebindCallback && Utilities.isFunction(args.rebindCallback)) {
args.rebindCallback();
}

Expand Down Expand Up @@ -690,7 +690,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
// soft-redirecting which means the URL will change but the route wont (i.e. creating content).

// In this case we need to detect what properties have changed and re-bind them with the server data.
if (args.rebindCallback && angular.isFunction(args.rebindCallback)) {
if (args.rebindCallback && Utilities.isFunction(args.rebindCallback)) {
args.rebindCallback();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function eventsService($q, $rootScope) {

/** pass in the result of 'on' to this method, or just call the method returned from 'on' to unsubscribe */
unsubscribe: function(handle) {
if (angular.isFunction(handle)) {
if (Utilities.isFunction(handle)) {
handle();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Umbraco.Web.UI.Client/src/common/services/tree.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
}
});
}
else if (args.filter && angular.isFunction(args.filter)) {
else if (args.filter && Utilities.isFunction(args.filter)) {
//if a filter is supplied a cacheKey must be supplied as well
if (!args.cacheKey) {
throw "args.cacheKey is required if args.filter is supplied";
Expand Down Expand Up @@ -315,7 +315,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
args.node.hasChildren = true;

//Since we've removed the children & reloaded them, we need to refresh the UI now because the tree node UI doesn't operate on normal angular $watch since that will be pretty slow
if (angular.isFunction(args.node.updateNodeData)) {
if (Utilities.isFunction(args.node.updateNodeData)) {
args.node.updateNodeData(args.node);
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
* @param {object} treeNode the node to remove
*/
removeNode: function (treeNode) {
if (!angular.isFunction(treeNode.parent)) {
if (!Utilities.isFunction(treeNode.parent)) {
return;
}

Expand Down Expand Up @@ -509,7 +509,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
if (current.metaData && current.metaData["treeAlias"]) {
root = current;
}
else if (angular.isFunction(current.parent)) {
else if (Utilities.isFunction(current.parent)) {
//we can only continue if there is a parent() method which means this
// tree node was loaded in as part of a real tree, not just as a single tree
// node from the server.
Expand Down Expand Up @@ -706,7 +706,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
//to fire, instead we're just going to replace all the properties of this node.

//there should always be a method assigned but we'll check anyways
if (angular.isFunction(node.parent().children[index].updateNodeData)) {
if (Utilities.isFunction(node.parent().children[index].updateNodeData)) {
node.parent().children[index].updateNodeData(found);
}
else {
Expand Down Expand Up @@ -741,7 +741,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
if (!node) {
throw "node cannot be null";
}
if (!angular.isFunction(node.parent)) {
if (!Utilities.isFunction(node.parent)) {
throw "node.parent is not a function, the path cannot be resolved";
}

Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Web.UI.Client/src/installer/installer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ angular.module("umbraco.install").factory('installerService', function ($rootSco
/** Have put this here because we are not referencing our other modules */
function safeApply (scope, fn) {
if (scope.$$phase || scope.$root.$$phase) {
if (angular.isFunction(fn)) {
if (Utilities.isFunction(fn)) {
fn();
}
}
else {
if (angular.isFunction(fn)) {
if (Utilities.isFunction(fn)) {
scope.$apply(fn);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
$scope.model.filterAdvanced = false;

//used advanced filtering
if (angular.isFunction($scope.model.filter)) {
if (Utilities.isFunction($scope.model.filter)) {
$scope.model.filterAdvanced = true;
}
else if (Utilities.isObject($scope.model.filter)) {
Expand All @@ -189,9 +189,9 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
if ($scope.model.filter.startsWith("{")) {
$scope.model.filterAdvanced = true;

if ($scope.model.filterByMetadata && !angular.isFunction($scope.model.filter))
if ($scope.model.filterByMetadata && !Utilities.isFunction($scope.model.filter))
{
var filter = angular.fromJson($scope.model.filter);
var filter = Utilities.fromJson($scope.model.filter);
$scope.model.filter = function (node){ return _.isMatch(node.metaData, filter);};
}
else
Expand Down Expand Up @@ -456,7 +456,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
if ($scope.model.filterAdvanced) {

//filter either based on a method or an object
var filtered = angular.isFunction($scope.model.filter)
var filtered = Utilities.isFunction($scope.model.filter)
? _.filter(nodes, $scope.model.filter)
: _.where(nodes, $scope.model.filter);

Expand Down
16 changes: 8 additions & 8 deletions src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ angular.mock.dump = function (object) {
});
out = '[ ' + out.join(', ') + ' ]';
} else if (Utilities.isObject(object)) {
if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) {
if (Utilities.isFunction(object.$eval) && Utilities.isFunction(object.$apply)) {
out = serializeScope(object);
} else if (object instanceof Error) {
out = object.stack || ('' + object.name + ': ' + object.message);
Expand Down Expand Up @@ -927,7 +927,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
responsesPush = angular.bind(responses, responses.push);

function createResponse(status, data, headers) {
if (angular.isFunction(status)) return status;
if (Utilities.isFunction(status)) return status;

return function () {
return angular.isNumber(status)
Expand All @@ -943,7 +943,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
wasExpected = false;

function prettyPrint(data) {
return (Utilities.isString(data) || angular.isFunction(data) || data instanceof RegExp)
return (Utilities.isString(data) || Utilities.isFunction(data) || data instanceof RegExp)
? data
: angular.toJson(data);
}
Expand Down Expand Up @@ -1372,20 +1372,20 @@ function MockHttpExpectation(method, url, data, headers) {

this.matchUrl = function (u) {
if (!url) return true;
if (angular.isFunction(url.test)) return url.test(u);
if (Utilities.isFunction(url.test)) return url.test(u);
return url == u;
};

this.matchHeaders = function (h) {
if (Utilities.isUndefined(headers)) return true;
if (angular.isFunction(headers)) return headers(h);
if (Utilities.isFunction(headers)) return headers(h);
return Utilities.equals(headers, h);
};

this.matchData = function (d) {
if (Utilities.isUndefined(data)) return true;
if (data && angular.isFunction(data.test)) return data.test(d);
if (data && !Utilities.isString(data)) return angular.toJson(data) == d;
if (data && Utilities.isFunction(data.test)) return data.test(d);
if (data && !Utilities.isString(data)) return Utilities.toJson(data) == d;
return data == d;
};

Expand Down Expand Up @@ -1484,7 +1484,7 @@ angular.mock.$TimeoutDecorator = function ($delegate, $browser) {

function formatPendingTasksAsString(tasks) {
var result = [];
angular.forEach(tasks, function (task) {
Utilities.forEach(tasks, function (task) {
result.push('{id: ' + task.id + ', ' + 'time: ' + task.time + '}');
});

Expand Down

0 comments on commit 9601dea

Please sign in to comment.