问题列表 - 第271125页

React-Native + Enzyme + Jest:如何测试平台的特定行为?

TLDR:如何告诉我的Enzyme / Jest测试应该像在iOS上一样运行测试?我想测试平台的特定行为

我正在构建一个自定义状态栏组件,如果该组件在iOS上运行时会增加20像素的高度,以防止我的内容与状态栏重叠。(是的,我知道React-Navigation具有SafeAreaView,但这仅适用于iPhone X,不适用于iPad。)

这是我的组件:

import React from "react";
import { StatusBar as ReactNativeStatusBar, View } from "react-native";

import styles from "./styles";

const StatusBar = ({ props }) => (
  <View style={styles.container}>
    <ReactNativeStatusBar {...props} />
  </View>
);

export default StatusBar;
Run Code Online (Sandbox Code Playgroud)

Here is the styles.js file:

import { StyleSheet, Platform } from "react-native";

const height = Platform.OS === "ios" ? 20 : 0;

const styles = StyleSheet.create({
  container: {
    height: height
  }
});

export default …
Run Code Online (Sandbox Code Playgroud)

platform platform-specific jestjs react-native enzyme

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

检查 scrollTo 以完成

我有一个可滚动的元素。我还有一个滚动到特定位置的功能。我想在 scrollTo 完成后调用一个函数。

Plunkr 示例

var x = document.querySelector('.container');
$scope.scrollTo = function() {
  x.scrollTo({
    top: 300 ,
    behavior: 'smooth'
  });
};

 // do something when scrollTo is finished
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

6
推荐指数
2
解决办法
4587
查看次数

ASP .NET CORE simple parameter validation

I have implemented model validation in some of my APIs, but I was wondering if it is possible to do some validation using attributes on simple parameters, like:

[HttpGet("test/{type}")]
public ActionResult  GetSomeData([Range(0,2)]byte type)
{
  if (!ModelState.IsValid)
  {
    // isValid is always TRUE
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

When you call /controller/test/4, IsValid is always TRUE.

Is there a clean way to do that?

Thanks!

c# validation asp.net-core

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

如何在 CNN 中训练卷积核?

在 CNN 中,卷积操作在输入矩阵上“卷积”一个内核矩阵。现在,我知道全连接层如何利用梯度下降和反向传播来训练。但是核矩阵是如何随时间变化的呢?

在 Keras 文档中,有多种初始化内核矩阵的方法,如此处所述。但是,我很想知道它是如何训练的?如果它也使用反向传播,那么有没有详细描述训练过程的论文?

这篇文章也提出了一个类似的问题,但没有答案。

convolution backpropagation conv-neural-network keras

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

引用属性写入中的公共setter

我可以引用一个共同的制定者_setTerm在性write访问,而无需编写单独的setter方法_setTerm1,_setTerm2,_setTerm3

TAdder = class(TCalculatorComponent)
private
  _terms: array[1..10] of OleVariant;
  procedure _setTerm(const i: Integer; const Value: OleVariant);
  procedure _setTerm1(const Value: OleVariant);
  procedure _setTerm2(const Value: OleVariant);
  procedure _setTerm3(const Value: OleVariant);
  .......
public
  constructor Create(AOwner: TComponent); override;
  property Term1: OleVariant read _terms[1] write _setTerm1;
  property Term2: OleVariant read _terms[2] write _setTerm2;
  property Term3: OleVariant read _terms[3] write _setTerm3;
  .......
end;

implementation

procedure TAdder._setTerm(const i: Integer; const Value: OleVariant);
begin
  _terms[i] := TVarConv.NullableFloat(Value);
  _calculate(); …
Run Code Online (Sandbox Code Playgroud)

arrays delphi setter

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

无法使用Saxon处理器应用区间运算

我正在使用Saxon处理器来执行验证.
包含所有函数定义的文件如下:
default-definition.txt:

declare variable $a external; 
declare variable $b external; 
declare variable $c external; 

declare function iaf:sum(
$params as item()*
) as item()+ {

  let $facts := if (empty($params)) then (0) else one-or-more($params)
  let $values := for $i in $facts return (iaf:splitValueThreshold($i)[1])
  let $thresholds := for $i in $facts return (iaf:splitValueThreshold($i)[2])
  let $sumValues := sum($values)
  let $sumThresholds := sum($thresholds)
  let $output := iaf:joinValueThreshold($sumValues, $sumThresholds) 
       return ($output)

};

declare function iaf:numeric-equal(
$paramA as item(), $paramB as item() …
Run Code Online (Sandbox Code Playgroud)

java xml xquery saxon xbrl

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

Eslint(Airbnb)缩进问题与React代码(JSX)

我正在与我的eslint一起解决一个小问题,它似乎在大多数情况下工作正常,但有些情况下它与React代码不起作用.

我们以此代码为例:

const cellPLay = (name, src) => (
  <Table.Cell>
    <Modal trigger={<Button icon><Icon name="video play" size="large" /></Button>}>
      <Modal.Header>
        {name}
      </Modal.Header>
      <Modal.Content image>
        <Modal.Description>
          <video src={src} controls style={{ width: 910 }} />
        </Modal.Description>
      </Modal.Content>
    </Modal>
  </Table.Cell>
);
Run Code Online (Sandbox Code Playgroud)

给出这样的错误:

/my-path/MyFile.js:18:7:预期缩进8个空格字符,但找到6. [Error/react/jsx-indent]

出于某种原因,eslint认为Modal.Content应该在Modal.Header之后缩进,但是即使我修复了所有缩进,它也要求它说某些结束标记的缩进是错误的:

预期结束标记以匹配开口缩进

我的eslint配置文件:

{
  "extends": "./my-eslint/index.js"
}
Run Code Online (Sandbox Code Playgroud)

实际的eslint代码:

module.exports = {
  extends: require.resolve('eslint-config-airbnb'),
  env: {
    browser: true,
    jest: true,
    es6: true,
  },
  parserOptions: {
    ecmaVersion: 8,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint visual-studio-code eslint-config-airbnb

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

eslint错误:找不到任何可观察到的实现或全局。

我已经安装了最新版本"rxjs": "6.2.2","redux-observable": "1.0.0",

我有预先提交的钩子,可以进行eslint检查。

安装开始后,抛出此错误:

C:\XXX\node_modules\any-observable\register.js:29
                throw new Error('Cannot find any-observable implementation nor' +
                ^

Error: Cannot find any-observable implementation nor
global.Observable. You must install polyfill or call
require("any-observable/register") with your preferred implementation,
e.g. require("any-observable/register")('rxjs') on application load
prior to any require("any-observable").
    at loadImplementation (C:\XXX\node_modules\any-observable\register.js:29:9)
    at register (C:\XXX\node_modules\any-observable\loader.js:32:18)
    at Object.<anonymous> (C:\XXX\node_modules\any-observable\index.js:2:39)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)

husky > pre-commit hook …
Run Code Online (Sandbox Code Playgroud)

rxjs eslint redux-observable

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

如何在 Automapper 和 Asp.Net Core 依赖注入中使用通用配置文件

我想创建将包含以下扩展方法的 .Net Core 类库:

public static class MyServiceExtensions
    {
        public static IServiceCollection AddMyService<TUserDto, TUserDtoKey, TUser, TUserKey>(this IServiceCollection services)
            where TUserDto : UserDto<TUserDtoKey>
            where TUser : User<TUserKey>
        {
            services.AddAutoMapper(config =>
            {
                config.AddProfile<UserMappingProfile<TUserDto, TUserDtoKey, TUser, TUserKey>>();
            });

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

我有以下 Automapper 配置文件:

public class UserMappingProfile<TUserDto, TUserDtoKey, TUser, TUserKey> : Profile 
        where TUserDto : UserDto<TUserDtoKey>
        where TUser : User<TUserKey>
    {
        public UserMappingProfile()
        {
            CreateMap<TUserDto, TUser>(MemberList.Destination)
                .ForMember(x => x.Id, opts => opts.MapFrom(x => x.UserId));

            CreateMap<TUser, TUserDto > (MemberList.Source)
                .ForMember(x => x.UserId, opts …
Run Code Online (Sandbox Code Playgroud)

c# automapper .net-core asp.net-core

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

C++ - Bool 到 int 转换错误

我的代码中有一个函数,如下所示:

bool foo(ObjectType& object){

    //code

    const float result = object.float_data + object.bool_data * integer_data;

    //code

}
Run Code Online (Sandbox Code Playgroud)

在寻找错误时,我发现result有时会有不正确的值,原因是有时bool*integer被计算为255*integer而不是1*integer

C++ 说在整数上下文中bool会转换为零或一,所以我不明白这一点。我与bool代码中的其他部分相乘,效果很好。这也是随机的:有时会转换为1,有时会转换为255。调试器还分别显示true255。当这个错误发生时,它总是发生在该执行中。重新编译代码没有任何效果,它仍然随机发生。

c++ gcc c++17

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