Closed AngelMunoz closed 2 years ago
This looks amazing.
It's not a massive issue with observing external manipulation (in my opinion) - you shouldn't do that to a component in any case, even though the DOM API allows it. As you say, if you think a particular component may want to check for it, then the observation APIs can help. For example, we'd never consider finding the WPF UIElement for a textbox and setting the internal text value, and expect the application to handle / respond to that.
I can happily say that YES IT WORKS by using the Haunted component
function!
check the last commit of this PR, it will need a little bit more of work because props don't seem to be automatically changed unless I start tracking attributes, but attributes are always strings so this might be troublesome but that is more about experimenting rather than still trying to figure out if it works
I think we can close this and I can pursue that over the Fable.Haunted
repo
As we've been discussing in #32 I took a step into a rough implementation (at least on the JS side) of a class factory that ties some of the Sutil semantics with the class and it's declaration as a custom element Please take a look at the two main files here
Above we're Simply exporting two functions that will help us define web components, I had to make this a JS file because (1st familiarity, 2nd I'm not sure we can return anonymous classes in F#) basically when we attach a shadow root (not required for custom elements but helpful for style encapsulation) we can use it as the context for the SutilElement the
build
andasDomElement
functions will internally append the view function result to the shadow DOM (since it is the context) at this point it already works but it is unable to respond to external manipulation (e.g. attribute changes, property changes), since that is a common case for WebComponents/CustomElements I just added getters and setters viaObject.defineProperty
which read/write values from the elemen'ts store, in addition thestatic get observedAttributes() { return Object.keys(defaultValues); }
also allows us to observe HTML Attributes and since we're using the same attribute changed callback invoked when attributes change we're able to do the followingor update the attributes in the HTML to update the values, please note that we're not reflecting attributes hence why the attributes don't change when the store does so.
In the case of the F# side, we don't really need to do much different things from what we already do
This approach does have some caveats though
Object.keys
in the js function), either an anonymoys object or a recorddisposeOnUnmount [ store ]
for it to show on the JS side, also the store should be based of the function's first parameter for it to behave as it does in the gif above.What are we missing?