小编Cha*_*man的帖子

OOP - 如何在ReasonML中创建一个类

我知道在OCaml中,可以创建一个类来执行以下操作:

class stack_of_ints =
  object (self)
    val mutable the_list = ( [] : int list ) (* instance variable *)
    method push x =                        (* push method *)
      the_list <- x :: the_list
  end;;
Run Code Online (Sandbox Code Playgroud)

但是,我一直在努力寻找有关如何在Reason中执行此操作的文档.谢谢.

oop ocaml reason

9
推荐指数
1
解决办法
1165
查看次数

如何在BuckleScript bsconfig.json中定位子目录

我有以下文件夹结构

--| button
--|--| button.re
main.re
Run Code Online (Sandbox Code Playgroud)

在我的bsconfig.json,使用此处的快速入门指南.我在配置中有以下键/值:

"sources": [
  "src/"
]
Run Code Online (Sandbox Code Playgroud)

它只针对main.re文件.我尝试了一些传统的配置选项*.re,但无济于事.如果我想定位所有子目录,我该怎么做?谢谢.

reason bucklescript

7
推荐指数
2
解决办法
644
查看次数

使用Javascript对HTML5 Canvas中的RGB随机化,并为每个fillRect使用新值

我当前用于随机化rgb的代码已放入变量cr(颜色随机)

var cr = 'rgb('+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+')';
Run Code Online (Sandbox Code Playgroud)

我继续将变量放入fillstyle canvas元素中以放置颜色:

ctx.fillStyle = cr;
Run Code Online (Sandbox Code Playgroud)

进行中的fillRect如预期的那样随机化。当前代码:

var c = document.getElementById('canvas');
var ctx = c.getContext('2d');

var cr = 'rgb('+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+')';

  ctx.fillStyle = cr;
  ctx.fillRect(0, 210 , 100 ,290);
Run Code Online (Sandbox Code Playgroud)

当我尝试将其放入新的fillRect()时出现问题。例如:

var c = document.getElementById('canvas');
var ctx = c.getContext('2d');

var cr = 'rgb('+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+','+
      Math.floor(Math.random()*256)+')';

  ctx.fillStyle = cr;
  ctx.fillRect(0, 210 , 100 ,290);

  ctx.fillStyle = cr;
  ctx.fillRect(100, 210, 100, 290);
Run Code Online (Sandbox Code Playgroud)

新的ctx.fillStyle使用相同的随机颜色。我希望新的fillRect具有新的随机颜色(做一个很酷的天际线效果,也许还有另外20个或更多)。也许,我需要将循环放入数组中,将其随机化,并用于每个新的fillRect。任何解决方案将不胜感激:)

javascript random canvas html5-canvas

4
推荐指数
1
解决办法
7828
查看次数

分派动作触发,但 redux 存储未更新

目前在我的 React-Redux 应用程序中,我想使用 React 将显示状态设置为 false 或 true。当设置为 true 时,应用程序将初始化。(有多个组件,因此使用 react/redux 执行此操作是有意义的。)

但是,我当前的问题是,即使我使用 react redux 连接了我的应用程序,并且使用提供程序连接了我的商店,也会调用调度操作,而不更新商店(我正在使用 redux 开发工具进行仔细检查,以及在应用测试)。

我附上了我认为相关的代码,但是,整个代码库可作为专门针对此问题制作的分支here。我在这方面花了很长时间(实际上是轻描淡写),任何贡献都将不胜感激。

组件相关代码

hideBlock(){
const{dispatch} = this.props;
dispatch(hideBlock);
}

return(
  <div className = "works">
    <button id="show-block" type="button" className="show-hide-button" onClick={this.showBlock}>show</button>
    <button id="hide-block" type="button" className="show-hide-button" onClick={this.hideBlock}>Hide</button>
  </div>
);

function mapStateToProps(state) {
  const {environment} = state;
  return{
    environment
  }
}

export default connect(mapStateToProps)(Form);
Run Code Online (Sandbox Code Playgroud)

行动

import * as types from "../constants/ActionTypes";

export function showBlock(show) {
   return {
      type: types.SHOW,
      show: true
   };
}

export function …
Run Code Online (Sandbox Code Playgroud)

javascript reducers reactjs redux react-redux

3
推荐指数
1
解决办法
4146
查看次数

在OCaml中箭头" - >"的目的是什么

我最近一直在学习OCaml,到目前为止,编译器似乎使用了一个箭头来表示下一个类型是什么.例如,int -> int -> <fun>一个返回整数的整数,它返回一个函数.

但是,我想知道我是否可以在OCaml代码中原生使用它.此外,如果有人碰巧知道它的适当名称.谢谢.

ocaml

3
推荐指数
1
解决办法
1967
查看次数

为什么css元素>元素在以下实例中作为意外工作

所以我决定将三个div用于实验目的

<div> 
  <div> 
    <div> 
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

然后我继续前进并决定使用css如下定位内部div:

div {
  border: 1px solid black;
  padding: 40px;
  background: white;
}

div > div:hover { 
  box-shadow: 0 0 0 40px white;
}

div > div:hover{
  box-shadow: 0 0 0 80px white;
}
Run Code Online (Sandbox Code Playgroud)

我期望发生的是,要么打破页面,要么一次选择所有的div.然而,奇怪的是,它一个接一个地瞄准div,如果你愿意的话就会传播.

div {
  border: 1px solid black;
  padding: 40px;
  background: white;
}

div > div:hover { 
    box-shadow: 0 0 0 40px white;
}

div > div:hover{
    box-shadow: 0 0 0 80px white;
}
Run Code Online (Sandbox Code Playgroud)
<div>
    <div> 
        <div>
        </div>
    </div>
</div>     
Run Code Online (Sandbox Code Playgroud)

html css css-selectors

2
推荐指数
1
解决办法
52
查看次数

在 Typescript 中使用导入时如何处理 Tslint 错误超过 100 个字符

我正在导入一个文件:

import { BodyTableHeaderExampleModule } from '../../components/example-table/example-table-header/example-table-header-xxxx/example-table-header-xxxxx.module';
Run Code Online (Sandbox Code Playgroud)

但是,tslint 抱怨该行超过 100 个字符。当我尝试通过执行以下操作来最小化行长时:

import { BodyTableHeaderExampleModule } from '../../components/example-table/example-table-header/' +
'example-table-header-xxxx/example-table-header-xxxxx.module';
Run Code Online (Sandbox Code Playgroud)

我收到以下 tslint 错误:

ERROR: 11:92  semicolon             Missing semicolon
ERROR: 11:93  no-unused-expression  unused expression, expected an assignment or function call
Run Code Online (Sandbox Code Playgroud)

任何关于在Exceeds maximum line length of 100使用长 Typescript 文件导入时解决问题的建议都将不胜感激。谢谢你。

typescript tslint

2
推荐指数
1
解决办法
4348
查看次数

如何在自定义 Angular Schematics 中定位文件路径?

我目前正在尝试创建自己的自定义 Angular Schematics。我有以下内容:

import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';


// You don't have to export the function as default. You can also have more than one rule factory
// per file.
export function pxSchematics(options: any): Rule {
  return (tree: Tree, _context: SchematicContext) => {
    tree.create(options.name || 'hello', 'world');
    return tree;
  };
}
Run Code Online (Sandbox Code Playgroud)

它只是创建一个带有“hello world”的文件。我将如何更改树的文件路径,以便它在自定义目录中输出文件?谢谢。

angular-cli angular angular-schematics

2
推荐指数
1
解决办法
2189
查看次数