我刚刚在React Native中构建了一个相对复杂的图像编辑UI.
该体验旨在与Instagram非常相似,并具有双指缩放,平移和旋转功能.
转换存储为数据,例如:
transformation: {
bottomBoundary: 1989,
leftBoundary: 410,
rightBoundary: 1634,
topBoundary: 765,
rotation: 0,
},
Run Code Online (Sandbox Code Playgroud)
其中topBoundary和bottomBoundary都是偏离图像顶部的偏移,leftBoundary并且rightBoundary都是图像左侧的偏移.
旋转时,因为React Native使用对象的中心作为变换原点,所以当处于90°或270°方向时,图像需要偏移,这样它们仍然可以"粘"到顶部/左角并且可以偏移:
calculateRotationOffset.js
export default function (width, height) {
const transform = [
{ rotate: `${this.rotation}deg` },
]
/*
RN rotates around centre point, so we need to
manually offset the rotation to stick the image
to the top left corner so that our offsets will
work.
*/
if (this.rotation === 90) {
transform.push( …Run Code Online (Sandbox Code Playgroud) 所以我有两个数组:
const allLanguages = [ 'ES', 'EN', 'DE' ]
const usedLanguages = [ { id: 1, lang: 'EN' } ]
Run Code Online (Sandbox Code Playgroud)
生成新阵列的最快方法是什么,这两者是不同的?在旧式JavaScript中,你必须在另一个for循环中进行for循环,我认为......
例如:
const availableLanguages = [ 'ES', 'DE' ]
Run Code Online (Sandbox Code Playgroud) 所以我使用的是带有ApiClient助手的react-redux样板.它看起来像这样:
export default class ApiClient {
constructor(req) {
/* eslint-disable no-return-assign */
methods.forEach((method) =>
this[method] = (path, withCredentials, { params, data } = {}) => new Promise((resolve, reject) => {
const request = superagent[method](formatUrl(path))
if (withCredentials) {
console.log('first of all, its true')
console.log(this)
}
if (params) {
request.query(params)
}
if (__SERVER__ && req.get('cookie')) {
request.set('cookie', req.get('cookie'))
}
if (data) {
request.send(data)
}
request.end((err, { body } = {}) => {
return err ? reject(body || err) : resolve(body)
})
})) …Run Code Online (Sandbox Code Playgroud) 我正在通过 Jest 和 supertest 为新 API 编写大量测试。在运行测试之前,我正在设置一个测试数据库并用用户填充它:
jest --forceExit --config src/utils/testing/jest.config.js
Run Code Online (Sandbox Code Playgroud)
module.exports = {
rootDir: process.cwd(),
// Sets up testing database with users
globalSetup: './src/utils/testing/jest.setup.js',
// Ensures connection to database for all test suites
setupTestFrameworkScriptFile: './src/utils/testing/jest.db.js',
}
Run Code Online (Sandbox Code Playgroud)
所以我从一些用户的数据库开始进行测试。问题是这样的:
我的一些测试依赖于其他测试的成功。在这个应用程序中,用户可以上传图像,并将它们分组。所以我的分组端点套件取决于我的图像上传套件的成功,等等。
我很清楚很多人可能会说这是不好的做法,并且测试不应该依赖于其他测试。话虽如此,我真的宁愿通过以下方式保留所有测试supertest,而不是进入依赖注入等。我不想精心设置测试条件(例如,在运行之前人为地创建一堆用户图像)测试),因为:(1)这只是逻辑的重复,并且(2)它增加了某些破坏的可能性。
有什么办法可以将 Jest Suite 分组吗?例如,要按顺序运行套件:
jest run creationSuite
jest run modificationSuite
Run Code Online (Sandbox Code Playgroud)
这样,我所有的“creationSuite”测试都可以同时运行,并且所有测试的成功都会触发“modificationSuite”以快速失败的方式运行等。
或者,在测试套件内部指定对其他测试套件的依赖会很棒:
describe('Grouping endpoint', () => {
// Somehow define dependencies
this.dependsOn(uploadSuite)
Run Code Online (Sandbox Code Playgroud) 我有兴趣使用Cesium来构建带有自定义磁贴的3D地球,但是根据这里的"入门"说明,似乎你必须下载一个巨大的30mb目录并在你的项目中包含整个东西才能拥有它运行正常.这是真的?我可以不只是包含Cesium.js并像这样运行吗?我不需要它们包含80%的UI元素.
在"入门"教程结束时,它们似乎表明您需要运行的所有内容都是这些位:
<script src="Cesium/Cesium.js"></script>
@import url(Cesium/Widgets/widgets.css);
<div id="cesiumContainer"></div>
var viewer = new Cesium.CesiumViewer('cesiumContainer');
Run Code Online (Sandbox Code Playgroud)
但是当我设置这些位时,我得到这个错误:"未定义定义"和"未定义铯".
运行Cesium最轻的方法是什么?
我正在使用Pikaday,它需要Moment.js格式化日期.这允许简单的日期格式:
var picker = new Pikaday({
format: 'YYYY-MM-DD'
});
Run Code Online (Sandbox Code Playgroud)
但是,当我加入Pikaday npm包时,Moment.js 超过40kb.我需要它的所有内容都是将日期格式更改YYYY-MM-DD为几乎无法使用的默认Pikaday格式.
我是否可以在不包含40kb库的情况下完成此操作?
我有一个名为"list.json"的文件设置如下:
{
"thing1": "Thing1",
"thing2": "Thing2",
"thing3": "Thing3"
}
Run Code Online (Sandbox Code Playgroud)
我怎么能循环呢?我想做的事情如下:
{% for item in list%}
<option>{{ thing }}</option>
{% endfor %}
Run Code Online (Sandbox Code Playgroud) 我设置了一个Facebook登录,和我成功地把事情一样first_name,email等等.但是,我似乎无法弄清楚如何获得的生日.如果我打电话给birthday下面,没有任何回报.
FB.api('/me', {fields: 'birthday'}, function(response) {
console.log(JSON.stringify(response));
})
Run Code Online (Sandbox Code Playgroud)
如果我打电话user_birthday如下,我收到此错误:"error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)
FB.api('/me', {fields: 'user_birthday'}, function(response) {
console.log(JSON.stringify(response));
})
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
所以我有一个带位置输入的搜索页面.如果用户来自带有搜索查询的其他页面,我想以编程方式将此查询输入到输入中并触发更改的位置.
这是我到目前为止所拥有的:
var searchBox = new google.maps.places.SearchBox(input);
$('input#location').val(searchQuery);
google.maps.event.trigger(searchBox, 'places_changed');
Run Code Online (Sandbox Code Playgroud)
但是,这给了我Cannot read property 'length' of undefined这行places_changed函数的错误:
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
Run Code Online (Sandbox Code Playgroud)
因此,在以编程方式填充输入时,可以清楚地searchBox返回.我怎么能绕过这个?undefinedgetPlaces()
更新: 这是一个JSFiddle来举例说明我的意思.
所以我有一个auth相关的reducer设置如下:
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case LOAD:
return {
...state,
loading: true,
}
case LOAD_SUCCESS:
return {
...state,
loading: false,
loaded: true,
jwt: action.jwt,
}
case LOAD_FAIL:
return {
...state,
loading: false,
loaded: false,
error: true,
errorMessage: action.error,
}
case LOGIN:
return {
...state,
loaded: false,
loggingIn: true,
}
case LOGIN_SUCCESS:
return {
...state,
loaded: true,
loggingIn: false,
jwt: jwtDecode(action.result.token),
}
case LOGIN_FAIL:
return {
...state,
loggingIn: false,
user: …Run Code Online (Sandbox Code Playgroud) javascript ×8
ecmascript-6 ×3
reactjs ×3
react-redux ×2
redux ×2
api ×1
arrays ×1
cesium ×1
date ×1
facebook ×1
flux ×1
geometry ×1
google-maps ×1
jestjs ×1
jquery ×1
json ×1
math ×1
nunjucks ×1
pikaday ×1
react-native ×1
react-router ×1
supertest ×1
testing ×1