简体   繁体   English

Netflix Falcor - 何时从数据源返回 pathValues 与 jsonGraph?

[英]Netflix Falcor - When to return pathValues versus jsonGraph from the data source?

In implementing a Falcor data source I am confused as to why sometimes you may return collections of path values:在实现 Falcor 数据源时,我很困惑为什么有时您可能会返回路径值的集合:

[{path, value}, {path, value}]

And sometimes you must supply the return value as a jsonGraph envelope:有时您必须将返回值作为 jsonGraph 信封提供:

{jsonGraph: {something: {here: value}}}

I understand how the entire framework works within the context of jsonGraph, but sometimes collections of path values just work, and sometimes they don't.我了解整个框架如何在 jsonGraph 的上下文中工作,但有时路径值的集合才起作用,有时则不起作用。 Maybe I'm just not representing more complicated jsonGraph shapes properly in path value collections.也许我只是没有在路径值集合中正确表示更复杂的 jsonGraph 形状。

My naive understanding is that collections of path values are parsed to jsonGraph by falcor.我天真的理解是路径值的集合被 falcor 解析为 jsonGraph。 But I can't find any documentation on this.但我找不到任何关于此的文档。

If anyone can clarify when to use the respective return types, or what exactly collections of path values represent as return types it would be very much appreciated.如果有人可以阐明何时使用相应的返回类型,或者路径值的集合究竟代表什么返回类型,将不胜感激。

Follow Up跟进

I believe my problem is simply not expressing JSONGraph in pathValue form correctly.我相信我的问题只是没有正确地以 pathValue 形式表达 JSONGraph。 For example, how is this arbitrary JSONGraph structure expressed with pathValues?例如,这个任意的 JSONGraph 结构如何用 pathValues 表示?

{jsonGraph: {tasksById: {0: "taskA",
                         1: "taskB",
                         2: "taskC"}}}

I thought that this would simply be a flat collection of 3 path values with the full path for each "task", but for some reason it keeps throwing.我认为这只是 3 个路径值的平面集合,每个“任务”都有完整路径,但由于某种原因,它一直在抛出。

[{path: ['tasksById', 0], value: "taskA"}, ...]

Is this the valid pathValue equivalent?这是等效的有效 pathValue 吗?

Handlers for get , set , and call should all accept either jsonGraph or an array of pathValues (or promises or observables wrapping either of those). getsetcall处理程序都应该接受jsonGraphpathValues数组(或包装其中任何一个的承诺或可观察对象)。 There's a reported bug with using jsonGraph to invalidate paths (haven't tested to see if it's still an issue), but besides that, the two should be equivalent.一个使用jsonGraph使路径无效的报告错误(尚未测试以查看它是否仍然存在问题),但除此之外,两者应该是等效的。 I've found pathValues easier to express, so haven't worked much w/ jsonGraph .我发现pathValues更容易表达,所以没有用jsonGraph工作太多。

As you noted, what is ultimately returned from the datasource is always a jsonGraphEnvelope wrapping jsonGraph , regardless of what your handlers return, so yes, if your handler returns pathValues , the datasource handles the transformation to jsonGraph .正如你提到的,什么是最终从数据源返回始终是jsonGraphEnvelope包装jsonGraph ,不管你的处理器返回什么,所以是的,如果你的处理程序返回pathValues ,数据源手柄改造jsonGraph

sometimes collections of path values just work, and sometimes they don't有时路径值的集合才起作用,有时则不起作用

Can you give an example?能给我举个例子吗? Might be a bug, or might be malformed pathValues .可能是一个错误,或者可能是格式错误的pathValues

Edit编辑

An example implementation of a get handler that nearly matches your example could look like:与您的示例几乎匹配的 get 处理程序的示例实现可能如下所示:

const RootRouter = Router.createClass([
  {
    route: 'tasksById[{integers:indices}]',
    get: ({ indices }) => {
      return indices.map((index) => ({
        path: ['tasksById', index],
        value: `task #${index}`,
      }));
    }
  }
]);

const router = new RootRouter()

router.get([['tasksById', [0, 2]]])
  .subscribe((data) => console.log(data));

// {"jsonGraph":{"tasksById":{"0":"task #0","2":"task #2"}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM