-
Notifications
You must be signed in to change notification settings - Fork 46
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
Suggestion with Web components? #110
Comments
Events is definitely the way I'd recommend, it's more standards compliant. I try to only use pushMessage for things that cannot really be done by events. I keep meaning to add some helpers for listening and pushing events but they are pretty easy to write yourself. Just make a new Cmd to 'send' an event out and make a new Sub type to 'listen' to global events or listen for directed events on the view itself. For a Custom Component wrapping as you are doing then pushMessage would be most useful for passing lifecycle and property update events into the system I'd think. I really should make a new Application type to handle this automatically (though PR's welcome! ^.^). :-) |
Thank you @OvermindDL1. This is a good start. Yes, I am definitely looking to have a PR but it would take some time. Just starting out with |
@OvermindDL1, Is there any way I can get access to the actual DOM node in my custom command? Also, is |
In the worst case you can always just go down to calling into the DOM itself. However, a 'Cmd' isn't associated with a node as it is designed to be front-end agnostic for later running on the server-side without a DOM, so although it can be done that way it may not actually be the best place, hmm... In that case the best method would really be something on the view. This is not something support by Elm either so it might be worth breaking the Elm API just a touch for this, but at least it can be done in a backwards compatible way. A new Program Type that accepts a Although at that point it would probably be best just to make a WebComponent program type that abstracts all that out more properly. ^.^ At the very least to get going 'now' you can give your root vdom an
You can but that's more useful for chaining things rather than pushing back into the main event loop (I prefer main event loop, but either way works fine). If you want to just make a normal Cmd you can basically copy this file into you app and just make a change to fire the event instead of acquire focus: let focus id =
Tea_cmd.call
(fun _enqueue ->
let ecb _ =
match Js.Nullable.toOption (Web.Document.getElementById id) with
| None ->
Js.log ("Attempted to fire event on a non-existant element of: ", id)
| Some elem -> <do-your-code-here, construct the Event then `dispatchEvent`>
in
ignore (ecb ());
()) The Web API built in exists before the one bucklescript had so you can just use bucklescript's API instead as it's more complete. You can use the API in this project by either adding the proper |
Thank you for your reply. I was able to get most of the things done. The idea of At a glance, I am piggybacking a dispatcher object having a // Trust simple dumb JS Closures
const dispatcher = {
trigger: (name, /* extra data */) => {
// this here refers to the Custom Element
this.dispatchEvent(new CustomEvent(name));
}
};
// Initiate TEA event loop
this._mainLoop = main(this[shadowRoot], dispatcher); The only cons is to currently maintain to this dispatcher object as part of the |
Specifically a webcomponent program type would listen for registrations via normal But yeah, a bouncer JS object is perfectly sufficient, basically what it will be doing in the background anyway. :-) |
Thank you for the great library. It has been a great experience so far.
I am trying to wrap bucklescript-tea component into web components. The initial skeleton looks like this:
I was wondering if you have any suggestions for observing props in a typesafe manner. Currently, I am thinking of manually accepting the list of prop string to be observed and adding setter for each prop. Something like this:
The plan is to either raise a custom event or call
pushMessage
directly from the prop setter. I am not sure if this is the right approach. Any suggestions on how I can do interoperability with JavaScript; specifically in the context of custom elements?The text was updated successfully, but these errors were encountered: