homebay / re-mapbox Goto Github PK
View Code? Open in Web Editor NEWMapbox GL bindings for ReasonML
Mapbox GL bindings for ReasonML
https://docs.mapbox.com/mapbox-gl-js/style-spec/#expression-reference
Using this API via an array of JSON is pretty error-prone. I started adding an ADT for Expressions, but it's very incomplete (basically "get", raw expression array and raw value). This could be so much better:
bool
Layer
's filter
field should be of type Expression.t(bool)
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:
src/
make two directories
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 placeObj.magic
to cast types to their Mapbox supertypes= "%identity"
to constrain strings, emulating enumsThe 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).
There are a few places the Mapbox API specifies a finite number of allowable strings to be used as options. I think we've mostly taken the approach of defining an abstract type and using "%identity"
to cast valid strings as that type. It has worked, but this article has a couple great tips that can improve things:
module type
with a module
, we can use type t = string
but hide the details from the outside world, so it still works the same, but there's no need for "%identity"
hacks and separating interface files[@bs.inline]
annotations, we can avoid defining string variants that end up unusedWe probably can't immediately take advantage of Bucklescript v7's records-as-js-objects since so many of the Mapbox objects expect fields to be missing (instead of undefined
values), but we could consider switching from [@bs.deriving abstract]
to a bs.obj implementation.
This has the advantage of being slightly more straightforward to read than the magical derived functions that come from @bs.deriving abstract
, plus for simply constructing objects, we don't actually need any of the generated getter functions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.