'use strict';

var vue = require('vue');

const saulVModel = (props, propName, emit) => {
  return vue.computed({
    get() {
      if (typeof props[propName] === "object") {
        return new Proxy(props[propName], {
          set(obj, name, val) {
            emit(`update:${String(propName)}`, { ...obj, [name]: val });
            return true;
          }
        });
      }
      return props[propName];
    },
    set(val) {
      emit(`update:${String(propName)}`, val);
    }
  });
};

exports.saulVModel = saulVModel;
