【发布时间】:2016-07-30 20:58:22
【问题描述】:
您好,我正在尝试编写依赖于其他作曲家函数提供的道具的作曲家函数。
这个提供道具叫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});
}
};
这个取决于名为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);
但是当我使用依赖于 A 的 composerB 组合它时,它会永远加载/等待。
export const ThisLoadsForever = composeAll(
composeWithTracker(composerA),
composeWithTracker(composerB)
)(Component);
我也试过这样做
export const temp = composeAll(
composeWithTracker(composerA)
)(Component);
export const StillLoadsForever = composeAll(
composeWithTracker(composerB)
)(temp);
我怀疑道具a 永远不会对composerB 可用或不为空,因此永远等待/加载。
我该如何解决?还是有其他方法可以组成具有依赖性的作曲家?
PS:我正在使用 mantra-js。
【问题讨论】:
标签: meteor reactjs ecmascript-6