问题标签 [halogen]

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 投票
0 回答
239 浏览

unit-testing - 如何在 purescript-halogen 中对组件的查询评估进行单元测试?

purescript-halogen 组件具有eval定义它如何评估查询的函数。我想编写测试来涵盖组件的行为;我该怎么做呢?

例如,如果我的组件GetValue在其查询代数中,我想编写一个测试来创建具有初始状态的组件,评估GetValue查询,并断言接收到的值与初始状态中提供的值匹配。如果我的组件也有 a SetValue,我可能想断言在 aGetValue之后评估 a 会SetValue返回我期望的结果。

我找不到任何此类测试的示例(我经常参考 Slamdata 的代码,但我看到的唯一测试是 Selenium 测试)。

我觉得解决方案必须在Halogen.Component中,其中的功能类似于queryComponentinitializeComponent驻留;我查看了Halogen.Driver源以尝试了解如何使用它们,但我一直无法弄清楚。

有人可以向我指出一个测试卤素组件的示例,或者解释如何创建一个组件,让它评估一个查询,并观察结果吗?

0 投票
1 回答
363 浏览

random - Purescript 卤素,副作用(随机数)

在 PureScript Halogen 项目中,我想将状态设置为随机数,但如何提取该值?正常的

当它在 eval 函数中时不编译。

0 投票
1 回答
458 浏览

purescript - purescript-halogen:通过有效计算修改状态

我想用一个依赖于旧状态的函数来修改我的状态,但也引入了一些随机性。我的功能f如下所示:

Eff我想我的状态应该是纯的,除了 using 之外,我不知道如何摆脱unsafePerformEff,所以我这样做了:

这行得通,但必须有另一种更安全的方法。我已经将随机效果添加到我的主要功能中:

但是应该怎么eval看?也许modify在这里不起作用,还有另一种更新状态的方法?

Purescript Halogen,副作用(随机数)对我不起作用,因为f取决于旧状态。

0 投票
1 回答
160 浏览

purescript - 是否可以在卤素 ComponentHTML 函数中在 Eff 中运行某些东西?

我想在我的 Halogen UI 中使用一些与 moment.js 的绑定来渲染时间跨度,它们的类型类似于

如果我想像这样在我的 UI 中使用此功能:

但这是在,Eff所以我不能。

我能做的是用这个函数调用时刻:

js:

ps:

我的问题(或几个)然后:

调用 javascript 而不说它是一个Eff. 如果不是,什么时候认为可以,什么时候不可以?无论哪种方式,我都可以将这些功能视为副作用。

如果我不能改变我打电话给时刻的方式,或者这确实是一个坏主意,有没有办法做到这一点HTML

0 投票
1 回答
488 浏览

purescript - Purescript 卤素处理 SVG

有没有一种在 purescript 卤素中使用 svg 元素的简便方法?我试图在 中绘制一个动态的、可点击的图形<svg>,但我能找到的唯一参考svg是 Halogen.Themes.Bootstrap,它似乎更关心 css 主题。

0 投票
1 回答
177 浏览

purescript - 是否可以在 eval 期间用卤素渲染组件?

在我的卤素项目中有这个 eval 分支:

如果停止执行 AJAX,则 toAff 位可能需要一段时间才能返回。在我的渲染功能中,我有

我天真地期望在我的 aff 操作返回之前看到一个加载微调器,但看起来 eval 在呈现 html 之前一直运行。这个对吗?

编辑

原来这是用户错误 - 我以错误的顺序调用我的查询。未来的混乱:设置状态确实会更新 ui :-)

0 投票
1 回答
832 浏览

purescript - Selecting Elements By Id in Purescript

Is there a function in purescript-halogen to select an element by it's id, or do I need to custom role it (which would seem very strange to me).

I'm reading through the documentation on Pursuit, and I see a selectElement function in Util, but nowhere do I see something that lets me select by id.

I can use getElementById :: ElementId -> NonElementParentNode -> Eff () (Nullable Element) to get an Element, but I do not know how to turn this Element into an HTMLElement.

The type search feature in Pursuit is also lacking, so I apologize for this naive question.

0 投票
1 回答
259 浏览

purescript - Purescript:仅卤素 HTML DSL 呈现“id”标签

我正在使用purescript-halogen v0.12.0,但我无法弄清楚为什么只有id标签在渲染。

即使使用据称支持良好的元素也会发生这种情况,例如div.

例子:

render = div [ id_ "some-id", name "some-name ] []

将创建一个 div,但仅具有一个id属性。这发生在 和 中的元素Halogen.HTMLHalogen.HTML.Indexed

任何正确方向的帮助将不胜感激。

==================================================== ===========

重现以下问题。

=============

0 投票
1 回答
530 浏览

purescript - Purescript Halogen: Defining Custom HTML Elements

I'm having difficulties similar to this unanswered question: Purescript: Halogen HTML DSL only Renders "id" tags

I'm trying to define a new HTML element. In particular, I would like to display an svg elem and image element with some new tags, like x_, and y_.

I'm defining the element like so:

And then attributes I would like:

When I create the element, the program compiles, however only the <image></image> tags are rendered, without the specified attributes. It seems like the way halogen interfaces with virtual-dom does not allow me to do this, however, I'm not sure why.

In general, why can't I just add any attributes to a div, svg, or image element? I'm not using Halogen.HTML.Indexed for any of these elements. Is that the problem?? Is the type checker just missing the fact that these combinations are not allowed because I haven't specified them??

In general, I would like to do something even like:

and then call

image [ customProperty "myProperty" "myPropertyValue" ] []

and have that attribute rendered.

========================

Edit: Reading through the source code, it seems that namespace has something to do with it, however, I'm not sure how to find the namespace of an already constructed element.

0 投票
1 回答
817 浏览

purescript - 如何将 purescript-halogen 组件渲染到标签中

如何将特定的 purescript-halogen 组件渲染到 <head> 标记中?

以下为 Halogen 1.0.0 编写的示例将样式表和段落呈现到 HTML 正文中:

DOM 生成如下:

此示例有效,但根据规范,样式元素仅允许“在预期元数据内容的位置”,即 <head> 元素。所以我想在那里渲染样式表。我该如何做到这一点?