-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Mola 渲染的过程中,会使用到 数据源(dataSource);
使用数据源
Mola 的渲染分为 Server 渲染和 Client 渲染两种:
Client 渲染
- 首先,取得组件配置数据;
- 使用对应的 Mola 组件结合组件配置数组进行渲染;
- 在
componentDidMount或者用户交互事件中,根据需要访问合适的数据源;
Server 渲染
- 首先,取得组件配置数据
- 找到所有需要 prefetch 的数据源,发送请求,获取数据
- 合并组件配置和 prefetched 数据,将组件渲染为 html
此时在 Client 端上,mola 应当可以自动标识那些有 prefetched 数据的组件。
多环境中的数据源
我们的系统需要多环境数据源的支持,例如预览环境与生产环境使用不同的数据源;
因此,在组件配置中的数据源字段是需要多套 endpoint 配置的。
但是 Mola 组件中,我们不希望 Mola 组件还需要运行环境还做出对应的处理;我们希望在上层就可以根据环境找到合适的 endpoint 作为唯一的 endpoint 参数传递给 Mola 组件;
数据源的格式
配置中的数据源格式如下所示:
{
type: 'object',
properties: {
id: {
type: 'integer',
minimum: 0
},
name: {
type: 'string'
},
sources: {
type: 'object',
properties: {
preview: {
type: 'string'
},
prodution: {
type: 'string'
}
},
required: ['production']
}
},
required: ['id', 'name', 'sources'],
media: {
type: 'captain/activity-service/lottery'
}
}Mola 组件的数据源格式:
{
type: 'string'
}Metadata
Metadata
Assignees
Labels
No labels