假设我有一个这样的嵌套结构:
(def board [[:x :e :e]
[:o :x :e]
[:o :e :x]])
Run Code Online (Sandbox Code Playgroud)
为什么这段代码将它转换为90%
(apply map vector board)
Run Code Online (Sandbox Code Playgroud) 我正在使用clojurescript 0.0-2371,我正在尝试编写一些克隆对象的代码.我有这个代码,我想克隆一个节点并调用一个clone-object函数:
(def animate
(js/React.createClass
#js
{:getInitialState
(fn []
(this-as this
{:children
(->
(.. this -props -children)
(js/React.Children.map (fn [child] child))
(js->clj :keywordize-keys false))}))
:render
(fn []
(this-as this
(let [children (:children (.. this -state))]
(doseq [[k v] children]
(clone-object (aget children k))))))}))
Run Code Online (Sandbox Code Playgroud)
clone-object 看起来像这样:
(defn clone-object [obj]
(log/debug obj)
(doseq [[k v] obj]
(log/debug k)))
Run Code Online (Sandbox Code Playgroud)
如果我这样打电话clone-object:
(doseq [[k v] children]
(clone-object v))
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
未捕获的错误:[object Object]不是ISeqable
我正在尝试将操作添加到Ember 1.10中的Ember.Service但是我必须_actions使用actions哈希的别名来使其工作,我错过了什么?
export default Ember.Service.extend(Ember.ActionHandler, {
actions:{
addItem: function(label) {
console.log(label);
}
},
setup: Ember.on('init', function(){
this._actions = this.actions;
})
});
Run Code Online (Sandbox Code Playgroud)
查看ember源,该triggerEvent方法查询_actions哈希:
if (handler._actions && handler._actions[name]) {
if (handler._actions[name].apply(handler, args) === true) {
eventWasHandled = true;
} else {
return;
}
}
Run Code Online (Sandbox Code Playgroud)
我想我错过了什么.
我想在电子邮件中提供跟踪图像。
该电子邮件将调用将返回图像的 sinatra 路由。
在 Rails 中,我会这样做:
send_data Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), type: "image/gif", disposition: "inline"
Run Code Online (Sandbox Code Playgroud)
我将如何在 sinatra 中做到这一点?
我在 d3 中绘制了 x 轴和 y 轴。
var margin = {top: 20, right: 100, bottom: 30, left: 100},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var xScale = d3.scale.linear()
.domain([0, 15])
.range([0, width]);
var yScale = d3.scale.linear()
.domain([0, 38])
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.innerTickSize(-height)
.outerTickSize(0)
.tickPadding(10);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.innerTickSize(-width)
.outerTickSize(0)
.tickPadding(10);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top …Run Code Online (Sandbox Code Playgroud) 有人可以解释一下转换和翻译在做什么:
d3.transform(d3.select(tick[0]).attr('transform')).translate[1];
Run Code Online (Sandbox Code Playgroud)
上面的勾选来自xaxis,其值可能是translate(0,280).
所以我可以看到我正在挑选翻译函数的第二个值,但为什么我需要将所有这些包装起来d3.transform呢?
我在init.el中有像这样的exec-path-from-shell
(exec-path-from-shell-initialize)
Run Code Online (Sandbox Code Playgroud)
每当我启动emacs时,都会收到以下消息:
您似乎在.bashrc或.zshrc中设置环境变量(“ PATH”“ MANPATH”):这些文件仅由交互式shell读取,因此您应在.profile,.bash_profile或.start等启动文件中设置环境变量。 hen 有关更多信息,请参考外壳的手册页。自定义“ exec-path-from-shell-arguments”以在完成后删除“ -i”,或禁用“ exec-path-from-shell-check-startup-files”以禁用此消息。有关GNU Emacs和GNU系统的信息,请键入ChCa。
我想要一个index.js来定义我的所有反应组件,如下所示:
import App from './app';
import Home from './home';
export App;
export Home;
Run Code Online (Sandbox Code Playgroud)
然后我在另一个文件中引用它们:
import { App, Home } from './components/index';
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
</Route>
</Router>
</Provider>,
document.getElementById('theContent')
);
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Module build failed: SyntaxError: /Users/paulcowan/projects/liverpool-managers/client/app/components/index.js: Unexpected token (4:10)
2 | import Home from './home';
3 |
> 4 | export App;
| ^
Run Code Online (Sandbox Code Playgroud) 假设我有一个名为 Forecast 的顶级最智能组件,如下所示:
function mapStateToProps(state) {
return {
dates: state.getIn(['forecast', 'dates']),
isFetching: state.getIn(['forecast', 'isFetching'])
};
}
export default connect(mapStateToProps, {
fetchForecast
})(Forecast));
Run Code Online (Sandbox Code Playgroud)
它包装了一个像这样的 Forecast 组件:
import { getSummary, getDayForecast } from '../selectors/selectors';
export default class Forecast extends Component {
render() {
const { dates, isFetching } = this.props;
return (
<div className="row">
{dates.map(date => (
<Weather
key={date}
date={date}
getSummary={getSummary}
getDayForecast={getDayForecast}
/>
))}
</div>
);
}
};
Run Code Online (Sandbox Code Playgroud)
在这里,我将 2 个选择器作为道具传递给一个Weather组件。选择器如下所示:
import { createSelector } from 'reselect';
import moment from …Run Code Online (Sandbox Code Playgroud) 我很好奇mobx如何在幕后工作.
如果我有一个既是观察者又包含observables的组件:
@observer
export default class Form extends Component {
@observable submitted = false;
@action.bound
submit() {
}
}
Run Code Online (Sandbox Code Playgroud)
mobx如何在不使用setState的情况下重新渲染,还是使用setState?