Skip to content

Commit 1c9f842

Browse files
#1199: Fix merge strategy and add docs
1 parent d21ff1a commit 1c9f842

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

packages/core/src/lib/pseudopattern_hunter.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
7373
!patternlab.config.patternMergeVariantArrays
7474
) {
7575
return srcValue;
76-
} else if (_.isArray(objValue)) {
77-
return objValue.concat(srcValue);
7876
}
7977
// Lodash will only check for "undefined" and eslint needs a consistent
8078
// return so do not remove

packages/core/test/pseudopattern_hunter_tests.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ tap.test('pseudo pattern variant data should merge arrays', function(test) {
148148
JSON.stringify(pl.patterns[1].jsonFileData),
149149
JSON.stringify({
150150
a: 2,
151-
b: [2, 3, 8],
152-
c: { d: [4, 5, 6, 7], e: 8, f: { a: ['a'], b: ['b', 'x'], c: ['c'] } },
151+
b: [8, 3],
152+
c: { d: [6, 7], e: 8, f: { a: ['a'], b: ['x'], c: ['c'] } },
153153
})
154154
);
155155
});
@@ -170,12 +170,8 @@ tap.test(
170170
JSON.stringify(pl.patterns[1].jsonFileData),
171171
JSON.stringify({
172172
a: 2,
173-
b: [2, 3, 8],
174-
c: {
175-
d: [4, 5, 6, 7],
176-
e: 8,
177-
f: { a: ['a'], b: ['b', 'x'], c: ['c'] },
178-
},
173+
b: [8, 3],
174+
c: { d: [6, 7], e: 8, f: { a: ['a'], b: ['x'], c: ['c'] } },
179175
})
180176
);
181177
});

packages/docs/src/docs/advanced-config-options.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ For example, to export the navigation, header, and footer, one might do:
186186

187187
**default**: `[]`
188188

189+
### patternMergeVariantArrays
190+
191+
Used to override the merge behavior of pattern variants. For more information see [The Pseudo-Pattern File Data](docs/using-pseudo-patterns/#heading-the-pseudo-pattern-file data).
192+
193+
- `true` will merge arrays of the pattern and pseudo-pattern with [lodash merge](https://lodash.com/docs/4.17.15#merge)
194+
- `false` will override arrays from the pattern with pseudo-patterns arrays
195+
196+
```javascript
197+
"patternMergeVariantArrays": true,
198+
```
199+
200+
**default**: `true` | `undefined`
201+
189202
### serverOptions
190203

191204
Sets live-server options. See the [live-server documentation](https://github.com/pattern-lab/live-server#usage-from-node) for more details.

packages/docs/src/docs/pattern-pseudo-patterns.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Pseudo-patterns are similar to [pattern-specific JSON files](/docs/creating-patt
1919

2020
The tilde (`~`) and `.json` file extension are the hints that Pattern Lab uses to determine that this is a pseudo-pattern. The `patternName` tells Pattern Lab which existing pattern it should use when rendering the pseudo-pattern. The JSON file itself works exactly like the [pattern-specific JSON file](/docs/creating-pattern-specific-values/). It has the added benefit that the pseudo-pattern will also inherit any values from the existing pattern's pattern-specific JSON file.
2121

22-
By default, arrays in pseudo-pattern data will be concatenated with the base pattern's array data. To override this behavior globally you can set the parameter `patternMergeVariantArrays` in your `patternlab-config.json` to `false`. Arrays will then be overwritten and you will only have the variant's array data left.
22+
## The Pseudo-Pattern File Data
23+
24+
By default, arrays in pseudo-pattern data will be merged with the base pattern's array data on an index basis, effectively creating an array having as many entries as the larger of the two, with the indices declared in the variant replacing the first n of the parent, while keeping the rest. Declaring a larger array in the variant results in only using the variant array. To override this behavior globally you can set the parameter `patternMergeVariantArrays` in your `patternlab-config.json` to `false`. Arrays will then be overwritten and you will only have the variant's array data left.
2325

2426
```json
2527
"patternMergeVariantArrays": false

0 commit comments

Comments
 (0)