/**
 * 数据源高阶业务组件
 * 该组件 比 pro-datasource更加灵活
 * @author xiu.wang
 */
 import {DataSourceContext} from 'mars-pro/src/pro/mixins/dataSource'
 import { ProConfigProvideMixin } from 'mars-pro/packages/pro-config-provide';
export default {
    name: 'ProOptionDatasource',
    componentName: 'ProOptionDatasource',
    mixins: [ProConfigProvideMixin],
    inheritAttrs: false,
    data(){
        return {
            isUpdate: false
        }
    },
    props: {
        //数据源 target配置
        target: {},
        //数据源业务配置
        option: {}
    },
    created(){
        //创建按数据源
        this.dataSource = new DataSourceContext('dataSource', this.target, this.option || {}, this)
    },
    computed:{
        isChange(){
            return [
                this.target, this.option
            ]
        }
    },
    watch: {
        isChange(){
            this.isUpdate = true
            this.dataSource.updateOption(this.option || {}, this.target)
        }
    },
    render() {
        if (this.$scopedSlots.default) {
            const vnodes = this.$scopedSlots.default({scope: this, isUpdate: this.isUpdate})
            if (Array.isArray(vnodes)) {
                return vnodes[0]
            }
        }
        return null
    }
}