const ActionsHandlerMixin = {
    props: [
        'actions'
    ],
    data: function () {
        return {
            actions_: [],
            isLoading_: false,
        }
    },
    methods: {
        onClick: function (event = null) {
            this.runAction(event, 'onClick');
        },
        onChange: function (event = null) {
            this.$nextTick(function () {
                this.runAction(event, 'onChange');
            }.bind(this));
        },
        
        runAction(event, action)
        {
            if (!this.actions_ || !this.actions_[action])
            {
                return
            }
            
            event ? event.preventDefault() : null;
            this.isLoading_ = true;
            
            this.$actionHandler().handle(this.actions_[action], this).then(function () {
                this.isLoading_ = false;
            }.bind(this)).catch(function () {
                this.isLoading_ = false;
            }.bind(this));
        }
    }
}