billgoo / vscode-tab-group

MIT License
19 stars 3 forks source link

optimize tab change and tree data change logic #9

Open Jiapeiyao opened 2 years ago

Jiapeiyao commented 2 years ago

Tab change will trigger tree data change, and tree data change (by some user operation on the extension) will also trigger tab change, so we need to get rid of unnecessary event triggering. (I was not very careful when coding this piece, so there could be some bugs that will lead to potential performance issue.)

moalamri commented 1 year ago

I was able to control unnecessary events triggers by controlling them in a class I created EventsLimit and control when to trigger accordingly.

You just have to init the class instance:

const elimit = new EventsLimit();

Register the callback function (the function in which you want to be triggered once):

// pass function name without the parentheses
elimit.Register(triggerUpdate);

function triggerUpdate() {
// action
}

Now, you can control when to call the callback function by adding either elimit.Lead(); or elimit.Tail(); in all the events triggers as I have done here.

Lead

Will fire the first time it get called and ignore any other calls for a period of time (defaults 100ms).

Tail

Will ignore all events calls for a period of time and call your function once only at the end of the period (defaults 100).

note 🗒️

You can change the defaults when first initiating the class:

const elimit = new EventsLimit(200,200); // Tail, Lead

I hope this helps 👍🏻