我有一个结构简化的对象,如下所示:
state = {
todo: {
1: {text: 'Buy apples'},
2: {text: 'Buy milk'}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我想删除待办事项的不变性,根据 Stack Overflow 上的其他答案,我可以解构待办事项列表:
const idToDelete = 2
let {
[idToDelete]: deleted,
...newTodo
} = state.todo
Run Code Online (Sandbox Code Playgroud)
如果我这样做console.log(newTodo),那么它具有相同的值state.todo,这意味着它没有删除到 id 为 2 的待办事项。如果我 console.log(deleted)然后它返回我想删除的待办事项的内容:{text: 'Buy milk'}。
我知道使用诸如 Immutable.js 之类的库来管理它会更容易一些,但是我想知道为什么解构对象不会删除待办事项项。谢谢。
我有一个关于CSS选择器如何在父级和子级之间工作的问题,以及哪一个优先于另一个.
<div class="red">
<div class="blue">
<div class="green">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果你那么的话
.red .green{
border: 1px solid red;
}
.blue .green{
border: 1px solid blue;
}
Run Code Online (Sandbox Code Playgroud)
哪一个会生效?要覆盖CSS样式,它必须与您尝试覆盖的那个特定的选择器一样吗?
我只是想探索异步/等待.当我调用该函数时,我在控制台中得到了这个:
Promise { <state>: "pending" }
Run Code Online (Sandbox Code Playgroud)
这是我的webpack.conf.js:
var path = require("path");
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
module.exports = {
devtool: 'eval',
entry: [
'babel-regenerator-runtime',
'./static/apps/app.jsx'
],
output : {
path: __dirname,
filename: "./static/js/bundles/[name]-[hash].js"
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
plugins: [ 'transform-decorators-legacy', 'syntax-async-functions', 'transform-async-to-generator'],
presets: ['react', 'es2015', 'stage-0']
}
}
]
},
plugins: process.env.NODE_ENV === 'production' ? [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: …Run Code Online (Sandbox Code Playgroud) Flux<Integer> shared = Flux.just(1, 2).share();
shared.subscribe(System.out::println);
shared.subscribe(System.out::println);
Run Code Online (Sandbox Code Playgroud)
由于share()将通量变成热通量,我希望第一个订阅者获得所有值,而第二个订阅者则得不到任何值,因为流在订阅时已完成。share但输出与没有:相同1 2 1 2,但它应该只是1 2.
当我替换share()它时publish.autoconnect(),它会按预期工作。这是为什么?
我一直在Spring Security + Webflux中使用ReactiveAuthenticationManager。它是经过自定义的,以返回一个实例UsernamePasswordAuthenticationToken,从该实例中我可以看出是调用时应接收的内容ReactiveSecurityContextHolder.getContext().map(ctx -> ctx.getAuthentication()).block()。据我所知,我无法通过两种方式访问身份验证上下文:
SecurityContextHolder.getContext().getAuthentication();
Run Code Online (Sandbox Code Playgroud)
要么
ReactiveSecurityContextHolder.getContext().map(ctx -> ctx.getAuthentication()).block()
Run Code Online (Sandbox Code Playgroud)
尝试从控制器或组件访问这些文件将解决null。对于我是否真的要Authentication在自定义管理器中返回实例,我有些怀疑,好像我是:
@Override
public Mono<Authentication> authenticate(final Authentication authentication) {
if (authentication instanceof PreAuthentication) {
return Mono.just(authentication)
.publishOn(Schedulers.parallel())
.switchIfEmpty(Mono.defer(this::throwCredentialError))
.cast(PreAuthentication.class)
.flatMap(this::authenticatePayload)
.publishOn(Schedulers.parallel())
.onErrorResume(e -> throwCredentialError())
.map(userDetails -> new AuthenticationToken(userDetails, userDetails.getAuthorities()));
}
return Mono.empty();
}
Run Code Online (Sandbox Code Playgroud)
和PreAuthentication的实例在哪里扩展AbstractAuthenticationTokenAuthenticationTokenUsernamePasswordAuthenticationToken
有趣的是,尽管ReactiveSecurityContextHolder.getContext().map(ctx -> ctx.getAuthentication()).block()在控制器中不起作用,但我可以@AuthenticationPrincipal在控制器中成功地将带有注释的身份验证主体作为方法参数注入。
这似乎是一个配置问题,但我不知道在哪里。有人知道为什么我不能返回身份验证吗?