使用此答案中的代码来解决组件外部的单击:
componentDidMount() {
document.addEventListener('mousedown', this.handleClickOutside);
}
componentWillUnmount() {
document.removeEventListener('mousedown', this.handleClickOutside);
}
setWrapperRef(node) {
this.wrapperRef = node;
}
handleClickOutside(event) {
if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
this.props.actions.something() // Eg. closes modal
}
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何对不愉快的路径进行单元测试以便警报不会运行,到目前为止我得到了什么:
it('Handles click outside of component', () => {
props = {
actions: {
something: jest.fn(),
}
}
const wrapper = mount(
<Component {... props} />,
)
expect(props.actions.something.mock.calls.length).toBe(0)
// Happy path should trigger mock
wrapper.instance().handleClick({
target: 'outside',
})
expect(props.actions.something.mock.calls.length).toBe(1) //true
// Unhappy path should not trigger mock …Run Code Online (Sandbox Code Playgroud) 我正在使用 aws lambdas、dynamodb 和 cognito 构建身份验证系统。
坚持比较 getOpenIdTokenForDeveloperIdentity() 提供的令牌;调用来自服务器的特定身份。
我正在通过以下方式获取令牌和身份:
function getToken(email, fn) {
var param = {
IdentityPoolId: cognitoIdentityPoolId,
Logins: {} // To have provider name in a variable
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getOpenIdTokenForDeveloperIdentity(param,
function(err, data) {
if (err) return fn(err); // an error occurred
else fn(null, data.IdentityId, data.Token); // successful response
});
}
Run Code Online (Sandbox Code Playgroud)
然后据我所知,我可以从 cognito 中获取已经生成的令牌(而不是创建一个新令牌),如下所示:
function checkToken(IdentityId, email, fn){
var param = {
IdentityPoolId: cognitoIdentityPoolId,
IdentityId: IdentityId,
Logins: {}
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getCredentialsForIdentity(param,
function(err, data) { …Run Code Online (Sandbox Code Playgroud) 我有一种简单的感觉,但是我有一个动作,如果满足条件,该动作将分派两个动作。
行动
export function changeDateRange({ startDate, endDate }) {
return function reload(dispatch, getState) {
if (!getState().navigation.focused) {
// If our datepicker has closed, reload the data on the page
dispatch(load());
}
dispatch({
type: types.CHANGE_DATE_RANGE,
startDate,
endDate
});
};
}
Run Code Online (Sandbox Code Playgroud)
然后我试图测试load()并用a对其进行了模拟,Jest.fn()但是当我mock.calls.length在分派后登录时是否changeDateRange()等于0?
设定
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
global.mockStore = configureMockStore([thunk]);
Run Code Online (Sandbox Code Playgroud)
测试:
import * as types from '../actionTypes';
import * as changeDateRange from './changeDateRange';
import { load } from '../reporting';
jest.mock('../reporting', …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的 React Native 应用程序:
关于我应该如何去做的任何想法?
我给出this了黑色的初始状态,但这似乎没有任何作用。
我想要发生的是在单击红色按钮时触发 makeRed,这将使文本变为红色。一旦我完成这项工作,我将添加更多颜色按钮。
谢谢!
请参阅下面的我的 App.js 代码。所有其他文件都保持默认状态。
import React, { Component } from 'react';
import {
AppRegistry,
Platform,
StyleSheet,
Text,
TextInput,
View,
Button
} from 'react-native';
export default class App extends Component<{}> {
constructor(props) {
super(props);
this.state = {
text: 'World',
color: 'black'
};
}
makeRed = () => {
this.setState({
color: 'red'
});
}
render() {
return (
<View style={styles.container}>
<Text style={[styles.welcome, {color: undefined}]}>
Hello, {this.state.text}!
</Text>
<TextInput …Run Code Online (Sandbox Code Playgroud) 好的,这将是一个有趣的...
几乎我似乎遇到了一个有趣的IE bug(特征),涉及当一个span在一个锚点内时,例如.
<a href='#'>
<span style="float:left;">Super cool link</span>
<span style="float:right;">10</span>
</a>
Run Code Online (Sandbox Code Playgroud)
在IE浏览器中,您似乎可以左键单击,但无法右键单击该项目并获取链接菜单,这个问题在Google的服务中似乎也是持久的,例如.

我想知道是否有人可以解释一下
到目前为止,我已经尝试 在锚点中添加一个并且摆弄z-index无济于事.
我能找到的唯一解决方案/解决方法是,如果您删除Doctype,问题似乎就会消失.(不会发生)
Ninja编辑 - 您似乎无法按CTRL +单击
好的另一个编辑:
看起来像display: block;跨度杀死它 - http://jsfiddle.net/vdfhz/4/
我正在尝试在 DynamoDB put 中执行 ConditionExpression 来检查存储的布尔值是否为 true(在本例中,用户是否已验证,请勿运行 put),我正在使用 javascript DocumentClient SDK(感谢 @shimon -tolts),代码如下:
var query = {
TableName: tableName,
Item: {
email: email,
verified: false,
verifyToken: token
},
ConditionExpression: 'attribute_exists(email) AND verified = :bool',
ExpressionAttributeValues: {
":bool":"false"
}
};
dynamodb.put(query, function(err, data){
if (err) return fn(err)
fn(null, data);
});
Run Code Online (Sandbox Code Playgroud)
这是行不通的,无论调用什么,它都无法通过条件检查。
几乎是我需要的(伪代码):
IF email already exists AND verified equals false
THEN allow PUT
IF email already exists AND verified equals true
THEN don't allow PUT
IF email does not exist
THEN …Run Code Online (Sandbox Code Playgroud) 正如标题一样,我似乎无法让它工作,我正在遵循此处详述的高级指南,但上传的任何图像似乎都是空白的。
我设置了什么:
/images/{object} - PUT
> Integration Request
AWS Region: ap-southeast-2
AWS Service: S3
AWS Subdomain [bucket name here]
HTTP method: PUT
Path override: /{object}
Execution Role [I have one set up]
> URL Path Paramaters
object -> method.request.path.object
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Postman 发送带有 Content-Type: image/png 的 PUT 请求,并且正文是 png 文件的二进制上传。
我也试过使用 curl:
curl -X PUT -H "Authorization: Bearer [token]" -H "Content-Type: image/gif" --upload-file ~/Pictures/bart.gif https://[api-url]/dev/images/cool.gif
Run Code Online (Sandbox Code Playgroud)
它在服务器上创建文件,大小似乎是上传的两倍,查看时我只是得到“图像有错误”。
当我尝试使用 .txt 文件(内容类型:文本/纯文本)时,它似乎可以工作。
有任何想法吗?
我正在尝试将keras模型转换为用于Google Cloud的ml-engine预测的模型。我有一个预先训练的分类器,将numpy数组作为输入。我发送给model.predict的正常工作数据称为input_data。
我将其转换为base 64,并json使用以下几行将其转储到文件中:
data = {}
data['image_bytes'] = [{'b64':base64.b64encode(input_data.tostring())}]
with open('weights/keras/example.json', 'w') as outfile:
json.dump(data, outfile)
Run Code Online (Sandbox Code Playgroud)
现在,我尝试从现有模型创建TF模型:
from keras.models import model_from_json
import tensorflow as tf
from keras import backend as K
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import utils
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import build_signature_def, predict_signature_def
init = tf.global_variables_initializer()
with tf.Session() as sess:
K.set_session(sess)
sess.run(init)
print("Keras model & weights loading...")
K.set_learning_phase(0)
with open(json_file_path, 'r') as file_handle:
model = …Run Code Online (Sandbox Code Playgroud) javascript ×3
jestjs ×2
reactjs ×2
unit-testing ×2
amazon-s3 ×1
anchor ×1
aws-lambda ×1
enzyme ×1
html ×1
keras ×1
react-native ×1
redux ×1
redux-thunk ×1
right-click ×1
tensorflow ×1