reason

How to extend JS class in ReasonML

佐手、 提交于 2019-12-23 12:28:52
问题 For example, I have an es6 -like class: class Foo {...} And I want to extend it: class Bar extends Foo {...} In reason-react documentation I found examples, but I'm not sure that it's appropriate for me: let component = ReasonReact.reducerComponent "TodoAppRe"; let make _children => { ...component, initialState: fun () => {count: 0}, <...> But when i try to write code in this style, i get an error: let myclass unit => { ...mysuperclass, hello: fun () => { Js.log "FooBar"; } }; Error: Unbound

Compile error using fast pipe operator after pipe last in ReasonML

折月煮酒 提交于 2019-12-13 13:41:08
问题 The way that the "fast pipe" operator is compared to the "pipe last" in many places implies that they are drop-in replacements for each other. Want to send a value in as the last parameter to a function? Use pipe last ( |> ). Want to send it as the first parameter? Use fast pipe (once upon a time |. , now deprecated in favour of -> ). So you'd be forgiven for thinking, as I did until earlier today, that the following code would get you the first match out of the regular expression match: Js

What are the Implications of Different ReasonML External Declarations?

亡梦爱人 提交于 2019-12-11 15:49:47
问题 In the examples below, both external declarations achieve the same functionality with slightly different ReasonML function structures. Does external declaration style impact anything (e.g. performance) beyond ReasonML function structure? Also, does ReasonML have a "suggested" external declaration "style"? Type Declarations type dom; type element; External Declaration Style 1 [@bs.val] external dom: dom = "document"; [@bs.send.pipe : dom] external get_by_id: string => element = "getElementById

Passing React Component to Another Component?

南楼画角 提交于 2019-12-10 11:37:01
问题 I'm trying to define a ProductRow and ProductCategoryRow from Thinking in React. productRow.re let component = ReasonReact.statelessComponent("ProductRow"); let make = (~name, ~price, _children) => { ...component, render: (_self) => { <tr> <td>{ReasonReact.stringToElement(name)}</td> <td>{ReasonReact.stringToElement(price)}</td> </tr> } }; productCategoryRow.re let component = ReasonReact.statelessComponent("ProductCategoryRow"); let make = (~title: string, ~productRows, _children) => { ..

What's the difference between -> and |> in reasonml?

蓝咒 提交于 2019-12-09 08:40:35
问题 A period of intense googling provided me with some examples where people use both types of operators in one code, but generally they look just like two ways of doing one thing, they even have the same name 回答1: tl;dr: The defining difference is that -> pipes to the first argument while |> pipes to the last. That is: x -> f(y, z) <=> f(x, y, z) x |> f(y, z) <=> f(y, z, x) Unfortunately there are some subtleties and implications that makes this a bit more complicated and confusing in practice.

Pattern matching on a GADT fails

。_饼干妹妹 提交于 2019-12-08 03:43:45
问题 I was playing around a bit more with ReasonML and found pattern matching on type t from the following example to not be working with the error Error: This pattern matches values of type t(float) but a pattern was expected which matches values of type t(int) Type float is not compatible with type int type t('a) = | One: t(int) | Two: t(float); let x = fun | One => None | Two => None; Now on some level this makes sense to me if this was about the return type of a function. I found an answer (I

How to bind to and use a higher-order component in ReasonReact

廉价感情. 提交于 2019-12-04 09:44:00
Let's say I have a higher-order component, something like the following trivial definition, exported from the JavaScript module ./hoc.js : export const withStrong = Component => props => <strong> <Component ...props/> </strong> Assuming I have some component called HelloMessage , what is the equivalent of this piece of JavaScript: import { withStrong } from './hoc.js'; const HelloMessage = ... const StrongMessage = withStrong(HelloMessage); ReactDOM.render( <StrongMessage name="Joe" />, document.getElementById('react-app') ); TL;DR: This should be the exact equivalent of the requested

What's the difference between -> and |> in reasonml?

坚强是说给别人听的谎言 提交于 2019-12-04 02:55:50
A period of intense googling provided me with some examples where people use both types of operators in one code, but generally they look just like two ways of doing one thing, they even have the same name tl;dr: The defining difference is that -> pipes to the first argument while |> pipes to the last. That is: x -> f(y, z) <=> f(x, y, z) x |> f(y, z) <=> f(y, z, x) Unfortunately there are some subtleties and implications that makes this a bit more complicated and confusing in practice. Please bear with me as I try to explain the history behind it. Before the age of pipe Before there were any

Are there any reasons not to use “this” (“Self”, “Me”, …)?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I read this answer and its comments and I'm curious: Are there any reasons for not using this / Self / Me ? BTW: I'm sorry if this has been asked before, it seems that it is impossible to search for the word this on SO. 回答1: Warning: Purely subjective answer below. I think the best "reason" for not using this/self/me is brevity. If it's already a member variable/function then why redundantly add the prefix? Personally I avoid the use of this/self/me unless it's necessary to disambiguate a particular expression for the compiler. Many people

RESTful Alternatives to DELETE Request Body

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: While the HTTP 1.1 spec seems to allow message bodies on DELETE requests, it seems to indicate that servers should ignore it since there are no defined semantics for it. 4.3 Message Body A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request. I've already reviewed several related discussions on this topic on SO and beyond, such as: Is an entity body allowed for an HTTP DELETE request?