问题标签 [bucklescript]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
373 浏览

node.js - 在 Node.js 中获取生成子进程的结果

如何执行子进程并获取结果退出代码和输出(stdout、stderr)?

就像是

不幸的是,这会导致编译错误:

0 投票
1 回答
209 浏览

asynchronous - 使用带有 setTimeout 的 Promise

我是 Reason 的新手,目前正在尝试将个人项目从 js 转换为 Reason。到目前为止,除了异步的东西之外,它一直很容易。我无法延迟递归地调用我的函数。我有一个getPrice返回 int 承诺的函数

我想做另一个功能checkPrice,除非满足条件,否则它会无休止地通过给定的用户价格检查当前价格。

但我得到类型不匹配说setTimeout应该是单元类型

0 投票
2 回答
592 浏览

ffi - 如何使用reason-react定义一个在函数签名中接受多种类型的绑定?

在定义一个原因反应绑定时,我想知道如何确定一个接受多种类型的绑定。例如,我有一个应该接受的参数~valuestringnumber或。目前我正在使用,但我认为这不是最干净的方法,因为我更愿意明确定义类型。如何才能做到这一点?我看过但我不确定如何将外部语法组合到函数签名中。array(string)array(number)option('a)bs.unwrap

作为一个附带问题,由于未定义数字类型,我的绑定是否也必须将浮点数和整数映射为数字?

0 投票
2 回答
248 浏览

ocaml - Graphql 数组对 ReasonReact 的响应

试图以合理的方式处理数据。我有这个 graphql 查询返回数据并记录它。问题是如何访问以下组件中的数据。

这是查询响应: 在此处输入图像描述

来自 JS 我一直想用一些类似 response.data 的方式记录 allEpisodes ......这显然在这里不起作用

组件的要点:剧集组件home.re 组件

如果我取消注释并运行,它会产生以下错误:

```

```

我不明白在返回数组时如何处理响应对象。谢谢你。

根据@glennsl 的建议更新:

这会产生以下错误:

在此处输入图像描述

我正在考虑它的到来,因为类型没有被传递给 episode.re

我应该在某处传递列表(剧集)吗?

更新 2:感谢@glennsl,这段代码可以在 JSX 上运行

0 投票
0 回答
316 浏览

visual-studio-code - VSCode 上的 ReasonML - *.ml 库文件中的“转到定义”不起作用

我正在 VSCode 上试用 ReasonML。但是“转到定义”功能有点问题。

从 SomeFile.re 我可以右键单击标准库函数(在这种情况下)上的“转到定义” Format.printf(...),它会按照我的预期跳转到定义(在这种情况下./node_modules/bs-platform/lib/ocaml/format.ml

但是在 format.ml 中,“转到定义”对我不起作用。所以我无法进一步探索底层功能。在这种情况下,在 format.ml 中,printf调用fprintf. 当我尝试“转到定义 on 时fprintf,它显示“没有找到 fprintf 的定义”

有没有人可以让我完成这项工作?

0 投票
1 回答
588 浏览

ocaml - Understanding ReasonML/Bucklescript Externals

Just trying to generally understand what is going on here. Does this make sense to explain ReasonApolloTypes.gql as an example of using Externals.

This is the bs.module code

[@bs.module] external gql : ReasonApolloTypes.gql = "graphql-tag";

bs.module tells buckelscript that we want to use a FFI.

external tells bs the name of the FII we want to use and we set its value to ReasonApolloTypes.gql which is a globally available Reason module that we installed when we added reason-apollo in bsconfig's bs-dependencies array, and to package.json. If you open node_modules/reason-apollo/src you will see defined Reason modules that are globally available like any other.

ReasonApolloTypes.re is listed there and contains a defined type named gql. So ReasonApolloType.gql is the named module we are accessing with external gql. In ReasonApolloType.gql there is a defined type, type gql = [@bs] (string => queryString);. This tell bucklescript to assign a type of string to the gql type and the assign the value to querystring, so type querystring is of type string. Then set ReasonApolloTypes.gql to use the "graphql-tag" node library to resolve ReasonApolloTypes.gql.

Am I missing an concepts here? Is this expressed correctly? The Bucklescript/Reason docs are above my head for Externals at this point. Thanks.

0 投票
1 回答
108 浏览

reason - 将 querySelectorAll 的结果传递给 EventTarget.addEventListener

我想做类似的事情:

但我得到一个错误addOrRemoveListeners(addListener);

我应该如何从 转换Dom.eventTargetDom.node


编辑:我最终得到了这个:

0 投票
1 回答
353 浏览

promise - 为什么需要调用resolve()?

我正在为 Javascript 开发人员查看 A First Reason React 应用程序中的 Reason 示例

我看到他Js.Promise.resolve在使用时正在打电话bs-fetch

我也在 BuckleScript 代码中看到了类似的代码。例如在Bucklescript Cookbook中:

在 JS 中,我们通常resolve在创建新的 Promise 时调用,而不是在使用返回 Promise 的函数时调用。那么为什么我们需要resolve在上述情况下调用呢?

0 投票
2 回答
126 浏览

ocaml - BuckleScript 项目的文档生成

有没有办法为 BuckleScript 或 Reason 生成代码文档?我试过使用ocamldoc,但我不知道如何自动包含节点包依赖项。

0 投票
2 回答
609 浏览

ffi - 在 Reasonml 中使用 React ref 时如何定义组件/绑定?

我在我的应用程序中集成 react-system-notification 模块时遇到问题,阅读了有关Reason React Ref的文档我不确定为什么引用没有传递到堆栈中;一个提示将不胜感激。

我不断收到以下错误,我过去曾在 React 中使用过这个组件,但在 ReasonML/React 中使用时似乎存在一些问题。我怀疑传递了一个空引用,这会破坏组件。

元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

检查Notifications.

捆绑:

零件