Giter Club home page Giter Club logo

Comments (7)

chenglou avatar chenglou commented on May 23, 2024 1

Ehhh, cc @bobzhang @rickyvetter @IwanKaramazow. It'd be great to have a good answer for decoding variants and such.

from bs-webapi-incubator.

chenglou avatar chenglou commented on May 23, 2024 1

option was just an example. I'm talking about not throwing, like here

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 23, 2024

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.

chenglou avatar chenglou commented on May 23, 2024

^ 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.

glennsl avatar glennsl commented on May 23, 2024

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.

bobzhang avatar bobzhang commented on May 23, 2024

I would just like something simpler

external fetchAsync : (_ [@bs.as "async"])  -> string -> t 

This works better with code completion

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.