Comments (7)
Ehhh, cc @bobzhang @rickyvetter @IwanKaramazow. It'd be great to have a good answer for decoding variants and such.
from bs-webapi-incubator.
option was just an example. I'm talking about not throwing, like here
from bs-webapi-incubator.
More context:
I've manually written encode and decode functions for stringly-typed enums, of which there are a lot. Sometimes I raise an exception when the unexpected happens (https://github.com/BuckleTypes/reason-js/blob/master/src/fetch/fetchRe.re#L53-L83), other times I add an extra Unknown
variant and wait for it to blow up somewhere else (https://github.com/BuckleTypes/reason-js/blob/master/src/dom/htmlElementRe.re#L7-L21)
from bs-webapi-incubator.
^ might be better to model this as an option or something, if it's not inconvenient. Likewise, I hope bs' encode/decode doesn't throw... please
from bs-webapi-incubator.
To me, an option
seems a bit less convenient than just having an Unknown
variant in many cases. It's also not always clear what None
would mean, since None
or Default
(encoded as ""
) are sometimes also actual values. So you might get Some None
perhaps.
Then there's a difference between whether the source of the value is from the "system", as e.g. nodeType
would be, or if it's user-specified, via an html attribute perhaps. In the former case, unless the spec changes and someone uses an obsolete version of reason-js, it really ought to be an exceptional occurrence to receive an ill-formed string value. In the latter case, when the user might type in whatever they damn well please, there should perhaps be an Unknown
variant or be wrapped in an option
or something similar.
from bs-webapi-incubator.
I would just like something simpler
external fetchAsync : (_ [@bs.as "async"]) -> string -> t
This works better with code completion
from bs-webapi-incubator.
@bobzhang That only works for a small subset of use cases though.
Consider nodeType
, which is used on Dom.node
to express whether it is actually a Dom.element
or Dom.document
etc. Then it needs to be a variant that can be pattern matched in order to do the right thing. (Or some other way of doing the same thing).
Or consider any of the variants in fetch
that's used with several different data structures. Using inline polymorphic variant types would mean a lot of duplication, messy ffi signatures and a much greater risk of a bug sneaking through when the variants need to be altered (These are web specs, they change all the time).
from bs-webapi-incubator.
Related Issues (20)
- Function for converting Node to real type HOT 1
- Project name HOT 2
- Nodelist forEach HOT 2
- Dom.Image does not exist (the current Dom.Image should be Dom.ImageData)?
- adding bindings to HtmlVideoElement HOT 3
- Binding for XHR HOT 1
- Classify for Dom.node HOT 4
- Adding replaceChild
- Canvas2d.putImageData creates erroneous calls when not using all the optionals. HOT 3
- Could be possible to perform auto-generation from WebIDL? HOT 3
- Bsdoc dependency makes contributing a bit difficult on Linux HOT 2
- Binding for URLSearchParams.entries() is incorrect
- Add bindings for HtmlTemplateElement
- unmet peer dependency warning HOT 1
- Regarding document.documentElement.scrollTop HOT 2
- Add functor to type CustomEvent.detail
- How to use HtmlInputElement (focus, select) ? HOT 5
- How to use addEventListener on window HOT 3
- Add DataTransfer bindings
- unsafeAsHtmlInputElement
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bs-webapi-incubator.