Conversation
tinder-garricnahapetian
left a comment
There was a problem hiding this comment.
Great work! Please consider breaking up a PR like this into smaller ones in the future. Maybe something like this: 1) Refactor PluginList with creationOrder, 2) Remove PluginMap, 3) Rename to AnyPlugin 4) Update templates.
| // swiftlint:disable:next strict_fileprivate | ||
| fileprivate func create(component: ComponentType, state: StateType) -> BuildType? { | ||
| let plugins: [KeyValuePair] = orderedPlugins(component: component) | ||
| for plugin: AnyPlugin in plugins.map(\.value).reversed() { |
There was a problem hiding this comment.
Does reversing still make sense with creationOrder? Without creationOrder, reversing made sense because the last plugin in the list was thought to be the latest experiment - for example. But as a user, if I define creation order, I would expect creationOrder to be respected. I would expect create (without key) to return the first plugin thats enabled in the creationOrder.
There was a problem hiding this comment.
Creation order is being respected. The create method is meant to return the one that is created last. A mental model for this is that each one that is created overrides the previous one … imagine A is created, B is created, C is created and so C is returned.
There was a problem hiding this comment.
Note that the implementation does not need to actually create A and B in the above example. By iterating in reverse order and returning the first non-nil one, we get the desired logic.
Sources/XcodeTemplateGeneratorLibrary/Resources/Templates/Plugin/PluginList.stencil
Outdated
Show resolved
Hide resolved
2b5ce35
c83a36c
Removes Plugin Map while converting the data structure used by Plugin List from array to KeyValuePairs. This enables Plugin List to provide both ordered lookup as it does now as well as key based lookup that Plugin Map previously provided.
Plugin List also gains an overridable method for defining the order plugins are created in. This allows Plugin List to contain conditional logic (based on A|B test assignment or other dynamic configuration) similar to how Plugin contains logic within its
isEnabledmethod. This new ability is crucial since Plugin List was significantly impaired by this missing capability until now.Changelog
KeyValuePairsas Plugin List data structureHashablekey typePlugintoAnyPlugin