我是redux和es6语法的新手.我使用官方的redux教程制作我的应用程序,并使用此示例.
下面有JS片段.我的观点 - 在帖子reducer中定义REQUEST_POST_BODY和RECEIVE_POST_BODY个案.主要难点 - 在商店中查找和更新正确的对象.
我尝试使用示例中的代码:
return Object.assign({}, state, {
[action.subreddit]: posts(state[action.subreddit], action)
})
Run Code Online (Sandbox Code Playgroud)
但它使用了简单的帖子.不需要通过id找到正确的帖子.
这是我的代码:
const initialState = {
items: [{id:3, title: '1984', isFetching:false}, {id:6, title: 'Mouse', isFetching:false}]
}
// Reducer for posts store
export default function posts(state = initialState, action) {
switch (action.type) {
case REQUEST_POST_BODY:
// here I need to set post.isFetching => true
case RECEIVE_POST_BODY:
// here I need to set post.isFetching => false and post.body => action.body
default:
return state;
}
} …Run Code Online (Sandbox Code Playgroud) 我需要像jquery.fullPage那样组织导航:当我滚动一次时 - 我转到下一部分.
我尝试使用jquery.mousewheel,但它在带有触摸板或触控板或APPLE Magic Mouse的MacOS中失败:它每个滚动滚动多个幻灯片.
我试图使用这个解决方案:https://github.com/jquery/jquery-mousewheel/issues/36#issuecomment-67648897
它在Chrome中运行良好,但它不在FF中并且在Safari中存在错误.
这是问题的简单演示:http: //jsfiddle.net/ss5LueLx/13/
$slider.on('mousewheel', function(event) {
if (event.deltaY>0) {
slider.prevSlide();
} else {
slider.nextSlide();
}
});
Run Code Online (Sandbox Code Playgroud) 该vinyl-ftp软件包有一个功能,clean()但我不知道如何正确使用它.我需要:
build文件夹中获取所有文件我有以下gulp任务:
gulp.task('deploy', () => {
let conn = ftp.create({host:host,user:user,password: password});
return gulp.src('build/**', {base: './build/', buffer: false })
.pipe(conn.newer('/path/on/my/server/')) // only upload newer files
.pipe(conn.dest('/path/on/my/server/'))
.pipe(conn.clean('build/**', './build/'));
});
Run Code Online (Sandbox Code Playgroud)
1)和2)是可以的,但clean()功能什么都不做
我试图通过限制内容未更改的组件的渲染调用次数来获取如何在React中管理复杂状态的方法。
例如:
我已经使用“ items”道具(即数组)简单地连接到redux存储容器组件。
const Component = ({ items }) => (
<>{items.map(item => <ItemComponent key={item.id} {...item} />}</>
);
const mapStateToProps = state => ({
items: $$data.select.items(state),
});
const ConnectedComponent = connect(mapStateToProps)(MyComponent);
Run Code Online (Sandbox Code Playgroud)
每当复杂存储区的任何部分发生更改时,即使道具数据没有更新,即使道具数据为空,道具属性也会更改:oldProp:[] => newProp:[]。并导致重新渲染。(我在React Dev Tools中找到了它,它突出显示了更新的组件)
我是否应该担心这种不必要的重新渲染?最好的解决方法是什么?我已经发现新的React.memo hoc可以停止重新渲染,但这是个好方法吗?
如何将任何字符串插入<script>console.log('it works');</script> 浏览器 DOM 中并在浏览器控制台中看到“它有效”?
jQuery 的附加函数做这件事:
$('html').append('<script>console.log('it works');
但我正在寻找轻量级的解决方案,最好是普通的 js
上下文:字符串可以很复杂,比如<div><h1>Title</h1></div><div><script>console.log('it works');</script></div>- 它应该在 DOM 中正确呈现并完成所有 JS 工作人员的工作
我目前正在研究基于 slatejs 的富文本编辑器。当图像聚焦时,我需要实现在图像后立即插入段落的可能性。现在当图像有焦点并且我按下Enter按钮时 - 什么也没发生。它应该在图像之后插入新的空段落。
示例中的相同行为https://www.slatejs.org/examples/images
任何帮助表示赞赏