package server-reason-react
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=3972f64a3ec22b120b40137f74e7862629b2164e5bbf8b85489d4c7b8bc13288
sha512=24a52537c091c4b278ea5e468aa6786378f8b559ed2128e824b6f84f26c283856a30e7ef01aab6101087bd53b9bdc2ecd8152c00db10bccff67221b9c67318a0
doc/externals-melange-attributes.html
Externals and melange attributes
melange.ppx is designed to preprocess Melange programs (simplifying code generation for common use cases like generating bindings or code from types). It's not compatible with native, but if you want to share a module with melange.ppx we provide a drop-in replacement called: server-reason-react.melange_ppx.
Most of the features are shimmed to not work on the server and the compiler will warn to wrap it in browser_only expressions.
server-reason-react.melange_ppx supports
All mel. attributes
mel.* attributes are stripped out of the native build, and transformed into raising functions to raise at server runtime.
Enables pipe_first ->
Pipe first is the operator to apply a function to a value where data is passed as the first argument. -> is a convenient operator that allows you to "flip" your code inside-out.
It's not supported in native OCaml, but server-reason-react.melange_ppx enables it and works as expected.
Supports RegExp [%re "/regex/"]
Transforms [%re ...] into Js.Re.t from server-reason-react.js and it uses a C implementation of the regex engine from QuickJS from quickjs.ml. (Experimental)
Debugger %debugger
It removes the debugger in native. It's a noop on the server context, and it's pretty uncommon it's usage.
Supports Js.t (object access ## and mel.obj)
let john = {"name": "john", "age": 99};
/* The type of john is `{ . "age": int, "name": string }` which represents a
JavaScript Object. */
let name = john##name;https://melange.re/v3.0.0/communicate-with-javascript.html#using-js-t-objects
Object creation and object field access is designed to interact with JavaScript Objects, in native we reperesent those as OCaml Objects (which are very different) and server-reason-react-ppx.melange_ppx proviedes the implementation to make it work. (Experimental)
Supports [@@deriving jsConverter]
The jsConverter deriver generates conversion functions between OCaml variants and JavaScript-friendly representations (integers for regular variants, strings for polymorphic variants).
Regular variants:
type action = Click | Submit | Cancel [@@deriving jsConverter]
(* Generates:
val actionToJs : action -> int
val actionFromJs : int -> action option *)Polymorphic variants:
type state = [`Idle | `Loading | `Error] [@@deriving jsConverter]
(* Generates:
val stateToJs : state -> string
val stateFromJs : string -> state option *)With \@mel.as to customize values:
type action = Click | Submit [@mel.as 3] | Cancel [@@deriving jsConverter]
(* Click = 0, Submit = 3, Cancel = 4 *)With { newType } for abstract types:
type action = Click | Submit [@@deriving jsConverter { newType }]
(* Generates an abstract type [abs_action] and:
val actionToJs : action -> abs_action
val actionFromJs : abs_action -> action *)Note: Only variants without payloads are supported. Variants with payloads like Submit of int will produce a compile-time error.
Usage
To use server-reason-react.melange_ppx you need to add it to your dune's pps field:
(preprocess (pps server-reason-react.melange_ppx))