sabinbajracharya / Svelte-with-Rescript

A project to showcase the use of ReScript to write Svelte Apps
72 stars 0 forks source link

I'm almost OK with this #1

Open kswope opened 3 years ago

kswope commented 3 years ago

It almost encourages a Service layer architecture where Rescript is your "app", and the .svelte files are just the messy outer interface, which will always be chaotic because you've got JS/CSS/HTML/preprocessors/postprocessors/bundlers/etc. reference Rails is Not Your Application

Now the part that isn't type-checked is the boundary between your display layer and its service layer. You can keep this interface to a minimum by using subscribe() to get data out and simple functions with simple arg types to get data in, like you did. An extra benefit of this discipline is that you can cleanly test it separate from the interface.

If rescript is ever an option is .svelte files then it will be easy conversion.

I tried using typescript in the svelte files and I'm not sure it got me anywhere. Every file needed a .d.ts file and chances are you might not reuse those definitions often so it might end up being one function call per definition, which just means you moved your bugs to the .d.ts files.

And typescript looks awful

  let updateName: svelte.JSX.FormEventHandler<HTMLInputElement> = (e) => {
    update(e.currentTarget.value)
  }
</script>

<main>
  <input on:input={updateName} value={name} placeholder="enter your name" />
  <p>Hello {name || "stranger"}!</p>
</main>
arafatamim commented 3 years ago

I wonder how hard it would be to add official ReScript integration in the toolchain.