通过 API 调用组件的时候,需要涉及到组件的单例、多例模式。如果说组件是单例的,在多次实例化的时候,只有一个实例,对应的视图层也只存在一份;如果说组件是多例的,那么每次实例化的时候都会产生一个新的实例,且对应的视图也是有多份的,它们之间互不影响。
You need to take the singleton and multiton pattern of components into account when invoking the component by API. If the component is singleton, then there will be only one instance when instantiating it multiple times, and there is only one corresponding view layer; If the component is multiton, then a new instance will be created each time you instantiate it, and there are multiple corresponding view layers which don't affect each other.
在 cube-ui 中涉及到 API 调用的组件都是弹层类,经常使用的如下:
The components that are involved with api-invoking in cube-ui are all popups. Frequently used ones among them are listed below:
-[Toast 提醒](#/zh-CN/docs/toast)
-[Picker 选择器](#/zh-CN/docs/picker)
-[TimePicker 时间选择器](#/zh-CN/docs/time-picker)
-[Dialog 弹框](#/zh-CN/docs/dialog)
-[ActionSheet 操作菜单](#/zh-CN/docs/action-sheet)
-[Toast](#/en-US/docs/toast)
-[Picker](#/en-US/docs/picker)
-[TimePicker](#/en-US/docs/time-picker)
-[Dialog](#/en-US/docs/dialog)
-[ActionSheet](#/en-US/docs/action-sheet)
所有的 API 调用都是使用 [create-api](#/zh-CN/docs/create-api) 模块暴露出的 `createAPI` 函数实现,在定义的时候就决定了该组件是否是单例的,详见 [create-api](#/zh-CN/docs/create-api) 文档。
All the api-invokings are implemented with the `createAPI` function exported by the [create-api](#/en-US/docs/create-api) module. It is decided whether the component is singleton in definition. See details in [create-api](#/en-US/docs/create-api).
By default, Toast, Dialog and ActionSheet is singleton, while Picker and TimePicker is multiton because their scenes tend to be more complex with a lot of extra data processing. If you want to change the default behavior at the time of instantiation,you can modify the parameter of `$createX`. For example, we change the Dialog into multiton: