Skip to content

Commit

Permalink
Fixed dynamic inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilian-iliev-io committed Mar 22, 2023
1 parent 7f202ac commit a05f99c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 10 additions & 3 deletions javascript/state.ext.control-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ state.extensions['control-net'] = (function () {
select.addEventListener('change', function () {
store.set(id, this.value);
});
if (id === 'preprocessor' && value && value !== 'none') {
state.utils.onNextUiUpdates(handleSliders); // update new sliders if needed
}
});
}

Expand Down Expand Up @@ -110,9 +113,7 @@ state.extensions['control-net'] = (function () {
});
}

function init() {
container = gradioApp().getElementById('controlnet');
store = new state.Store('ext-control-net');
function load() {
handleToggle();
handleTabs();
handleCheckboxes();
Expand All @@ -121,5 +122,11 @@ state.extensions['control-net'] = (function () {
handleRadioButtons();
}

function init() {
container = gradioApp().getElementById('controlnet');
store = new state.Store('ext-control-net');
load();
}

return { init };
}());
22 changes: 22 additions & 0 deletions javascript/state.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,27 @@ state.utils = {
},
txtToId: function txtToId(txt) {
return txt.split(' ').join('-').toLowerCase();
},
callXTimes: function callXTimes(func, times) {
let called = 0;
return function() {
if (called < times) {
called++;
return func.apply(this);
}
}
},
debounce: function debounce(func, delay) {
let lastCallTime = 0;
return function() {
const currentCallTime = new Date().getTime();
if (currentCallTime - lastCallTime > delay) {
lastCallTime = currentCallTime;
func.apply(this, arguments);
}
}
},
onNextUiUpdates: function (func) {
onUiUpdate(this.callXTimes(this.debounce(func, 50), 10));
}
};

0 comments on commit a05f99c

Please sign in to comment.