示例代码:https://github.com/d6u/example-redux-update-nested-props/blob/master/one-connect/index.js
观看现场演示:http://d6u.github.io/example-redux-update-nested-props/one-connect.html
我有上面的组件,Repo和RepoList.我想更新第一个仓库的标签(第14行).所以我发出了一个UPDATE_TAG
动作.在我实施之前shouldComponentUpdate
,调度大约需要200毫秒,这是预料之中的,因为我们浪费了很多时间<Repo/>
来分析没有改变的东西.
添加后shouldComponentUpdate
,调度大约需要30ms.在生产构建React.js之后,更新仅花费大约17ms.这要好得多,但Chrome开发者控制台中的时间线视图仍然表示jank帧(超过16.6ms).
想象一下,如果我们有这样的许多更新,或者<Repo/>
比当前更新更复杂,我们将无法维持60fps.
我的问题是,对于嵌套组件的道具的这种小更新,是否有更高效和规范的方式来更新内容?我还可以使用Redux吗?
我通过用tags
可观察的内部减速器替换每一个来获得解决方案.就像是
// inside reducer when handling UPDATE_TAG action
// repos[0].tags of state is already replaced with a Rx.BehaviorSubject
get('repos[0].tags', state).onNext([{
id: 213,
text: 'Node.js'
}]);
Run Code Online (Sandbox Code Playgroud)
然后我使用https://github.com/jayphelps/react-observable-subscribe在Repo组件中订阅它们的值.这很有效.即使使用React.js的开发构建,每个调度仅花费5ms.但我觉得这是Redux中的反模式.
我按照Dan Abramov的回答中的建议,将我的状态和更新的连接组件规范化
新的状态形状是:
{
repoIds: ['1', '2', '3', ...],
reposById: {
'1': {...},
'2': {...}
}
}
Run Code Online (Sandbox Code Playgroud)
我加了console.time
各地 …
最近我启用了Amazon S3 + CloudFront作为我的rails应用程序的CDN.为了使用字体资源并在Firefox或IE中显示它们,我必须在我的S3存储桶上启用CORS.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
然后我用了curl -I https://small-read-staging-assets.s3.amazonaws.com/staging/assets/settings_settings-312b7230872a71a534812e770ec299bb.js.gz
,我得到了:
HTTP/1.1 200 OK
x-amz-id-2: Ovs0D578kzW1J72ej0duCi17lnw+wZryGeTw722V2XOteXOC4RoThU8t+NcXksCb
x-amz-request-id: 52E934392E32679A
Date: Tue, 04 Jun 2013 02:34:50 GMT
Cache-Control: public, max-age=31557600
Content-Encoding: gzip
Expires: Wed, 04 Jun 2014 08:16:26 GMT
Last-Modified: Tue, 04 Jun 2013 02:16:26 GMT
ETag: "723791e0c993b691c442970e9718d001"
Accept-Ranges: bytes
Content-Type: text/javascript
Content-Length: 39140
Server: AmazonS3
Run Code Online (Sandbox Code Playgroud)
我应该看看'Access-Control-Allow-Origin'
哪里?S3是否需要时间来更新CORS设置?如果缓存它们,我可以强制过期标头吗?
amazon-s3 font-face cors amazon-cloudfront ruby-on-rails-3.2
我试图在我的iPhone上运行我的iOS应用程序.项目编译得很好.但是当应用程序启动时,XCode控制台显示:
dyld: Library not loaded: @rpath/Runes.framework/Runes
Referenced from: /private/var/mobile/Containers/Bundle/Application/CC8759F5-A501-400C-93A8-DCEE3BFE4770/XXX.app/XXX
Reason: Incompatible library version: XXX requires version 2.0.0 or later, but Runes provides version 1.0.0
Run Code Online (Sandbox Code Playgroud)
我使用Cocoapods,我的Podfile看起来像:
platform :ios, '8.0'
use_frameworks!
pod 'SnapKit', '~> 0.12.0'
pod 'Alamofire', '~> 1.2'
pod 'SwiftTask', '~> 3.3'
pod 'Argo'
pod 'Async', :git => 'https://github.com/duemunk/Async.git', :commit => '9e64046b767fe11010891f5b7fe2aed613a6ee55'
pod 'TapLabel', '0.0.3'
pod 'RealmSwift'
pod 'Kingfisher', '~> 1.4'
Run Code Online (Sandbox Code Playgroud)
我该怎么办?在模拟器上一切正常.
我有一个服务,我从服务器拉数据.当我单击按钮通过此服务向服务器发送请求时,窗口会冻结,直到我收到服务器的响应.有什么办法可以让这个请求异步吗?
这是我的服务.
app.factory('service', function($http) {
return {
getLogData : function(startTime,endTime){
return $http({
url: baseURL + 'getLogData',
method: 'GET',
async: true,
cache: false,
headers: {'Accept': 'application/json', 'Pragma': 'no-cache'},
params: {'startTime': startTime , 'endTime': endTime}
});
}
};
)};
Run Code Online (Sandbox Code Playgroud)
HTML.
<button ng-click="getData()">Refresh</button>
<img src="pending.gif" ng-show="dataPending" />
Run Code Online (Sandbox Code Playgroud)
码
$scope.getData = function(){
service.getLogData().success(function(data){
//process data
}).error(function(e){
//show error message
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用ng-animate来滑动应用程序视图,因此每条路径都会自己滑动视图,这是我的简单代码:
HTML:
<div ng-view ng-animate class="slide"></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
/*Animations*/
.slide{
left:0;
}
.slide.ng-enter{
transition:0.15s linear all;
position:fixed;
z-index:inherit;
left:-100%;
height:inherit;
}
.slide.ng-leave{
transition:0.15s linear all;
position:fixed;
z-index:9999;
right:0;
}
.slide.ng-leave-active{
transition:0.15s linear all;
position:fixed;
right:-100%;
left:100%;
}
.slide.ng-enter-active{
transition:0.15s linear all;
left:0;
position:relative;
}
Run Code Online (Sandbox Code Playgroud)
现在,我想知道, is there anyway to exclude the home page (main "/" route) from sliding?
换句话说:任何从ng-animate中排除路线的方法?
我在Swift 1.2中工作时发现了这一点.我把它报告为一个bug.但不知道为什么?
import UIKit
var str = " LHR ?? SFO "
([str] as NSArray).componentsJoinedByString("") // Will work
join("", [str]) // Hangs forever
Run Code Online (Sandbox Code Playgroud) 在ESLint 1中,我可以使用该ecmaFeatures
选项来禁用或启用某些语言功能.例如
ecmaFeatures:
defaultParams: false
Run Code Online (Sandbox Code Playgroud)
以上配置禁用defaultParams
.
这非常有用,因为在运行时像Node一样,并非所有功能都可用,而且我不想使用转换器.
但在ESLint 2中,已被删除.你只有ecmaVersion
,即使你给它一个ecmaVersion
5 ,也没有提醒ES2015功能的使用.我想这是有意义的,因为JavaScript解释器会抱怨在解释时使用不支持的语法,但是开发怎么样?对于浏览器有不同级别的ES2015支持?适用于Chrome的语法不适用于IE9.
有没有办法搞定语言功能的使用,例如禁用解构?
很长一段时间我一直在使用一个非常好的列跨越方法我偶然发现,其中我可以有一个带有类.boxcontainer
和子.box
元素的div ,并使用一个:after
伪元素.boxcontainer
,我的.box
列在页面上对齐很好.以下是最重要的定义:
.boxcontainer {
text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
background-color: orange;
}
.boxcontainer:after {
content: '';
display: inline-block;
width: 100%;
height: 0px;
font-size: 0px;
line-height: 0px;
}
Run Code Online (Sandbox Code Playgroud)
我之前的大多数项目都是XHTML1 Transitional(我后来学到了与其他DTD相比使用了有限的怪癖模式),并且在XHTML1中使用这种方法,父对象.boxcontainer
总是完全包裹在子.box
元素周围.
但是,在HTML5中处理一个新项目时,我发现在对齐.box
元素下面似乎添加了一条额外的行.你可以在这里看到一个例子:http://jsfiddle.net/RZQTM/1/ - 点击小提琴选项并将DTD更改为其他任何内容,你会看到我的意思 - 一个橙色的'乐队'出现在合理的蓝盒子.
我认为这归结为:after
伪元素的呈现几乎就像是一个额外的内容,但我不知道如何解决它.任何有关如何移除框下额外空间的提示都将非常感激.