-
Notifications
You must be signed in to change notification settings - Fork 402
Description
I am using Pattern Lab Node v3.0.0-beta.1 on Mac, with Node v8.11.1, using a Gulp Edition.
Expected Behavior
all Pseudo-Patterns are available
Actual Behavior
Pseudo Patterns are missing for some base Patterns
Steps to Reproduce
You have a pattern structure like this:
atoms/button.hbs
atoms/button.json
atoms/button~1.json
atoms/button~2.json
atoms/button~3.json
atoms/icon.hbs
atoms/icon.json
atoms/icon~1.json
atoms/icon~2.json
Now the Pseudo Patterns icon1 and icon2 are missing
Debugging
After some debugging i found an issue with the pseudopattern_hunter and addPattern
in lib/patternlab.js@334 a foreach is called for the patterns
this.patterns.map(pattern => { return processIterative(pattern, self); })
in processIterative the pseudopattern_hunter is invoked which searches for pseudo patterns. if the hunter finds some it will call addPattern. The addPattern function directly inserts the new pattern in the same array used in patternlab.js@334 (this.patterns). As it inserts the new pattern on a specific index (so the array is correctly sorted for the menu) and not pushes it to the end of the array the this.patterns.map() doesn't go through all the base patterns.
in the example above this means:
this.patterns will have initially the patterns button and icon and have a length of 2
0: button
1: icon
after the pseudopattern_hunter fot the button pattern the array will look like this:
0: button
1: button-1
2: button-2
3: button-3
4: icon
in the next iteration of this.patterns.map() the pattern will be button-1 instead of icon
as map only looks for the length of the array when it will be called, the icon pattern won't be searched for pseudo patterns.
possible Solution
a quick solution, but i don't know if this is an appropriate one, would be:
addPattern.js@45
patternlab.patterns.splice( _.sortedIndexBy(patternlab.patterns, pattern, 'name'), 0, pattern );
replace with
patternlab.patterns.push(pattern);
buildPatterns.js@67
at first command in the then() block add
//patterns sorted by name so the patterntype and patternsubtype is adhered to for menu building
patternlab.patterns.sort((p1, p2) => p1.name.localeCompare(p2.name));