我使用React Router为我的React.js应用程序提供了以下结构:
var Dashboard = require('./Dashboard');
var Comments = require('./Comments');
var Index = React.createClass({
render: function () {
return (
<div>
<header>Some header</header>
<RouteHandler />
</div>
);
}
});
var routes = (
<Route path="/" handler={Index}>
<Route path="comments" handler={Comments}/>
<DefaultRoute handler={Dashboard}/>
</Route>
);
ReactRouter.run(routes, function (Handler) {
React.render(<Handler/>, document.body);
});
Run Code Online (Sandbox Code Playgroud)
我想将一些属性传递给Comments组件.
(通常我会这样做<Comments myprop="value" />)
使用React Router,最简单,最正确的方法是什么?
我一直在我的mac os x 10.8上使用mongo,突然昨天在我的日志中出现了这个警告(当启动shell时它也存在) -
警告:软限制太低.文件数为256,应至少为1000
谁能解释一下,这是什么意思?我应该以某种方式增加rlimits的数量吗?
我正在探索React Native的可能性,同时在Navigator组件的帮助下开发一个在视图之间自定义导航的演示应用程序- http://facebook.github.io/react-native/docs/navigator.html#content
主app类渲染navigator和inside Navigator返回传递的组件:
class App extends React.Component {
render() {
return (
<Navigator
initialRoute={{name: 'WelcomeView', component: WelcomeView}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
// count the number of func calls
console.log(route, navigator);
if (route.component) {
return React.createElement(route.component, { navigator });
}
}}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
现在app包含2个视图:
class FeedView extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>
Feed View!
</Text>
</View>
);
}
}
class WelcomeView extends …Run Code Online (Sandbox Code Playgroud) 主要问题 - 有可能吗?我试着没有运气..
主app.js
...
var app = angular.module('myApp', ['services']);
app.config(['customProvider', function (customProvider) {
}]);
...
Run Code Online (Sandbox Code Playgroud)
提供者本身
var services = angular.module('services', []);
services.provider('custom', function ($http) {
});
Run Code Online (Sandbox Code Playgroud)
我有这样的错误:
Uncaught Error: Unknown provider: $http from services
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢!
此代码适用于第一个XCode 6 Beta,但在最新的Beta版本中,它无法正常运行并出现此类错误Must call a designated initializer of the superclass SKSpriteNode:
import SpriteKit
class Creature: SKSpriteNode {
var isAlive:Bool = false {
didSet {
self.hidden = !isAlive
}
}
var livingNeighbours:Int = 0
init() {
// throws: must call a designated initializer of the superclass SKSpriteNode
super.init(imageNamed:"bubble")
self.hidden = true
}
init(texture: SKTexture!) {
// throws: must call a designated initializer of the superclass SKSpriteNode
super.init(texture: texture)
}
init(texture: SKTexture!, color: UIColor!, size: CGSize) {
super.init(texture: texture, color: …Run Code Online (Sandbox Code Playgroud) 我只想弄清楚我的应用程序有什么好处:
使用.jsx扩展,但我需要在require函数中要求具有显式扩展名的组件require('MyComponent.jsx');
使用.js扩展,这很好,require('MyComponent);但我需要破解Sublime正确lint它们并突出显示语法.
你有什么经历?
我认为这可能只是性能案例 - http://jsperf.com/comparing-underscore-js-isfunction-with-typeof-function/2
而且似乎typeof更快..所以我的问题是 - 哪个更适合使用?
我正在学习Swift语言,但是我无法将可选的回调参数传递给函数:
func dismiss(completion: () -> Void) {
if (completion) {
return self.dismissViewControllerAnimated(true, completion: completion)
}
self.dismissModalViewControllerAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)
这显示了一个错误 - Type () -> Void does not conform to protocol 'LogicValue'
有什么建议?
我在客户端用Babel编译器在ES6中编写了同构应用程序.我希望我的快速服务器具有与客户端代码相同的ES6语法.
不幸的是require('babel/register')不起作用..
require('babel/register'); // doesn't work
// require('babel-core/register); doesn't work..
const env = process.env.NODE_ENV || 'development';
const port = process.env.NODE_PORT || 1995;
const http = require('http');
const express = require('express');
const address = require('network-address');
let app = express();
app.set('port', port);
app.use(express.static(path.join(__dirname, 'public')));
app.get('*', (req, res) => {
res.send('Hello!');
});
http.createServer(app).listen(app.get('port'), function () {
console.info('Demo app is listening on "%s:%s" env="%s"', address(), app.get('port'), env);
});
Run Code Online (Sandbox Code Playgroud) 我正在玩新的MVVM框架 - Vue.js(http://vuejs.org/).
这在简单的示例和演示中非常好,但现在我正在尝试使用多个视图创建大型SPA,并且我意识到框架的文档中没有描述如何执行它的最佳模式.
主要问题是我不知道如何处理不同路径上的视图.
例如,我使用Director(https://github.com/flatiron/director)进行路由,但是如何更改视图?
var booksCtrl = function () {
var booksViewModel = new Vue({
el: '#books'
data: { ... }
ready: function () {
// hide previous ViewModel and display this one??
}
});
};
var editBookCtrl = function (id) {
var editBookViewModel = new Vue({
el: '#editBook'
data: { ... }
ready: function () {
// hide previous ViewModel and display this one??
}
});
};
var routes = …Run Code Online (Sandbox Code Playgroud) javascript ×7
reactjs ×3
ios ×2
swift ×2
angularjs ×1
babeljs ×1
callback ×1
ecmascript-6 ×1
express ×1
function ×1
limits ×1
macos ×1
mongodb ×1
navigation ×1
node.js ×1
performance ×1
properties ×1
react-native ×1
react-router ×1
router ×1
skspritenode ×1
sprite-kit ×1
typeof ×1
viewmodel ×1
vue.js ×1