react-testing-library

Submitted by Lizhe on Mon, 06/11/2018 - 16:27

任意目录下的 *.test.js

__tests__ 目录下的 *.js

 

import React from 'react'
import {renderIntoDocument, cleanup} from 'react-testing-library'
import App from '../App'
import * as jestDom from 'jest-dom'

expect.extend(jestDom)

afterEach(cleanup)

React ES6 优化笔记

Submitted by Lizhe on Mon, 06/11/2018 - 08:29

以下内容为最近一段时间使用React的优化笔记

1. 使用解构传递参数

const AddPlayerForm = ({ values, onSubmit, onChange }) => {

    return (...)

}

2. promise函数中不一定要使用_this


          .then(response => {
              if(this.isMountedDone) {
                  this.setState({
                      options: response.data
                  });
              }

3.     Stop Memory Leaks with componentWillUnmount Lifecycle Method in React

Kong API Gateway Load Balance

Submitted by Lizhe on Fri, 06/01/2018 - 12:15

第一步你需要创建一个upstream

这里命名为 helloworld_upstream

[admin@localhost ~]$ curl -i -X POST --url http://localhost:8001/upstreams/ -d "name=helloworld_upstream"
HTTP/1.1 201 Created
Date: Fri, 01 Jun 2018 04:17:49 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

Kong API Gateway Helloworld

Submitted by Lizhe on Fri, 06/01/2018 - 09:09

 

 

[admin@localhost ~]$ curl -i -X POST http://localhost:8001/apis/ -d "name=helloworld" -d "uris=/helloworld" -d "upstream_url=http://www.baidu.com"
HTTP/1.1 201 Created
Date: Fri, 01 Jun 2018 01:59:15 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

Kong API Gateway Install and Start

Submitted by Lizhe on Thu, 05/31/2018 - 09:20

https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-0.13.1.el7.noarch.rpm

sudo yum install epel-release

sudo yum install kong-community-edition-0.13.1.el7.noarch.rpm

 

安装数据库

sudo yum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm

 

sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7.6-x86_64/pgdg-centos96-9.6-3.noarch.rpm

sudo yum install postgresql94

mysql seq

Submitted by Lizhe on Fri, 05/11/2018 - 10:58

create table tb_sequence(name varchar(50) not null,current_value int not null,_increment int not null default 1, primary key(name));

insert into tb_sequence values('userid',0,1);

DELIMITER //

create function _nextval(n varchar(50)) returns integer

begin

declare _cur int;

set _cur=(select current_value from tb_sequence where name= n for update);

update tb_sequence set current_value = _cur + _increment where name=n ;

return _cur; end;

//

 

DELIMITER ;

 

 

centos7 chrome install

Submitted by Lizhe on Wed, 04/04/2018 - 10:40

 

https://blog.csdn.net/u010472499/article/details/72327963

1. 配置yum源

在目录 /etc/yum.repos.d/ 下新建文件 google-chrome.repo

cd /ect/yum.repos.d/ vim google-chrome.repo

  • 1
  • 2

写入如下内容:

start node

Submitted by Lizhe on Wed, 04/04/2018 - 10:07

cd /root/.jenkins/workspace/fr-commerce-front-admin/app

npm install

python /root/pyscripts/sedByPy.py ./scripts/start.js "const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;" "const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3001;"
python /root/pyscripts/sedByPy.py ./scripts/start.js "openBrowser(urls.localUrlForBrowser);" " "

npm install http-server -g
npm start &

python /root/pyscripts/test.py 

 

 

React browserHistory.push 传参

Submitted by Lizhe on Tue, 03/27/2018 - 16:03

传参方式1:

将参数直接写在路径中,前提是router定义时,需要指定参数的名字,这里假定为:value;

browserHistory.push(pathname: '/routerName/123');

如何获取到123呢?

通过this.props.params.value即可获取

传参方式2:

通过state传参,可以在页面跳转时,url中不显示参数;

browserHistory.push(pathname: '/routerName',state: { key: value });

跳转界面如何接收参数呢?

this.props.location.state.key便可以获得state中的key的value;

 

尝试了第二种方式发现不好用, 可能是router版本更新到4之后网上的内容太旧了

经过推敲之后发现可以这样