Giter Club home page Giter Club logo

Comments (10)

chenglou avatar chenglou commented on May 27, 2024 1

Verbose is fine; consumers wouldn't notice the difference. They also don't create additional bindings and get inlined.

from bs-webapi-incubator.

chenglou avatar chenglou commented on May 27, 2024

_MyConstant is kind of an awkward middle between myConstant and _MY_CONSTANT. I prefer myConstant but maybe we got counterexamples.

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 27, 2024

Some more context on different types of constants, how the JS API implements them and how they're currently modeled in reason-js:

  • Enum values:
    • In JS: PROCESSING_INSTRUCTION_NODE
    • Current implementation in Dom: Variant with type constructors in the form of e.g. ProcessingInstruction
    • Current implementation in Gl: let binding in the form of e.g. _LINE_STRIP
  • Bitmask flags:
    • In JS: SHOW_DOCUMENT_TYPE
    • Current implemtnation in Dom: module with let bindings in the form of e.g. WhatToShow._DocumentType
    • Current implementation in Gl: let binding in the form of e.g. _STENCIL_BUFER_BIT

from bs-webapi-incubator.

chenglou avatar chenglou commented on May 27, 2024

let bindings shouldn't be necessary there right? Just externals? I don't know why those are lets.

Since we do use variants too, we can probably be idiomatic here and use lineStrip, documentType and stencilBufferBit? Hopefully this doesn't clash with an actual lineStrip variable?. Otherwise it should probably be _LINE_STRIP, etc.

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 27, 2024

externals would be more verbose, I guess?

It feels a bit inconsistent to me to have bitmask flags in camelCase while enums, being modeled as variants, would have to be PascalCase. But in either case they should probably both be wrapped in type-specific modules, which would make name collisions a non-problem.

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 27, 2024

I think I'm leaning towards the following:

enums:

module NodeType = {
  type t =
  | Element
  | Attribute
  | ...

  let encode : t -> string = ...
  let decode : string -> t = ...
};

bitmask flags:

module WhatToShow = {
  type t;

  external all : t = "NodeFilter.SHOW_ALL" [@@bs.val];
...
  external processingInstruction : t = "NodeFilter.SHOW_PROCESSING_INSTRUCTION" [@@bs.val];
...
};

from bs-webapi-incubator.

chenglou avatar chenglou commented on May 27, 2024

humm that's a bit much. Not sure we should take the occasion to rearrange things like this. I still prefer either myConstant or _MY_CONSTANT

Btw I've also used quite a few [@@bs.val] this way. @bobzhang are things like NodeFilter.SHOW_ALL" [@@bs.val] ok?

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 27, 2024

I'm not sure I understand. Converting the variants to externals would be a much bigger rearrangement, is non-idiomatic and misses out on exhaustiveness-checking. And not namespacing with a module will require namespacing in the names themselves (The variants are already overlapping, but they can be, because they're variants).

The bitmask flags is already a module, in part because it provides a function to safely compose the flags. This should probably be functionality provided by some standard library or other, but there's of course no consensus on that either yet (I have my own implementation in rebase though).

from bs-webapi-incubator.

bobzhang avatar bobzhang commented on May 27, 2024

it depends on how those enum variant will be used, will you do OPEN | WRITE or not?

from bs-webapi-incubator.

glennsl avatar glennsl commented on May 27, 2024

For the WhatToShow bitmask flags type I have a (poorly named) many function that will lor flags together in a type safe manner. I'd like to keep the type abstract.

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.