小编tom*_*ole的帖子

如何将 createSelector 与参数和 Typescript 一起使用?

我用来redux-toolkit生成选择器。我想在我自己的带有参数的自定义选择器中使用它们reselect。但我不知道如何输入我的选择器的返回类型?

const selectOrganizationName = (id: string): ??? =>
  createSelector(
    [(state: RootState) => organizationSelectors.selectById(state, id)],
    organization => organization.name
  );

export default selectOrganizationName;
Run Code Online (Sandbox Code Playgroud)
Missing return type on function.eslint@typescript-eslint/explicit-module-boundary-types
Run Code Online (Sandbox Code Playgroud)

typescript reselect redux-toolkit

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

Cleancode:在Promise中尝试/捕获

我正在使用redux-form atm并找到了这段代码.它为我工作但是有没有更清洁的方式来写这个ES6风格?

const asyncValidate = (values/* , dispatch */) => {
  return new Promise((resolve, reject) => {
    try {
      if (['john', 'paul', 'george', 'ringo'].includes(values.name)) {
        const error = {
          name: 'That username is taken'
        };
        throw error;
      }
      resolve();
    } catch (e) {
      reject(e);
    }
  });
};
Run Code Online (Sandbox Code Playgroud)

我很感激你的帮助


const asyncValidate = (values/* , dispatch */) => {
  return new Promise((resolve, reject) => {
    const errors = {};
    if (['john', 'paul', 'george', 'ringo'].includes(values.name)) {
      errors.name = 'That username is taken'; …
Run Code Online (Sandbox Code Playgroud)

javascript coding-style ecmascript-6 es6-promise

8
推荐指数
1
解决办法
7531
查看次数

使用 sass 和 css 模块主题化 React 应用程序

我想在我的反应应用程序中实现主题。因此我使用了这个教程(sass-mixins)。

但这不能与 css-modules 结合使用,因为主题类位于我想要主题化的 css-module 之外。

有没有人有解决此问题的方法或使用 sass 主题化反应应用程序的另一种方法?

应用程序.js

const theme = require('../../Theming.sass)

<div class={theme['theme-dark'}>
  <SearchBar/>
  ...
</div>
Run Code Online (Sandbox Code Playgroud)

搜索栏.js

const styles = require('./SearchBar.scss)
const theme = require('../../Theming.sass)

<div class={styles.searchBar}>
  ...
</div>
Run Code Online (Sandbox Code Playgroud)

搜索栏.scss

.searchBar {
  @include themify($themes) {
    color: themed('primary');
    background: themed('secondary');
  }

  height: 3em;
  overflow: hidden;
Run Code Online (Sandbox Code Playgroud)

SearchBar.css(已编译)

.searchBar {
  height: 3em;
  overflow: hidden;
}

.theme-light .searchBar {
  color: #fff;
  background: #bfbfbf;
}

.theme-dark .searchBar {
  color: #000;
  background: #1a1a1a;
}
Run Code Online (Sandbox Code Playgroud)

主题化.sass

.theme-dark { background: #000; }

.theme-light …
Run Code Online (Sandbox Code Playgroud)

sass reactjs css-modules

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

检测图像中重叠的噪声圆圈

我尝试识别下图中的两个区域。内部区域内部以及外部和内部之间的区域 - 边界 - 使用 python openCV 进行圆化。

在此输入图像描述

我尝试了不同的方法,例如:

这不太合适。

这对于经典图像处理来说是可能的还是我需要一些神经网络?

编辑:使用 opencv 霍夫圆检测圆图像

# import the necessary packages
import numpy as np
import argparse
import cv2
from PIL import Image

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())

# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread(args["image"])
output = …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing image-recognition

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

sqlite3-异步调用的承诺

我想选择一个sqlite3数据库的异步数据。但是由于db.each是异步函数,因此我的以下select函数无法正常工作。如何添加一个承诺来等待结果?

const sqlite3 = require('sqlite3').verbose();

export default function select(database, table) {
  return new Promise((resolve, reject) => {
    const db = new sqlite3.Database(database);
    const queries = [];
    db.each(`SELECT rowid as key, * FROM ${table}`, (err, row) => {
      if (err) {
        reject(err);
      }
      console.log(`Push row ${row.key} from database.`);
      queries.push(row);
    });
    console.log(queries);
    console.log(JSON.stringify(queries));
  });
}
Run Code Online (Sandbox Code Playgroud)

代码片段的结果

javascript sqlite asynchronous promise

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

sqlite3 - 插入 - javascript 对象作为值

使用 javascript 对象作为 sqlite3 插入的值的最简单的解决方案是什么?下面的代码不起作用。

const values = {
  name: 'John',
  age: 34,
  language: 'english'
};

db.run('INSERT INTO tablename VALUES (?)', values, (err) => {
  if (err) {
    console.log(err);
  } else {
    console.log('success');
  }
});
Run Code Online (Sandbox Code Playgroud)

javascript sqlite insert

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

如何仅触发可点击div中的内部可点击

如何仅触发可点击div中的内部可点击div?

如果你点击内部的蓝色框,内部和外部的onclick事件都会被触发,但我只是想触发蓝色的事件?

.outer {
  width: 100px;
  height: 50px;
  cursor: pointer;
  background: green;
  }
  
.inner {
  width: 50px;
  height: 50px;
  cursor: pointer;
  background: blue;
}
Run Code Online (Sandbox Code Playgroud)
<div class="outer" onclick="alert('Hello world from outside');" role="button" tabIndex="-1">
  <div class="inner" onclick="alert('Hello world form inside');" role="button" tabIndex="-1">
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

不确定是否有必要提及但我想在使用sass的React中修复此问题.

html javascript css hyperlink

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

多个链接的指针

对于家庭作业,我必须构建以下简单方案。

在此处输入图片说明

我的尝试看起来像:

#include <stdlib.h>

int main() {
  char* heap1P = malloc(sizeof(char**));
  char* heap2P = malloc(sizeof(char*));
  char* heap3P = malloc(sizeof(char));

  *heap3P = 'X';
  *heap2P = heap3P;
  *heap1P = heap2P;

  char*** stackP = heap1P;

  puts("stack                           | heap ");
  printf("%p [%p] | %p [%p] => %p [%p] => %c [%p] \n", stackP, &stackP, *heap1P, heap1P, *heap2P, heap2P, *heap3P, heap3P);

  return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

首先,我在内存中分配空间,然后设置值。输出类似于(格式:值[地址]):

stack                           | heap 
0x55a1e184f260 [0x7fff05e55c08] | 0xffffff80 [0x55a1e184f260] => 0xffffffa0 [0x55a1e184f280] => X [0x55a1e184f2a0] 
Run Code Online (Sandbox Code Playgroud)

如您所见,堆栈值包含第一个堆值的地址。但是堆值不正确。它们不包含以下堆值的地址。

为什么堆值不包含给定的地址?

c pointers

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

多行中的多个返回值

如何在GoLang中多行返回多个值?

  if  x == y {
    req, _ := cgi.Request()
    return req.FormValue("a"),
      req.FormValue("b"),
      req.FormValue("c"),
      req.FormValue("d"),
      req.FormValue("e"),

  } else {
      ...
  }
Run Code Online (Sandbox Code Playgroud)

./example.go:9:3:语法错误:意外},期待表达

return return-type go

-1
推荐指数
1
解决办法
111
查看次数