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

Question about HTMLElement-in-state warning #401

Open
txbm opened this issue Nov 25, 2024 · 4 comments
Open

Question about HTMLElement-in-state warning #401

txbm opened this issue Nov 25, 2024 · 4 comments

Comments

@txbm
Copy link

txbm commented Nov 25, 2024

Is this warning still relevant when you wrap the HTMLElement in ObservableHint.opaque ?

console.warn(`[legend-state] Set an HTMLElement into state. You probably don't want to do that.`);

If so, I'd like to understand why (I have seemingly legitimate use cases for wanting HTMLElement references in my state). And if not then I'd vote for not issuing the warning if the element is properly wrapped.

Thanks.

@nightire
Copy link

nightire commented Dec 4, 2024

I believe the answer is already in the document here: https://www.legendapp.com/open-source/state/v3/usage/helper-functions/#observablehintopaque

@txbm
Copy link
Author

txbm commented Dec 28, 2024

I read those docs first and they do not state why this warning is relevant when .opaque is used over an HTMLElement. Hence my question

@nightire
Copy link

@txbm You mean something like this?

const store$ = observable<{ element: null | HTMLElement }>({
  element: null
})

store$.element.set(ObservableHint.opaque(element)) // causes warning here

You might be correct since opaque defines a new property with a Symbol on the passing value to prevent setting listeners on it later. This warning only checks if the passing value is an instance of HTMLElement; it should also check if it has the opaque symbol property.

@txbm
Copy link
Author

txbm commented Dec 29, 2024

That is exactly what I am asking thank you.

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

No branches or pull requests

2 participants