我正在使用redux-observable来触发两个动作。第一个动作是基于条件为真,第二个动作应该在500秒时使用去抖动触发。两个可观察量都可以并行运行,而不是相互依赖。
到目前为止,我想出了以下哪些不起作用。
export const updateContent = (content$, { getState }) => {
return content$.ofType(actionTypes.REQ_CHANGE_EDIT)
.flatMap(action =>
Observable.forkJoin(
Observable.if(() => isChanged(getState()),
Observable.of(({ type: actionTypes.CHANGE_EDIT, changed: true }))),
Observable.of({ type: actionTypes.CACHE_CONTENT, isCached: false }).debounceTime(500),
));
};
答案 0 :(得分:0)
尝试使用combineLatest而不是forkjoin并强制从.if operator
发出初始值var keystone = require('keystone'),
Types = keystone.Field.Types;
var Post = new keystone.List('Post', {
autokey: { path: 'slug', from: 'newKey', unique: true },
map: { name: 'newKey' },
defaultSort: '-createdAt'
});
Post.add({
newKey: { type: Types.Text, watch: true, noedit: true, value: function (callback) {
var author = this.author;
var title = this.title;
keystone.list('User').model.findOne({_id: this.author.toString()}).exec(function (err, u) {
if (err) {
callback(err, "unknown")
} else {
var r = "("+u.name.first+" "+u.name.last+")-"+title;
callback(null, r)
}
});
}},
title: { type: String, required: true, index: true, initial: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft' },
author: { type: Types.Relationship, ref: 'User', index: true, initial: true },
createdAt: { type: Date, default: Date.now },
publishedAt: Date,
image: { type: Types.CloudinaryImage },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 }
}
});
Post.defaultColumns = 'title, state|20%, author, publishedAt|15%'
Post.register();