Last active
May 15, 2018 06:56
-
-
Save wegry/f2b96c327291a08edc5120815f29e189 to your computer and use it in GitHub Desktop.
Bucklescript FFI bindings with Reason for prop-types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as PropTypes from "prop-types"; | |
var shape = PropTypes.default.shape(); | |
var arrayOf = PropTypes.default.arrayOf(); | |
var Internal = /* module */[ | |
/* shape */shape, | |
/* arrayOf */arrayOf | |
]; | |
function add(prim, prim$1) { | |
prim.propTypes = prim$1; | |
return /* () */0; | |
} | |
var string = PropTypes.default.string; | |
var requiredString = string.isRequired; | |
var func = PropTypes.default.func; | |
var requiredFunc = func.isRequired; | |
var bool = PropTypes.default.bool; | |
var requiredBool = bool.isRequired; | |
var array = PropTypes.default.array; | |
var requiredArray = array.isRequired; | |
function requiredArrayOf(x) { | |
return arrayOf(x).isRequired; | |
} | |
function requiredShape(x) { | |
return shape(x).isRequired; | |
} | |
export { | |
Internal , | |
add , | |
string , | |
requiredString , | |
func , | |
requiredFunc , | |
bool , | |
requiredBool , | |
array , | |
requiredArray , | |
arrayOf , | |
requiredArrayOf , | |
shape , | |
requiredShape , | |
} | |
/* shape Not a pure module */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Internal = { | |
[@bs.deriving abstract] | |
/* This is a little dishonest, but the resulting code generated works out like this. */ | |
type isRequired = { | |
isRequired, | |
}; | |
[@bs.deriving abstract] | |
type proptypes = { | |
[@bs.as "string"] | |
string_: isRequired, | |
number: isRequired, | |
array: isRequired, | |
func: isRequired, | |
[@bs.as "bool"] | |
bool_: isRequired, | |
}; | |
[@bs.module "prop-types"] external propTypes : proptypes = "default"; | |
[@bs.send] external arrayOf : proptypes => (. isRequired) => isRequired = ""; | |
[@bs.send] | |
external shape : proptypes => (. Js.Dict.t(isRequired)) => isRequired = ""; | |
/* Still need to add oneOf and shape at some point... */ | |
let shape = shape(propTypes); | |
let arrayOf = arrayOf(propTypes); | |
}; | |
[@bs.set] | |
external add : (ReasonReact.reactClass, Js.t(_)) => unit = "propTypes"; | |
let add = add; | |
open Internal; | |
let string = propTypes |. string_; | |
let requiredString = string |. isRequired; | |
let func = propTypes |. func; | |
let requiredFunc = func |. isRequired; | |
let bool = propTypes |. bool_; | |
let requiredBool = bool |. isRequired; | |
let array = propTypes |. array; | |
let requiredArray = array |. isRequired; | |
let arrayOf = arrayOf; | |
let requiredArrayOf = x => arrayOf(. x) |. isRequired; | |
let shape = shape; | |
let requiredShape = x => shape(. x) |. isRequired; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment