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

FFI Structure #3

Open
1 of 4 tasks
mlms13 opened this issue Mar 21, 2019 · 0 comments
Open
1 of 4 tasks

FFI Structure #3

mlms13 opened this issue Mar 21, 2019 · 0 comments

Comments

@mlms13
Copy link
Contributor

mlms13 commented Mar 21, 2019

Currently, the Mapbox FFI is a mix of zero-runtime-cost bindings to raw Mapbox types/functions and a layer of Reason types with runtime conversion to Mapbox types. I probably won't knock all of this out at once, but here's a plan to clean things up:

  • Move GeoJSON out of this repo
  • Inside src/ make two directories
    • FFI (filled with low-level abstract types)
    • Re ( filled with Reason wrappers and runtime conversions)

The low-level bindings in src/FFI/ should provide as much safety as possible while bringing virtually no runtime cost. We should generate *.rei interfaces here and aggressively hide anything unsafe.

Examples of strategies in FFI:

  • [@bs.deriving abstract] all over the place
  • Obj.magic to cast types to their Mapbox supertypes
  • = "%identity" to constrain strings, emulating enums

The src/Re/ directory should have 1:1 mappings to files in the FFI directory (mostly, probably?), but all objects should be Reason records, all subtyping should be represented as variants, and all functions that call into the FFI should do runtime conversion as needed.

This approach should make it clear when you're choosing between clean JS code vs real Reason data that can be pattern-matched and updated using normal patterns (but with more overhead in the compiled JS).

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

1 participant