小编Sha*_*ika的帖子

用于ASP.NET样板的SignalR集成

我正在研究一个ASP.NET Boilerplate项目。我想将SignalR正确集成到该项目中。

有文档,但是当我从后端向前端发送通知时,我想了解SignalR的流程。任何示例代码或建议,表示赞赏。

signalr aspnetboilerplate

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

saga 中 thunk 调度的替代方案是什么?

在我的反应项目中,我有以下代码。

import uuid from 'uuid';
import { SET_ALERT, REMOVE_ALERT } from './types';

export const setAlert = (msg, alertType, timeout = 5000) => dispatch => {
  const id = uuid.v4();
  dispatch({
    type: SET_ALERT,
    payload: { msg, alertType, id }
  });

  setTimeout(() => dispatch({ type: REMOVE_ALERT, payload: id }), timeout);
};
Run Code Online (Sandbox Code Playgroud)

这里就用到了thunk。我将 saga 应用到项目中,我想用 saga 重写。由于没有 API 调用,我不想通过 saga 发送到减速器。我想从这个action直接转到reducer。那么如何在不发送的情况下重写呢?

javascript reactjs react-native redux-thunk redux-saga

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

在 redux saga 中的 setTimeOut 内部使用 Yield

在我的 React 项目中,我有以下代码:

export function* onDisplayAlert({ payload }: any) {
  payload.id = getUniqueID();
  yield put(setAlert(payload));

  yield setTimeout(() => {
    yield put(removeAlert(payload.id));
  }, 3000);
}
Run Code Online (Sandbox Code Playgroud)

我想要在这里做的是使用yield内部setTimeOut回调。

yield put(removeAlert(payload.id));
Run Code Online (Sandbox Code Playgroud)

但是我写的方法不起作用,因为箭头函数回调不是生成器函数,所以我不能在其中使用yield。我如何在里面使用yield setTimeOut

javascript typescript reactjs react-native redux-saga

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

编写一个单元测试来检查应用程序是否在react-native中离线

我有以下组件,如果应用程序离线,它会在应用程序上显示文本。

\n
import React from 'react';\n\nimport { useNetInfo } from '@react-native-community/netinfo';\n\nimport { Label } from 'components/ui';\n\nconst OfflineNotice = () => {\n  const netInfo = useNetInfo();\n\n  if (netInfo.type !== 'unknown' && netInfo.isInternetReachable === false) {\n    return <Label size={18} text='No Internet Connection' />;\n  }\n\n  return null;\n};\n\nexport default OfflineNotice;\n
Run Code Online (Sandbox Code Playgroud)\n

我想为此编写一个单元测试来检查它是否正常工作。我该怎么做?\n我是单元测试新手。我不明白如何嘲笑这个。

\n

我使用打字稿和测试库/反应本机。

\n

更新: \n为什么第一次测试失败?它不应该为空。但它失败了。错误是,

\n
OfflineNotice component \xe2\x80\xba test\n\nexpect(received).not.toBeNull()\n\nReceived: null\n\n  15 | \n  16 |     const { queryByText } = render(<OfflineNotice />);\n> 17 |     expect(queryByText(/no internet connection/i)).not.toBeNull();\n     |                                                        ^\n  18 …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs react-native react-native-community-netinfo react-native-testing-library

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

角度返回网址

我目前正在处理的项目,我想将 returnUrl 应用于登录。我在这里附上了代码。当我尝试在 ngOnInit() 中初始化 returnUrl 时,它无法正常工作。但是如果我在 login 方法中初始化 returnUrl ,它就可以工作。这里可能有什么问题?

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { LoginUser } from '../_models/LoginUser';
import { AlertifyService } from '../_services/alertify.service';
import { AuthService } from '../_services/auth.service';

@Component({
  selector: 'app-nav',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})

export class NavBarComponent implements OnInit {
  user: LoginUser = { username: '', password: '' };
  photoUrl: string;

  constructor(
    public authService: AuthService,
    private alertify: AlertifyService,
    private router: Router,
    private route: …
Run Code Online (Sandbox Code Playgroud)

angular

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

在 react-native 中的 navigation.goBack() 之后重新加载屏幕

我想在使用 react-native 中的 navigation.boBack() 导航后重新加载我的屏幕。

这是我的代码。

 // navigation options
 static navigationOptions = ({ navigation }) => {
    const { params = {} } = navigation.state;

    return {
        headerTitle: "Comment",
        headerTitleStyle: {
            marginLeft: 0,
            width: "100%",
            textAlign: "center",
            fontWeight: 'bold',
            fontFamily: "helvetica",
        },
        headerStyle: {
            paddingLeft: 10,
            paddingRight: 10
        },
        headerLeft: (
            <ClickableIcon
                source={Close}
                height={35}
                width={35}
                onIconPressed={() => {
                    navigation.goBack();
                }}
            />
        ),
        headerRight: <View />
    };
};
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

react-native

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

在玩笑和酵素中检查按钮文字

我有以下反应本机测试代码。

it('should render a <BorderlessButton />', () => {
    expect(wrapper.find(BorderlessButton)).toHaveLength(1);
    expect(wrapper.find(BorderlessButton).props.text.toEqual('D'));
  });
Run Code Online (Sandbox Code Playgroud)

这不能正常工作。我要检查的是按钮文本。我怎样才能做到这一点?

javascript reactjs jestjs react-native enzyme

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

节点/快速安全

我正在开发我的第一个节点应用程序。现在可以部署了,我想保护我的应用程序。所以我使用这些库来保护它。

import mongoSanitize from 'express-mongo-sanitize';
import helmet from 'helmet';
import xss from 'xss-clean';
import hpp from 'hpp';
import cors from 'cors';
import rateLimit from 'express-rate-limit';
Run Code Online (Sandbox Code Playgroud)

我想知道的是,我在这里复制东西吗?我必须使用所有这些库吗?这里的库是否做同样的事情,以便我可以通过从应用程序中删除不必要的中间件来删除它们以提高应用程序的性能?

javascript middleware node.js express

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

将 ES6 类转换为 typescript 类

我有以下 ES6 类。

class Http {
    isFormData;
    url;
    token;
    data;

    constructor() {
        this.isFormData = false;
        this.url = '';
        this.token = '';
        this.data = {};
    }

    /** Set url */
    setUrl(url: string) {
        this.url = url;
        return this;
    }

    /** Set data */
      setData(data: Object) {
        this.data = data;
        return this;
    }
}

export default new Http();
Run Code Online (Sandbox Code Playgroud)

我想让它成为一个打字稿类。我试过了,但有些属性没有正确识别。我怎样才能使它成为一个打字稿类?

javascript node.js typescript ecmascript-6 reactjs

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

订阅做什么,以及它与Observable的关系如何?

我是Angular的新手,我所遵循的教程有" Observable".导师解释说,但我并不完全明白.

什么是Observable,为什么我们总是要打电话 observable.subscribe()

什么是subscribe()真正做到?

observable rxjs rxjs5 angular

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