Meteor react komposer,依赖于其他编写器函数提供的prop的编写器函数
您好,我正在尝试编写依赖于其他编写器函数提供的道具的编写器函数 这个提供了名为Meteor react komposer,依赖于其他编写器函数提供的prop的编写器函数,meteor,reactjs,ecmascript-6,Meteor,Reactjs,Ecmascript 6,您好,我正在尝试编写依赖于其他编写器函数提供的道具的编写器函数 这个提供了名为a的道具 import {useDeps, composeWithTracker, composeAll} from 'mantra-core'; import Component from '../components/component'; export const composerA = ({context, _id}, onData) => { const {Meteor,Collections}
a
的道具
import {useDeps, composeWithTracker, composeAll} from 'mantra-core';
import Component from '../components/component';
export const composerA = ({context, _id}, onData) => {
const {Meteor,Collections} = context();
const query = {_id};
if (Meteor.subscribe('a', query).ready()) {
const a = Collections.A.findOne(query);
onData(null,{a});
}
};
// depends on `prop` named `a` which is provided by `composerA`
export const composerB = ({context, a}, onData) => {
const {Meteor,Collections} = contex();
if(a){
const query = {a_id : a._id};
if (Meteor.subscribe('b', query).ready()) {
const bs = Collections.B.find(query);
onData(null,{bs});
}
}
};
这个依赖于名为a
的道具
import {useDeps, composeWithTracker, composeAll} from 'mantra-core';
import Component from '../components/component';
export const composerA = ({context, _id}, onData) => {
const {Meteor,Collections} = context();
const query = {_id};
if (Meteor.subscribe('a', query).ready()) {
const a = Collections.A.findOne(query);
onData(null,{a});
}
};
// depends on `prop` named `a` which is provided by `composerA`
export const composerB = ({context, a}, onData) => {
const {Meteor,Collections} = contex();
if(a){
const query = {a_id : a._id};
if (Meteor.subscribe('b', query).ready()) {
const bs = Collections.B.find(query);
onData(null,{bs});
}
}
};
当没有依赖关系时,它可以正常工作
export const ThisWorks = compoaseAll(
composeWithTracker(composerA),
// some other composer function without dependency
composeWithTracker(composerWithoutDependency)
)(Component);
但当我用Composer B创作它时,它将永远加载/等待
export const ThisLoadsForever = composeAll(
composeWithTracker(composerA),
composeWithTracker(composerB)
)(Component);
我也试过这样做
export const temp = composeAll(
composeWithTracker(composerA)
)(Component);
export const StillLoadsForever = composeAll(
composeWithTracker(composerB)
)(temp);
我怀疑propa
对composerB
永远不可用或不为空,因此永远等待/加载。
我该如何解决这个问题?或者有没有其他方法来编写具有依赖性的作曲家
PS:我正在使用MantraJS。
composeAll
从右到左组合函数。如果您依赖componentB中componentA的道具,则需要将componentB置于componentA之上:
export const thisloadsforver=composell(
composeWithTracker(作曲家B),
composeWithTracker(作曲家A)
)(构成部分);
composell
从右到左组合函数。如果您依赖componentB中componentA的道具,则需要将componentB置于componentA之上:
export const thisloadsforver=composell(
composeWithTracker(作曲家B),
composeWithTracker(作曲家A)
)(构成部分);