是否有可能不导出某些不应由包消费者直接使用的内部模块?
这种语法非常有用 - 这是否有理由不起作用?谢谢!
module Foo = {
let bar: string = "bar"
};
let bar = Foo.bar; /* works */
let { bar } = Foo; /* Unbound record field bar */
Run Code Online (Sandbox Code Playgroud)
有没有办法将多个变体组合成一个?像这样的东西:
type pet = Cat | Dog;
type wild_animal = Deer | Lion;
type animal = pet | wild_animal;
Run Code Online (Sandbox Code Playgroud)
这是一个语法错误,但我希望动物成为一个有四个构造函数的变体:Cat | Dog | Deer | Lion.有没有办法做到这一点?
我正在尝试为https://github.com/oblador/react-native-keychain/blob/master/typings/react-native-keychain.d.ts#L76编写绑定
getGenericPassword返回false错误,否则返回object(credentials).我不确定这种联合类型是否可以在合理的情况下表示,但更好的API将是一个选项(选项(凭证))的结果.但是,我怎样才能在绑定文件中转换Promise<boolean | credentials>- > Js.Promise.t(option(credentials)).下面是一个模板.
谢谢你的帮助.
[@bs.deriving abstract]
type credentials = {
service: string,
username: string,
password: string,
};
/* TODO convert the actual return value
Js.Promise.t(option(credentials)) to more reason type
Js.Promise.t(option(credentials)) */
[@bs.module "react-native-keychain"] [@bs.scope "default"]
external getGenericPassword: unit => Js.Promise.t(option(credentials)) = "";
Run Code Online (Sandbox Code Playgroud) 假设我有一个高阶组件,类似于下面的琐碎定义,是从JavaScript模块导出的./hoc.js:
export const withStrong =
Component => props =>
<strong> <Component ...props/> </strong>
Run Code Online (Sandbox Code Playgroud)
假设我有一个名为的组件HelloMessage,那么这段JavaScript是等效的:
import { withStrong } from './hoc.js';
const HelloMessage = ...
const StrongMessage = withStrong(HelloMessage);
ReactDOM.render(
<StrongMessage name="Joe" />,
document.getElementById('react-app')
);
Run Code Online (Sandbox Code Playgroud) interop reason higher-order-components bucklescript reason-react
我想分析一个OCaml/Reason代码库并理解各种函数之间的调用.有没有提供此类功能的工具?
我正在为Javascript开发人员查看 Reason的第一个原因反应应用程序的示例
我看到他Js.Promise.resolve在使用时正在打电话bs-fetch:
RepoData.fetchRepos()
|> Js.Promise.then_(repoData => {
handleReposLoaded(repoData);
Js.Promise.resolve();
})
|> ignore;
Run Code Online (Sandbox Code Playgroud)
我在BuckleScript代码中也看到了类似的代码.例如在Bucklescript Cookbook中:
Js.Promise.(
Fetch.fetch "https://api.github.com/users/reasonml-community/repos"
|> then_ Fetch.Response.text
|> then_ (fun text ->
text
|> names
|> Array.iter Js.log
|> resolve)
|> ignore
Run Code Online (Sandbox Code Playgroud)
在JS中,我们通常resolve在创建新promise时调用,而不是在使用返回promise的函数时调用.那么为什么我们需要打电话给resolve上面的案例呢?
我正在尝试学习 ReasonML,并且我正在做一些公案来帮助我完成这项任务。我尝试编写的公案之一是在将列表转换为数组后询问列表的类型。我知道在某些语言中存在诸如 Haskell ( :t) 之类的运算符,我们可以在其中询问变量的类型。是否有任何相当于:tReasonML 的东西?或者检查是否Array.of_list返回数组是没有意义的,因为编译器确保......
在我的代码中开始出现的很多东西是:
<Parent>
{if (condition) {
<Child />;
} else {
<div />;
}}
<Sibling />
</Parent>;
Run Code Online (Sandbox Code Playgroud)
基本上,我只希望在Child条件为true时渲染,否则不渲染任何东西。
将divelse 置于else条件中感觉不对,因为这会使a div确实不应该存在。如果条件为假,如何有条件地渲染组件而不必渲染不必要的元素?
let numbers = [1, 5, 6, 12, 52, 25];
let state: list((int, bool)) = numbers |> List.map(n => (n, false));
state |> List.map((n, b) => <NumberCard number=n picked=b onClick />);
Run Code Online (Sandbox Code Playgroud)
可能做错了什么,因为类型检查器说:
51 ?
52 ? let elems =
53 ? state |> List.map((n, b) => <NumberCard number=n picked=b onClick />
);
54 ?
55 ? <div className="flex flex-column">
This has type:
list(int) => list(bool => React.element)
But somewhere wanted:
list((int, bool)) => 'a
The incompatible parts:
int
vs
(int, bool)
Run Code Online (Sandbox Code Playgroud) reason ×10
ocaml ×6
bucklescript ×5
reason-react ×3
analysis ×1
call-graph ×1
ffi ×1
interop ×1
module ×1
promise ×1
types ×1
union-types ×1
variant ×1