Files
scrypted/plugins/core/ui/src/interfaces/RPCInterface.vue
Koushik Dutta a46b2811ed initial commit
2021-08-24 21:22:41 -07:00

56 lines
1.2 KiB
Vue

<script>
import CustomValue from "../common/CustomValue.vue";
export default {
props: {
device: undefined,
value: Object,
properties: Object
},
mixins: [CustomValue],
mounted() {
// call onChange to guarantee sane values.
if (!this.device && !this.lazyValue.rpc) {
this.onChange();
}
},
methods: {
rpc(options) {
if (this.device) {
return this.device;
}
options = options || {};
const { varargs, append } = options;
var vm = this;
return new Proxy(
{},
{
get: function(target, method) {
return function() {
var parameters = Array.prototype.slice.call(arguments);
if (!vm.device) {
if (append) {
vm.lazyValue.rpc.push({
method,
parameters,
varargs
});
} else {
vm.lazyValue.rpc = {
method,
parameters,
varargs
};
}
vm.onInput();
return;
}
};
}
}
);
}
}
};
</script>