Redux 如何枚举给定关系模式的所有可能关联?
一些背景 我正在开发一个数据密集型UI,其中状态存储在Redux容器中。任何接触过Redux的人都知道,有很多重复的样板文件需要以减缩器、动作、动作创建者、选择器(类似于查询)等形式编写 写这些并没有什么乐趣,尤其是当涉及到很多实体类型和伴随关系时 因此,我们的想法是设计一个关系模式和一个代码生成器,繁重的工作可以外包给它 问题 给定一个(假设的)关系模式,如下所示:Redux 如何枚举给定关系模式的所有可能关联?,redux,foreign-keys,schema,code-generation,entity-relationship,Redux,Foreign Keys,Schema,Code Generation,Entity Relationship,一些背景 我正在开发一个数据密集型UI,其中状态存储在Redux容器中。任何接触过Redux的人都知道,有很多重复的样板文件需要以减缩器、动作、动作创建者、选择器(类似于查询)等形式编写 写这些并没有什么乐趣,尤其是当涉及到很多实体类型和伴随关系时 因此,我们的想法是设计一个关系模式和一个代码生成器,繁重的工作可以外包给它 问题 给定一个(假设的)关系模式,如下所示: const schema = { book: { attributes: ["id", "name", "subGe
const schema = {
book: {
attributes: ["id", "name", "subGenreId"],
foreignKeys: [
{ fromAttribute: "subGenreId", toEntity: "subGenre", toAttribute: "id" }
]
},
mainGenre: {
attributes: ["id", "name"]
},
subGenre: {
attributes: ["id", "name", "mainGenreId"],
foreignKeys: [
{ fromAttribute: "mainGenreId", toEntity: "mainGenre", toAttribute: "id" }
]
},
author: {
attributes: ["id", "name"]
},
book_author: {
attributes: ["bookId", "authorId"],
foreignKeys: [
{ fromAttribute: "bookId", toEntity: "book", toAttribute: "id" },
{ fromAttribute: "authorId", toEntity: "author", toAttribute: "id" }
]
},
seller: {
attributes: ["id", "name"]
},
seller_book: {
attributes: ["sellerId", "bookId"],
foreignKeys: [
{ fromAttribute: "sellerId", toEntity: "seller", toAttribute: "id" },
{ fromAttribute: "bookId", toEntity: "book", toAttribute: "id" }
]
}
};
目标是(当然是通过计算)沿着以下几行生成选择器(可能忘记了一些):
“直接”关系:
按书籍
id子类型
bymain流派
id子流派
by子类型
idbook
by子体裁
idmain体裁
by作者
idbook
作者id书籍
由书籍
id卖家
bysellers
idbook
by作者
idmain流派
作者卖家id作者
by作者
id子类型
by书籍
idmain流派
bymain流派
idbook
bymainGenres
idauthor
bymaingenders
idseller
作者id卖家
by卖家
idmain流派
by卖家
id子类型
作者id子体裁
by子类型
id卖家