目前我正在这样做,但这不是react.js的方式,对吧?render()是正确的地方吗?有什么选择?
var App = React.createClass({
render: function() {
if (this.state.touchMode === 2) {
$('body').addClass('touchMode');
}
return (<div> etc /div>)
}
)}
Run Code Online (Sandbox Code Playgroud) 我有一个带有功能的模块:
const utils = {
redirectTo(url) {
if (url) {
window.location = url;
}
},
};
export default utils;
Run Code Online (Sandbox Code Playgroud)
它在React组件的某处使用,如下所示:
import utils from '../../lib/utils';
componentWillUpdate() {
this.redirectTo('foo')
}
Run Code Online (Sandbox Code Playgroud)
现在,我要检查redirectTo用equals调用的值foo。
it('should redirect if no rights', () => {
const mockRedirectFn = jest.fn();
utils.redirectTo = mockRedirectFn;
mount(
<SomeComponent />,
);
expect(mockRedirectFn).toBeCalled();
expect(mockRedirectFn).toBeCalledWith('foo');
console.log(mockRedirectFn.mock);
// { calls: [], instances: [] }
});
Run Code Online (Sandbox Code Playgroud)
那就是我所拥有的,它不起作用。我该怎么做呢?
这是数据库模式:
以下是规则:
"notifications": {
"$year": {
".read": "false",
".write": "!data.exists()",
"$month": {
".read": "false",
".write": "!data.exists()",
"$day": {
".read": "false",
".write": "!data.exists()",
"$hour": {
".read": "false",
".write": "!data.exists()",
"$minute": {
".read": "false",
".write": "!data.exists()",
"$data": {
".read": "false",
".write": "!data.exists()"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何验证(使用".validate"或".write"规则)用户只能在该树中输入整数?或者有一些解决方法吗?
我想要实现的是创建只写(没有删除或更新)日志,该日志具有一些结构并将在以后处理.我可以将结构更改为2015-10-6-17-30之类的密钥或其他内容.我简直不敢相信Firebase没有针对这种情况的东西.
更新:这不重复,我正在寻找一种解决方法,或者其他能帮助我实现目标的东西.
我希望并行执行这三个Firebase请求,并在所有请求完成后接收回调.我以为我可以使用等待*,但似乎Babel不支持它.我并不担心数据的一致性,因为我正在编写/更新不同的firebase数据节点.
我正在使用巴贝尔.
await* Promise.all([
firebaseRef1.push(data1),
firebaseRef2.push(data2),
firebaseRef3.push(data3)
]);
// all three are finished
Run Code Online (Sandbox Code Playgroud)
最初是这样的:
const [first, second, third] = await* Promise.all([
firebaseRef1.push(data1),
firebaseRef2.push(data2),
firebaseRef3.push(data3)
]);
// all three are finished
Run Code Online (Sandbox Code Playgroud) 我在使用JQuery Ajax将数据发布到本地appengine应用程序时遇到问题.这是简化的客户端代码:
text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id + '&data=' + text_to_save;
$.post(req, function(data) {
$('.result').html(data);
});
Run Code Online (Sandbox Code Playgroud)
这是简化的服务器端代码:
class StoryEdit(webapp.RequestHandler):
def post(self):
f = Story.get(self.request.get('story_id'))
f.html = self.request.get('data')
f.put()
Run Code Online (Sandbox Code Playgroud)
错误是414(请求的URI太长).我究竟做错了什么?