Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expectElement() #23

Merged
merged 8 commits into from
Oct 20, 2023
Merged

Add expectElement() #23

merged 8 commits into from
Oct 20, 2023

Conversation

fregante
Copy link
Owner

@fregante fregante commented Oct 9, 2023

Closes #20

@fregante fregante marked this pull request as ready for review October 9, 2023 06:02
@fregante
Copy link
Owner Author

fregante commented Oct 9, 2023

Will be used in https://github.com/refined-github/refined-github/pull/6973/files#diff-c95e377cf1c957e2609d26792bac720c60f2cff7e2b2fadec703a5dc5764ab2fR13-R22

Unfortunately thrown errors can't specify the original feature like features.log.error can, unless thrown in the init

I think the only way to achieve this would be to pre-wrap every callback to provide the source, .e.g.

observe(selector, wrap(import.meta.url, addButton));

function addButton(parent) {
	parent.append(<button/>)
}
// utils.js
function wrap(feature, callback) {
	return (...args) =>  {
		try {
			callback(...args)
		} catch (error) {
			features.log.error(feature, error);
		}
	}
}

I think this would work, if we remember to wrap each and every callback 😬

This is where decorators would be useful, too bad they're only available to classes 🤦‍♂️

@callback(import.meta.url)
function addButton(parent) {
	parent.append(<button/>)
}

cc @yakov116 @134130

Copy link

@134130 134130 left a comment

Choose a reason for hiding this comment

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

LGTM

@yakov116
Copy link

yakov116 commented Oct 9, 2023

Looks great

Base automatically changed from api to main October 20, 2023 11:50
@fregante fregante merged commit b8c6d1e into main Oct 20, 2023
6 checks passed
@fregante fregante deleted the expect branch October 20, 2023 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add select.expect
3 participants