我正在使用react,redux和react-router.我的一个页面是发出API请求并显示数据.它工作正常.我想知道的是,如果API请求尚未完成,并且用户导航到另一个路由,我希望能够中止请求.
我假设我应该派出一些行动componentWillUnmount.只是无法理解它将如何运作.就像是...
componentWillUnmount() {
this.props.dispatch(Actions.abortRequest());
}
Run Code Online (Sandbox Code Playgroud)
我会xhr在动作的某处存储引用.不确定这是否是正确的方法(我认为不是),有人能指出我正确的方向吗?
我正在为react和redux的应用程序编写测试用例.
container = TestUtils.renderIntoDocument(
<Provider store={createStore({"key": "old_val"})}>
{() => <Component />}
</Provider>
);
Run Code Online (Sandbox Code Playgroud)
渲染后initialState,我发出一个动作,看看状态是否发生了变化.
Component.store.dispatch({ type: 'SET_VAL', value: 'some_val' });
Run Code Online (Sandbox Code Playgroud)
然后我打印状态
console.log(store.getState());
Run Code Online (Sandbox Code Playgroud)
我期待这个州{"key": "some_val"}.但是,它仍然显示{"key": "old_val"}.
应用程序工作正常,只是没有测试,所以我action-creators或我的任何问题都没有reducers.
我在这里做错了吗?顺便说一下,我正在使用thunk中间件进行异步操作调度.这会干扰吗?如果是,我该如何等待异步操作完成?
更新:
这里显示的redux测试非常简单,但它们似乎工作正常.
store.dispatch(addTodo('Hello'));
expect(store.getState()).toEqual([{
id: 1,
text: 'Hello'
}]);
Run Code Online (Sandbox Code Playgroud) javascript是否保证即使将新值分配给键,也会保留对象的键序列?
例如,如果我有以下对象
var Object = {
keyX: value1,
keyB: value2,
keyZ: value3
}
Run Code Online (Sandbox Code Playgroud)
如果我使用密钥迭代for .. in,我得到正确的序列即keyX, keyB, keyZ.如果我改变了值keyB,我仍然在迭代中获得相同的序列.
我的问题是,序列是否始终保持不变,或者在任何情况下都可能发生变化?
我试图在Solr架构中使用ICUTokenizerFactory.这是我定义field和fieldType.
<fieldType name="text_icu" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.ICUTokenizerFactory"/>
</analyzer>
</fieldType>
<field name="fld_icu" type="text_icu" indexed="true" stored="true"/>
Run Code Online (Sandbox Code Playgroud)
而且,当我启动Solr时,我得到了这个错误
Plugin init failure for [schema.xml] fieldType "text_icu": Plugin init failure for [schema.xml] analyzer/tokenizer: Error loading class 'solr.ICUTokenizerFactory'
Run Code Online (Sandbox Code Playgroud)
我搜索过但没有成功.我不知道我是否遗漏了某些东西或者架构中存在一些问题.如果有人尝试过ICUTokenizerFactory,那么请建议可能出现的问题.
我在node.js上使用https://github.com/felixge/node-mysql模块.
Mysql表有一个类型的字段POINT.该模块需要发送数组数组以插入批量记录.但它似乎没有指定数据类型的选项.
很自然地,下面的内容用引号括起来
var loc = "GeomFromText('POINT(" + lat + "," + lon + ")')";
Run Code Online (Sandbox Code Playgroud)
有人试过吗?如何说服查询构建器将其视为sql函数?
或者我是否必须创建自己的查询构建器?
我正在尝试在Angular2中创建一个具有"重复密码"功能的注册表单.我希望这可以使用自定义验证器作为表单控件.
我遇到的问题是,当验证器运行时,"this-context"似乎被设置为验证器,因此我无法访问RegistrationForm类上的任何本地方法.我似乎无法找到从验证器访问ControlGroup的任何好方法.
任何人都知道在自定义验证器中访问同一控件组中的其他控件的好方法吗?
这是组件的简短示例:
import { Component, View } from 'angular2/angular2';
import { Validators, ControlGroup, Control, FORM_DIRECTIVES, FORM_BINDINGS } from 'angular2/angular2';
@Component({
selector: 'form-registration'
})
@View({
directives: [FORM_DIRECTIVES, ROUTER_DIRECTIVES],
template: `
<form (submit)="register($event)" [ng-form-model]="registerForm">
<label for="password1">Password:</label>
<input id="password1" ng-control="password1" type="password" placeholder="Passord" />
<label for="password2">Repeat password:</label>
<input id="password2" ng-control="password2" type="password" placeholder="Gjenta passord" />
<button class="knapp-submit" type="submit" [disabled]="!registerForm.valid">Registrer deg</button>
</form>
`
})
export class RegistrationForm {
registerForm: ControlGroup;
constructor() {
this.registerForm = new ControlGroup({
password1: new Control('', Validators.required),
password2: new Control('', this.customValidator) …Run Code Online (Sandbox Code Playgroud) javascript ×2
reactjs ×2
redux ×2
analyzer ×1
angular ×1
jasmine ×1
lucene ×1
mysql ×1
node.js ×1
point ×1
react-router ×1
schema ×1
solr ×1
tokenize ×1
typescript ×1