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

Proposal: Generic launch example #198

Closed
stevechy opened this issue May 4, 2023 · 7 comments
Closed

Proposal: Generic launch example #198

stevechy opened this issue May 4, 2023 · 7 comments

Comments

@stevechy
Copy link
Contributor

stevechy commented May 4, 2023

I was trying out Tyrian and wrote a simple launcher based on how react-rails mounts elements.

There's some extra Promise wrapping around it but the basic idea is.

        for {element <- dom.document.querySelectorAll("[data-tyrian-app]")
             } yield {
          val htmlElement = element.asInstanceOf[HTMLElement]
          htmlElement.dataset.get("tyrianApp") match {
            case Some("MyCustomApp") => {
              println("Launching")
              new MyCustomApp().launch(element)
            }
            case _ => ()
          }
        }

Flags could also be read from the dataset

Does this seem useful?

@davesmith00000
Copy link
Member

Yes I like it. So if I'm reading it right, the idea would be to launch from the main method, and that essentially does the above? (+ flags in the dataset)

Have I got that right?

One of the common questions I get quite often is "why can't I just use the main method?" and the answer is of course that you can! ...but we don't have many examples, nor is there a good built in solution for that.

@stevechy
Copy link
Contributor Author

stevechy commented May 5, 2023

Yep, I'm currently launching this from the main method. It looks like if the bundle is loaded as a regular script vs module it has to wait for DOMContentLoaded so I also have some handling for that.

I could create a PR with an example in the examples folder?

@davesmith00000
Copy link
Member

Hi @stevechy - I was wondering about baking it into the main launcher, here somewhere:

https://github.com/PurpleKingdomGames/tyrian/blob/main/tyrian/js/src/main/scala/tyrian/TyrianAppF.scala

Although I confess that at the moment I don't know exactly what that would look like!

If you felt like having a go, you could either work on the main launcher, or add an example - as you suggested - that we could use as the basis for the launcher version later (that I could help with). It would be great to have either contributed if you have the time, no pressure. 😄

stevechy added a commit to stevechy/tyrian that referenced this issue May 5, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 5, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 5, 2023
@stevechy
Copy link
Contributor Author

stevechy commented May 5, 2023

Ok, I created #200 I guess I should have made it a draft.

@stevechy
Copy link
Contributor Author

stevechy commented May 9, 2023

Having multiple apps probably doesn't fit with the Elm Architecture but I find it useful to get things up and running.

  <div data-tyrian-app="CounterApp" data-tyrian-app-flag-initial-counter="42"></div>

  <div data-tyrian-app="ChatApp" data-tyrian-app-flag-initial-message="Hello"></div>

stevechy added a commit to stevechy/tyrian that referenced this issue May 16, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 16, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 16, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 16, 2023
stevechy added a commit to stevechy/tyrian that referenced this issue May 17, 2023
…ap. Update flag data-attr to data-tyrian-flag. Fixed the types to IO and ZIO in tyrian-io and tyrian-zio.
davesmith00000 pushed a commit that referenced this issue May 17, 2023
* #198 : Add a launch method that scans for data-tyrian-app container elements

* #198 : Add main-launcher example

* #198 : Update launch method name and signature.  Add TyrianApp companion objects.

* #198 : Change TyrianAppF to take both varargs and Map.  Update flag data-attr to data-tyrian-flag.  Fixed the types to IO and ZIO in tyrian-io and tyrian-zio.
@davesmith00000
Copy link
Member

The PR has been merged and this feature will be in the next release - thanks for all the work @stevechy! 😄

@stevechy
Copy link
Contributor Author

That's great! Looking forward to using this instead of the messy version in my current project 😄

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