adds utility.js as facade to generic javascript utility functio… (#7738)

This commit is contained in:
Nathan Woulfe
2020-03-25 02:48:14 +10:00
committed by GitHub
parent b6a34ebac7
commit b082d40921
11 changed files with 106 additions and 21 deletions

View File

@@ -19,10 +19,10 @@
"tinyMCE": false,
"FileReader": false,
"Umbraco": false,
"Utilities": false,
"window": false,
"LazyLoad": false,
"ActiveXObject": false,
"Bloodhound": false
}
}

View File

@@ -28,7 +28,7 @@ module.exports = {
installer: { files: "./src/installer/**/*.js", out: "umbraco.installer.js" },
filters: { files: "./src/common/filters/**/*.js", out: "umbraco.filters.js" },
resources: { files: "./src/common/resources/**/*.js", out: "umbraco.resources.js" },
services: { files: "./src/common/services/**/*.js", out: "umbraco.services.js" },
services: { files: ["./src/common/services/**/*.js", "./src/utilities.js"], out: "umbraco.services.js" },
security: { files: "./src/common/interceptors/**/*.js", out: "umbraco.interceptors.js" },
//the controllers for views

View File

@@ -178,11 +178,11 @@ function angularHelper($q) {
$valid: true,
$submitted: false,
$pending: undefined,
$addControl: angular.noop,
$removeControl: angular.noop,
$setValidity: angular.noop,
$setDirty: angular.noop,
$setPristine: angular.noop,
$addControl: Utilities.noop,
$removeControl: Utilities.noop,
$setValidity: Utilities.noop,
$setDirty: Utilities.noop,
$setPristine: Utilities.noop,
$name: formName
};
}

View File

@@ -1,4 +1,3 @@
/**
* @ngdoc controller
* @name Umbraco.MainController

View File

@@ -0,0 +1,86 @@
/**
* A friendly utility collection to replace AngularJs' ng-functions
* If it doesn't exist here, it's probably available as vanilla JS
*
* Still carries a dependency on underscore, but if usages of underscore from
* elsewhere in the codebase can instead use these methods, the underscore
* dependency will be nicely abstracted and can be removed/swapped later
*
* This collection is open to extension...
*/
(function (window) {
/**
* Equivalent to angular.noop
*/
const noop = () => { };
/**
* Facade to angular.copy
*/
const copy = val => angular.copy(val);
/**
* Equivalent to angular.isArray
*/
const isArray = val => Array.isArray(val) || val instanceof Array;
/**
* Facade to angular.equals
*/
const equals = (a, b) => angular.equals(a, b);
/**
* Facade to angular.extend
* Use this with Angular objects, for vanilla JS objects, use Object.assign()
*/
const extend = (dst, src) => angular.extend(dst, src);
/**
* Equivalent to angular.isFunction
*/
const isFunction = val => typeof val === 'function';
/**
* Equivalent to angular.isUndefined
*/
const isUndefined = val => typeof val === 'undefined';
/**
* Equivalent to angular.isDefined. Inverts result of const isUndefined
*/
const isDefined = val => !isUndefined(val);
/**
* Equivalent to angular.isString
*/
const isString = val => typeof val === 'string';
/**
* Equivalent to angular.isNumber
*/
const isNumber = val => typeof val === 'number';
/**
* Equivalent to angular.isObject
*/
const isObject = val => val !== null && typeof val === 'object';
let _utilities = {
noop: noop,
copy: copy,
isArray: isArray,
equals: equals,
extend: extend,
isFunction: isFunction,
isUndefined: isUndefined,
isDefined: isDefined,
isString: isString,
isNumber: isNumber,
isObject: isObject
};
if (typeof (window.Utilities) === 'undefined') {
window.Utilities = _utilities;
}
})(window);

View File

@@ -325,7 +325,7 @@
/* ---------- SAVE ---------- */
function save() {
saveInternal().then(angular.noop, angular.noop);
saveInternal().then(Utilities.noop, Utilities.noop);
}
/** This internal save method performs the actual saving and returns a promise, not to be bound to any buttons but used by other bound methods */

View File

@@ -15,7 +15,7 @@
packageResource.getAllCreated().then(createdPackages => {
vm.createdPackages = createdPackages;
}, angular.noop);
}, Utilities.noop);
}

View File

@@ -80,7 +80,7 @@
activate: false
});
completeSave(saved);
}, angular.noop);
}, Utilities.noop);
} else {

View File

@@ -168,7 +168,7 @@
extendedSave(saved).then(function(result) {
//if all is good, then reset the form
formHelper.resetForm({ scope: $scope });
}, angular.noop);
}, Utilities.noop);
vm.user = _.omit(saved, "navigation");
//restore

View File

@@ -112,7 +112,7 @@
userGroupsResource.deleteUserGroups(_.pluck(vm.selection, "id")).then(function (data) {
clearSelection();
onInit();
}, angular.noop);
}, Utilities.noop);
overlayService.close();
}
};

View File

@@ -386,7 +386,7 @@
vm.selectedBulkUserGroups = [];
editorService.close();
clearSelection();
}, angular.noop);
}, Utilities.noop);
},
close: function () {
vm.selectedBulkUserGroups = [];