I have a component and a subcomponent. The subcomponent works on some data and sends the data to parent component.
So my flow goes like this:
component('parentComponent', {
controller: function () {
vm.onSubcomponentValueChange = function (obj) {
// convert data into some other format, lets say for example
vm.objAPIFormat = [];
for (value in obj.somevalue1) {
vm.objAPIFormat.push({
'somevalue1': value
'somevalue2': obj.somevalue2,
'somevalue3': obj.somevalue3
});
}
}
vm.onFormSubmit = function () {
// make an API call with some complex format of obj
// API call in service with vm.objAPIFormat
}
}
}
component('subComponent', {
bindings: {
inputObject: '<',
onInputObjectChange: '&'
}
controller: function () {
vm.$onChange = function (changes) {
if (changes.inputObject) {
vm.obj = changes.inputObject.currentValue;
}
}
//some complex logic with vm.obj.somevalue1 = []
//some complex logic with vm.obj.somevalue2 = ''
//some complex logic with vm.obj.somevalue3 = ''
vm.onSubcomponentChange= function () {
vm.onInputObjectChange(vm.obj);
}
}
}
Now my question is, which is an efficient approach?
passing inputObject as a single object to subcomponent? or splitting up the object into individual bindings? Like:
bindings: {
somevalue1: '<',
somevalue2: '<',
somevalue3: '<'
onSomeValue1Change: '&'
onSomeValue2Change: '&'
onSomeValue3Change: '&'
}