小编Dan*_*ani的帖子

用Jest模拟redux saga中间件

我有这个configureStore.js,它配置我的增强型redux存储并将其持久存储到localStorage中:

// @flow

import 'babel-polyfill'

import { addFormSubmitSagaTo } from 'redux-form-submit-saga/es/immutable'
import { applyMiddleware, createStore, compose } from 'redux'
import { autoRehydrate, persistStore } from 'redux-persist-immutable'
import { browserHistory } from 'react-router'
import { combineReducers } from 'redux-immutable'
import { fromJS } from 'immutable'
import { routerMiddleware } from 'react-router-redux'
import createSagaMiddleware from 'redux-saga'

import rootReducer from './reducers'
import sagas from './sagas'

export default function configureStore () {
  const initialState = fromJS({ initial: { dummy: true } })
  const sagaMiddleware …
Run Code Online (Sandbox Code Playgroud)

unit-testing jestjs redux-saga

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

在对象上设置默认值时,流程缺少道具验证

我有一个反应的官能组件,它采用一个List作为道具。

const Dashboard = (props: { items: List } = { items: List() }) => {
  const { items } = props
  ...
})
Run Code Online (Sandbox Code Playgroud)

但是,itemsin const { items } = props会产生以下错误:

error 'items' is missing in props validation react/prop-types

流动型的文档举个例子:

ES2015功能设定参数必须出现在参数的类型标注后的默认值:

函数foo(P1:T1 = V):U {..}

但它不是真的我清楚如何适用对象

javascript static-typing eslint flowtype

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

无法安装node-postgres

我正在尝试为我的项目设置node-postgres.但是,当我尝试安装它时,我不断收到这些gyp错误.如何让node-postgres识别出我的pg_config位于/Library/PostgreSQL/9.3/bin/pg_config中.因为我最喜欢的搜索引擎结果告诉我这样做:

?  src git:(master) ? PG_CONFIG=/Library/PostgreSQL/9.3/bin/pg_config
?  src git:(master) ? export PG_CONFIG
?  src git:(master) ? sudo npm install pg
Password:
npm WARN package.json test@0.1.0 No repository field.
npm http GET https://registry.npmjs.org/pg
npm http 304 https://registry.npmjs.org/pg
npm http GET https://registry.npmjs.org/generic-pool/2.0.3
npm http GET https://registry.npmjs.org/buffer-writer/1.0.0
npm http GET https://registry.npmjs.org/pgpass/0.0.1
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/pgpass/0.0.1
npm http 304 https://registry.npmjs.org/buffer-writer/1.0.0
npm http 304 https://registry.npmjs.org/generic-pool/2.0.3
npm http GET https://registry.npmjs.org/split
npm http 304 https://registry.npmjs.org/split
npm http GET https://registry.npmjs.org/through …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js node-postgres

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

基于加载模板的css类

我在我的_base.html模板中有这样的bootstrap导航,如下所示:

<ul class="nav navbar-nav">
   <li><a href="/" class="">Home</a></li>
   <li><a href="/blog/">Blog</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

使用Golang我想添加一个

class="active"
Run Code Online (Sandbox Code Playgroud)

到相应的列表项.

我读过的HTML /模板文件和类似物品thisone,但在我看来,我必须写一个golang功能,增加了

class="active"
Run Code Online (Sandbox Code Playgroud)

到每个对应的相应列表项.但不知怎的,我觉得如果我能添加类似的东西会更清洁

<ul>
    <li{{ if .template = "index.html" }} class="active"{{ end }}><a href="/">Home</a></li>
    <li{{ if .template = "blog.html" }} class="active"{{ end }}><a href="/blog/">Blog</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

或类似的东西.我记得Rob Pike说Golang应该为你做所有的计算,但为什么html/template-package中有一个"if"语句?

css go go-html-template

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

将node.js-mysql结果返回给函数

我有两个node.js文件:server.js和database.js。我希望我的socket.io发出发生在server.js中,而数据库查询发生在database.js中。Server.js:

// init
io.sockets.on('connection', function(socket) {
    initdb = db.initdb();
    console.log(initdb)
});
Run Code Online (Sandbox Code Playgroud)

我的database.js基本上包含以下代码:

function query(queryString) {
    connection = mysql.createConnection({
        host: '12.23.45.67',
        user: 'user',
        password: 'password',
        database: 'database'
    });

    connection.connect();

    var res = connection.query(queryString, function(err, rows, fields) {
        if (err) throw err;
    });

    connection.end();
}


// export initdb for external usage by server.js
exports.initdb = function() {
    var initdb = query("SELECT * FROM columns;");
};
Run Code Online (Sandbox Code Playgroud)

我的问题是我希望将connection.query函数中的行对象返回给我的initdb函数。但是,我可以记录该对象的唯一位置是该函数内。如何传递查询结果,以便可以从server.js发出JSON对象?

javascript json node.js socket.io node-mysql

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

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