[fs-widget] Implement an alternative config pattern #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
(This PR targets your
274-make-beatiful-optionalbranch)I didn't have time to do this earlier, but at least, here it is: my take on making beautiful not a hard dependency for the fs-widget. (Also, please note this is untested)
My solution is actually quite easy:
You already have defined the (module level) global
configtable that holds all the available config properties and their default values. I trusted this table to set the local widget instance configuration table.In the widget instance constructor, I add a
_configtable that holds the local version of the global config table. The local_configcan be blindly used by the widget instance as "its own definition of configuration" ([1]).I then replaced all the usage of the
configtable by the instance level_configtable.The main idea here is that the instance level
_configtable will be a copy of the globalconfigtable. With the exception, it's also checking for the first available value fromargs,beautiful, then fallback to the default.(A notable limitation for this is that it will not work with nested table!)
Note: In the Awesome source code, we generally don't do a full copy of the default config table. Instead, we do the
args or beautiful or defaultcheck every time we need to access the config value. We could have a debate on "what's the best approach: code readability/performance with a local config or save memory by doing the check". I personally think both approaches are equivalent at the end of the day...[1]: Another approach with more complex widget would be to have something like
self._private.configand some meta-table methods to properly implement getters and setters for these properties.CC: @raven2cz