Skip to content

Compile with TypeScript #36

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

alfonsogarciacaro
Copy link

Hi @tpetricek! Not sure how to go with this PR. I am using your wonderful library to test TypeScript compilation to provide a typed API, but there are also other changes so maybe you don't want to merge everything at once.

  • Clean up F# code: use string interpolation and remove most of unboxing.
  • Use React instead of virtual-dom. This should increase user base, but for now I've removed the standalone version and the embedded Elmish. We could also include an option to emit the html string without the React dependency (e.g. to run it in a dotnet server).
  • Use Vite instead of Webpack for the app sample (I haven't touched the release script yet).
  • Upgrade to Fable 4 and compile to TypeScript

The most important point is the last one. This makes it possible to use your excellent and documented API in a type-safe manner from TypeScript. We can also use TS erased unions (Coord becomes number | [any, number]) and even the object to pass the events is typed.

image

@alfonsogarciacaro
Copy link
Author

I've also expanded the API so most of the methods can be accessed directly from Shape objects. This allows for fluent APIs that may be nicer to use:

return c.overlay([
  c.shape(
    gbpusd.slice(0, 17).map((v, i) => [i, v] as [number, number])
      .concat([[16, lo], [0, lo]]))
    .fillColor("#1F77B460"),

  c.shape(
    gbpusd.slice(16).map((v, i) => [i + 16, v] as [number, number])
      .concat([[gbpusd.length - 1, lo], [16, lo]]))
    .fillColor("#D6272860"),

  c.line(gbpusd.map((v, i) => [i, v]))
    .strokeColor("#202020")
])
  .axes({ left: true, right: true, bottom: true })
  .svg(500, 200);

@tpetricek
Copy link
Contributor

Hello!

This looks like a fantastic list of improvements for the library - I'd be happy to merge a PR that implements everything you listed above. I think having an option to emit HTML without React would be nice - I expect supporting some way of using the library on the server without the browser may be useful for someone.

I'll have more time to look into this in the next week or so - but wanted just to quickly say thanks for looking into this!

@alfonsogarciacaro
Copy link
Author

Thanks @tpetricek! I've updated the build script which will now put the JS files ready for distribution together with the declaration files in dist folder. Another improvement is that fable-library files has been published as a separate npm package so it can be set as a dependency of compostjs instead of having to embed all the files.

I've also added code to support dotnet compilation. If you type dotnet run --project src/dotnet it will print a sample SVG file, though it still needs a nicer API for F# :)

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

Successfully merging this pull request may close these issues.

2 participants