Skip to content

Conversation

@trusktr
Copy link

@trusktr trusktr commented Oct 24, 2017

This also prevents from modifying the custom attribute's this.value when disconnected, so that the old value can be used in the disconnected logic (because the value wasn't changed, the attribute was removed).

@trusktr
Copy link
Author

trusktr commented Oct 24, 2017

Anything I should add to tests?

@trusktr
Copy link
Author

trusktr commented Oct 25, 2017

Oops, realized I changed the wrong file. Let me edit...

…back instead of disconnectedCallback removing an attribute
…disconnectedCallback logic can rely on the value (i.e. the attribute value didn't change, the attribute was removed)
@trusktr
Copy link
Author

trusktr commented Oct 25, 2017

Alright, updated.

@matthewp
Copy link
Owner

Thanks! I'll probably add a test to this before merging.

@matthewp matthewp closed this Oct 25, 2017
@matthewp matthewp reopened this Oct 25, 2017
@matthewp
Copy link
Owner

Woops, closed by mistake.

* master:
  bump travis node version
  build to test
  use @pika/pack to build
}
// Attribute was removed
else if(newVal == null && !!inst.value) {
inst.value = newVal;
Copy link
Author

Choose a reason for hiding this comment

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

The reasoning here is that this.value will show the last value that the Custom Attribute had while being disconnected.

So it's more of like null doesn't exist in the eyes of a Custom Attribute, instead it should just get disconnected. The null is a value in the eyes of an element (f.e. Custom Element), so that it knows an attribute is not connected (the custom attributes that this is the case when disconnectedCallback is called).

In my use cases, I found it useful to know what the last value was during disconnected (and I can automatically infer the DOM's is null due to disconnectedCallback, though in practice I never need the null value, because I already know when my custom attribute is disconnected and can react to that).

}
}
// Attribute was removed
else if(newVal == null && !!inst.value) {
Copy link
Author

Choose a reason for hiding this comment

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

Example: if a custom attribute is some-attribute="", and then it gets removed, the newVal will be null, and the current inst.value will "" which is falsy, which then causes the conditional to incorrectly skip calling disconnectedCallback.

@trusktr
Copy link
Author

trusktr commented Aug 5, 2019

I'll add a test soon...

@trusktr
Copy link
Author

trusktr commented Jul 7, 2020

I need to circle back to this! Putting it on my Todo list this time.

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.

2 participants