I am constructing a customized view that has a number of configuration choices, every of them, upon being modified, will result in a re-layout, so I’m wondering, if I ought to group them in a single struct in order that change of 1 or a number of configurations will end in one single structure calculation, versus a number of properties however every can set off a separate work for re-calculating the structure.
For instance:
class MyView {
var textDirection: TextDirection = .leftToRight
var scrollType: ScrollType = .steady
}
vs:
class MyViewConfiguration {
let textDirection: TextDirection {
didSet {
updateLayout()
}
}
let scrollType: ScrollType {
didSet {
updateLayout()
}
}
}
class MyView {
var configuration: MyViewConfiguration {
didSet {
updateLayout()
}
}
}
It appears apparent to me that one single configuration is extra environment friendly, the one draw back might be that every time any configuration modifications I must re-create and cross the entire configuration object.
Is there some other profit for the primary method with separated configuration choices?
Thanks!