remove lodash dependency and add once helper

This commit is contained in:
selberhad 2022-10-06 20:47:51 -04:00
parent 4e58b70a06
commit 2e9bc79cb9
2 changed files with 18 additions and 7 deletions

View file

@ -32,6 +32,20 @@ let goldenlayout = (function () {
id: "inputComponent",
};
// helper function: only allow a function to be called once
function once(func) {
function _f() {
if (!_f.isCalled) {
_f.isCalled = true;
_f.res = func.apply(this, arguments);
}
return _f.res;
}
_f.prototype = func.prototype;
_f.isCalled = false;
return _f;
}
// helper function: filter vals out of array
function filter (vals, array) {
if( Array.isArray( vals ) && Array.isArray( array ) ) {
@ -248,8 +262,8 @@ let goldenlayout = (function () {
}
//
// ensure only one handler is set up on the parent with _.once
var registerInputTabChangeHandler = _.once(function (tab) {
// ensure only one handler is set up on the parent with once
var registerInputTabChangeHandler = once(function (tab) {
tab.header.parent.on( "activeContentItemChanged", onActiveInputTabChange );
});
@ -261,8 +275,8 @@ let goldenlayout = (function () {
}
//
// ensure only one handler is set up on the parent with _.once
var registerMainTabChangeHandler = _.once(function (tab) {
// ensure only one handler is set up on the parent with once
var registerMainTabChangeHandler = once(function (tab) {
tab.header.parent.on( "activeContentItemChanged", onActiveMainTabChange );
});

View file

@ -21,9 +21,6 @@ JQuery available.
<link rel="icon" type="image/x-icon" href="/static/website/images/evennia_logo.png" />
<!-- Lodash -->
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js" integrity="sha256-qXBd/EfAdjOA2FGrGAG+b3YBn2tn5A6bhz+LSgYD96k=" crossorigin="anonymous"></script>
<!-- Import JQuery and warn if there is a problem -->
{% block jquery_import %}
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>