这个问题与Redux Form v6.0.0有关(在写这个问题的时候它是v6.0.0-alpha.15).
我怎样才能得到表单验证身份(如pristine,submitting,invalid)从表格组件的外面?
让我举个例子.这是"经典的redux-form"伪结构:
<Form(MyExampleForm)>
<MyExampleForm>
<input name="title" ... />
<submit-button />
Run Code Online (Sandbox Code Playgroud)
... <submit-button>在JSX中的位置如下:
<button type="submit" disabled={pristine || submitting || invalid} >Save</button>
但是在我的应用程序中,我的提交按钮必须位于表单之外,放在应用程序的不同位置(假设在应用程序标题中,位于整个应用程序的顶部).
pristine,submitting,invalid从终极版表格之外?(如果可能的话,没有真正令人讨厌的黑客:-))我想测试,如果在我的测试中调用了特定的函数并且使用了正确的参数.从JEST文档中我无法弄清楚,正确的方法是什么.
假设我有这样的事情:
// add.js
function child(ch) {
const t = ch + 1;
// no return value here. Function has some other "side effect"
}
function main(a) {
if (a == 2) {
child(a + 2);
}
return a + 1;
}
exports.main = main;
exports.child = child;
Run Code Online (Sandbox Code Playgroud)
现在进行单元测试:
我想运行main(1)并测试它返回2并且child()没有被调用.
2.然后我想跑main(2),并且它返回3并且child(4)被称为恰好一次.
我现在有这样的事情:
// add-spec.js
module = require('./add');
describe('main', () => {
it('should add one and not call child …Run Code Online (Sandbox Code Playgroud) 从Golang中的切片创建自己的类型是个好主意吗?
例:
type Trip struct {
From string
To string
Length int
}
type Trips []Trip // <-- is this a good idea?
func (trips *Trips) TotalLength() int {
ret := 0
for _, i := range *trips {
ret += i.Length
}
return ret
}
Run Code Online (Sandbox Code Playgroud)
在Golang中以某种方式创建类似于Trips我的示例中的类型吗?或者最好[]Trip在整个项目中使用?有什么优点和缺点?
我想编写一个跟踪应用程序,当用户上车时,它会做出反应/记录,而手机会自动与蓝牙配对.我还需要免提设备的ID.
在Android上很容易,使用广播接收器你的应用程序听设备已与手机配对的广播.它甚至在手机重新启动后工作,并且重启后App没有运行.
在iOS(7+)上可以吗?
javascript ×2
bluetooth ×1
convention ×1
conventions ×1
go ×1
ios7 ×1
iphone ×1
jestjs ×1
reactjs ×1
redux ×1
redux-form ×1
unit-testing ×1