Skip to content

Replaced .el() with .el_()#4574

Open
agryder-work wants to merge 3 commits intodevelopmentfrom
agryder-replaceElement.el
Open

Replaced .el() with .el_()#4574
agryder-work wants to merge 3 commits intodevelopmentfrom
agryder-replaceElement.el

Conversation

@agryder-work
Copy link
Collaborator

Fixes #4555

function adjustTopBarHeight() {
if ( ! this.headerSlot_ ) return;
let root = this.document.documentElement;
this.headerSlot_.el().then(el => {
Copy link
Owner

Choose a reason for hiding this comment

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

The old el() method returns a Promise, which is why you need to do a .then() to wait for the promise to resolve. But the new el_() method just returns the element directly, so then then() or await's are no longer needed. So this code would be converted to just:
root?.style.setProperty('--topbar-height', this.headerSlot_.el_().offsetHeight + 'px' );

},
async function addHeaderObserver() {
const root = await this.el();
const root = await this.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

In this case, you would remove the 'await', which would also mean you could remove the 'async' from the function if this is the only place in the function that await is used.

var resize = new ResizeObserver (this.adjustTopBarHeight);
this.onDetach(resize.disconnect());
this.headerSlot_?.el().then(el => {
this.headerSlot_?.el_().then(el => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is also a then() here.. do we need to get rid of that, as well?

Copy link
Owner

Choose a reason for hiding this comment

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

let el = this.headerSlot_?.el_();
if ( el ) resize.observe(el);

OR

if ( this.headerSlot_ ) resize.observe(this.headerSlot_.el_());

There is no need for a then() anymore because el_() returns the element directly rather than via a Promise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, thank you!

this.headerSlot_.el().then(el => {
root?.style.setProperty('--topbar-height', el.offsetHeight + 'px' );
})
root?.style.setProperty('--topbar-height', el.offsetHeight + 'px' );
Copy link
Owner

Choose a reason for hiding this comment

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

This one looks wrong. Where does 'el' come from? Previously it came from this.headerSlot_.el().

.addClass(this.myClass('img')).end();

this.el().then((v) => {
this.el_().then((v) => {
Copy link
Owner

Choose a reason for hiding this comment

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

No then(), since it is synchronous.

this.SUPER();

this.out$.sub(() => this.el().then(e => e.scrollTop = e.scrollHeight));
this.out$.sub(() => this.el_().then(e => e.scrollTop = e.scrollHeight));
Copy link
Owner

Choose a reason for hiding this comment

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

No then().

// U2 or U3
var a = start('b');
a.el().then(el => el.innerHTML = 'foobar');
a.el_().then(el => el.innerHTML = 'foobar');
Copy link
Owner

Choose a reason for hiding this comment

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

No then.
Just a.el_().innerHTML = 'foobar';

}

var el = await this.el();
var el = await this.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No need for 'await' since it is sync.

async function onDelete() {
// do the deletion
var el = await this.childNodes[this.currentIndex].el();
var el = await this.childNodes[this.currentIndex].el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No await.

async function render() {
var parent = this.parentNode;
var parentE = await parent.el();
var parentE = await parent.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No await

isFramed: true,
code: async function() {
var el = await this.el();
var el = await this.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No await

async function eToObj(event) {
/** Find the object associated with a DOM element. **/
var me = await this.el();
var me = await this.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No await


async function setTooltip(evt) {
var el = await this.target.el();
var el = await this.target.el_();
Copy link
Owner

Choose a reason for hiding this comment

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

No await. Remaining errors are of the same type as this or previous ones.

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.

Replace uses of Element.el() with Element.el_()

2 participants