Skip to content

Meta: Deinit all feature delegates using AbortSignal - #5726

Merged
fregante merged 8 commits into
mainfrom
abort-delegates
Jul 30, 2022
Merged

fregante merged 8 commits into
mainfrom
abort-delegates

Conversation

@cheap-glitch

@cheap-glitch cheap-glitch commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor

rocket

@cheap-glitch cheap-glitch added the meta Related to Refined GitHub itself label Jun 25, 2022

@cheap-glitch cheap-glitch left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the next step is to add support for AbortSignal into selector-observer so we can get rid of Deinit completely 🙂

Comment thread source/globals.d.ts Resolved

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6eg

Comment thread source/features/index.tsx Resolved
Comment thread source/features/prevent-link-loss.tsx Outdated
Comment on lines +69 to +70

return updateUI.cancel;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts?

Suggested change
return updateUI.cancel;
signal.addEventListener('abort', updateUI.cancel);

I'd love to have an onAbort(emitter: signal, listener: function | controller) helper for this kind of situations:

Suggested change
return updateUI.cancel;
onAbort(signal, updateUI.cancel)

and also when we have multiple controllers and we want to link them together, like:

function foo(otherSignal) {
	const controller = new AbortController
	onAbort(otherSignal, controller)
	return controller;
}

In this case, controller would also be aborted when otherSignal is aborted.

I'm not sure it's useful in this specific case though, return fn will always be more convenient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this specific case we should just drop this. There's no chance that the user changes page within 300ms of the last keypress

Comment thread source/features/quick-mention.tsx Resolved
Comment thread source/github-events/on-new-comments.ts Resolved
Comment thread source/github-events/on-new-comments.ts Resolved
delegate(document, '.rgh-prevent-link-loss', 'click', handleButtonClick),
];
function init(signal: AbortSignal): Deinit {
delegate(document, 'form:is(#new_issue, #new_release) textarea, form.js-new-comment-form textarea, textarea.comment-form-textarea', 'input', updateUI, {signal});

@fregante fregante Jun 26, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiline selector? Maybe in the lint PR after this one is merged

@fregante fregante changed the title Deinit all feature delegates using AbortSignal Meta: Deinit all feature delegates using AbortSignal Jun 26, 2022
@fregante
fregante marked this pull request as draft July 3, 2022 12:23
@fregante fregante mentioned this pull request Jul 7, 2022
2 tasks done
@fregante

fregante commented Jul 29, 2022 •

Copy link
Copy Markdown
Member

Ping on this if you have time, the onAbort helper was added. I resolved all the comments that are no longer applicable, this only needs conflict resolution and a couple more changes

@fregante fregante self-assigned this Jul 30, 2022
@fregante
fregante marked this pull request as ready for review July 30, 2022 07:11
@fregante fregante removed their assignment Jul 30, 2022
@fregante

Copy link
Copy Markdown
Member

you only live once

@fregante
fregante merged commit 50cb939 into main Jul 30, 2022
@fregante
fregante deleted the abort-delegates branch July 30, 2022 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

2 participants