1+ const {
2+ createDefaultMergeOperation,
3+ normalizeMergeOptions,
4+ normalizeMergeTargets
5+ } = require ( './merge-targets' )
6+
17/**
28 * MergeableProp - Base class for props that can be merged during partial reloads.
39 *
@@ -27,12 +33,7 @@ module.exports = class MergeableProp {
2733 this . shouldMerge = true
2834 this . shouldDeepMerge = false
2935 if ( this . mergeOperations . length === 0 ) {
30- this . mergeOperations . push ( {
31- direction : 'append' ,
32- path : null ,
33- matchOn : null ,
34- isDefault : true
35- } )
36+ this . mergeOperations . push ( createDefaultMergeOperation ( ) )
3637 }
3738 return this
3839 }
@@ -83,14 +84,13 @@ module.exports = class MergeableProp {
8384 }
8485
8586 _addMergeOperations ( direction , paths , options ) {
86- const normalizedOptions =
87- typeof options === 'string' ? { matchOn : options } : options || { }
87+ const normalizedOptions = normalizeMergeOptions ( options )
8888
8989 this . shouldMerge = true
9090 this . shouldDeepMerge = false
9191 this . _clearDefaultMergeOperation ( )
9292
93- this . _normalizeMergeTargets ( paths , normalizedOptions ) . forEach ( ( target ) => {
93+ normalizeMergeTargets ( paths , normalizedOptions ) . forEach ( ( target ) => {
9494 this . mergeOperations . push ( {
9595 direction,
9696 path : target . path ,
@@ -109,47 +109,4 @@ module.exports = class MergeableProp {
109109 this . mergeOperations = [ ]
110110 }
111111 }
112-
113- _normalizeMergeTargets ( paths , options ) {
114- if ( paths === null || paths === undefined ) {
115- return [
116- {
117- path : null ,
118- matchOn : options . matchOn || null
119- }
120- ]
121- }
122-
123- if ( Array . isArray ( paths ) ) {
124- return paths . map ( ( path ) => ( {
125- path : this . _normalizePath ( path ) ,
126- matchOn : this . _resolveMatchOn ( path , options )
127- } ) )
128- }
129-
130- if ( typeof paths === 'object' ) {
131- return Object . entries ( paths ) . map ( ( [ path , matchOn ] ) => ( {
132- path : this . _normalizePath ( path ) ,
133- matchOn
134- } ) )
135- }
136-
137- return [
138- {
139- path : this . _normalizePath ( paths ) ,
140- matchOn : this . _resolveMatchOn ( paths , options )
141- }
142- ]
143- }
144-
145- _normalizePath ( path ) {
146- return path === '' ? null : path
147- }
148-
149- _resolveMatchOn ( path , options ) {
150- if ( ! options . matchOn ) return null
151- if ( typeof options . matchOn === 'object' )
152- return options . matchOn [ path ] || null
153- return options . matchOn
154- }
155112}
0 commit comments