99 * @param {Object } stateManager - State manager instance
1010 * @returns {Object } Web component integration utilities
1111 */
12- export function createWebComponentIntegration ( stateManager = null ) {
13- // Create a simple state manager if none is provided
14- const simpleStateManager = stateManager || {
15- getState ( path ) {
16- return { } ;
17- } ,
18- setState ( update , options ) {
19- return { } ;
20- } ,
21- subscribe ( callback , paths ) {
22- // Return a no-op unsubscribe function
23- return ( ) => { } ;
24- }
25- } ;
12+ export function createWebComponentIntegration ( stateManager ) {
2613 /**
2714 * Create a connected web component
2815 * @param {string } tagName - Custom element tag name
@@ -48,22 +35,7 @@ export function createWebComponentIntegration(stateManager = null) {
4835 } ;
4936
5037 // Create a new class that extends the base component
51- // Handle case where BaseComponent might be undefined or null
52- let ParentClass ;
53-
54- try {
55- // Ensure BaseComponent is a valid constructor or use HTMLElement as fallback
56- if ( BaseComponent && typeof BaseComponent === 'function' ) {
57- ParentClass = BaseComponent ;
58- } else {
59- ParentClass = HTMLElement ;
60- }
61- } catch ( error ) {
62- console . error ( '[state-manager] Error creating parent class:' , error ) ;
63- ParentClass = HTMLElement ;
64- }
65-
66- const ConnectedComponent = class extends ParentClass {
38+ const ConnectedComponent = class extends BaseComponent {
6739 constructor ( ) {
6840 super ( ) ;
6941
@@ -97,7 +69,7 @@ export function createWebComponentIntegration(stateManager = null) {
9769 * @returns {any } The requested state
9870 */
9971 getState ( path ) {
100- return simpleStateManager . getState ( path ) ;
72+ return stateManager . getState ( path ) ;
10173 }
10274
10375 /**
@@ -107,7 +79,7 @@ export function createWebComponentIntegration(stateManager = null) {
10779 * @returns {Object } The new state
10880 */
10981 setState ( update , options ) {
110- return simpleStateManager . setState ( update , options ) ;
82+ return stateManager . setState ( update , options ) ;
11183 }
11284
11385 /**
@@ -151,14 +123,14 @@ export function createWebComponentIntegration(stateManager = null) {
151123 }
152124
153125 // Subscribe to state changes
154- this . _stateUnsubscribe = simpleStateManager . subscribe (
126+ this . _stateUnsubscribe = stateManager . subscribe (
155127 this . _handleStateChange . bind ( this ) ,
156128 config . statePaths
157129 ) ;
158130
159131 // Initial state update
160132 if ( typeof config . mapStateToProps === 'function' ) {
161- const fullState = simpleStateManager . getState ( ) ;
133+ const fullState = stateManager . getState ( ) ;
162134 const props = config . mapStateToProps ( fullState , this ) ;
163135
164136 // Update component properties
@@ -223,22 +195,7 @@ export function createWebComponentIntegration(stateManager = null) {
223195 } ;
224196
225197 return ( BaseClass ) => {
226- // Handle case where BaseClass might be undefined or null
227- let ParentClass ;
228-
229- try {
230- // Ensure BaseClass is a valid constructor or use HTMLElement as fallback
231- if ( BaseClass && typeof BaseClass === 'function' ) {
232- ParentClass = BaseClass ;
233- } else {
234- ParentClass = HTMLElement ;
235- }
236- } catch ( error ) {
237- console . error ( '[state-manager] Error creating parent class:' , error ) ;
238- ParentClass = HTMLElement ;
239- }
240-
241- return class extends ParentClass {
198+ return class extends BaseClass {
242199 constructor ( ) {
243200 super ( ) ;
244201
@@ -281,7 +238,7 @@ export function createWebComponentIntegration(stateManager = null) {
281238 }
282239
283240 // Subscribe to state changes
284- this . _stateUnsubscribe = simpleStateManager . subscribe (
241+ this . _stateUnsubscribe = stateManager . subscribe (
285242 this . _handleStateChange . bind ( this ) ,
286243 this . _statePaths
287244 ) ;
@@ -295,7 +252,7 @@ export function createWebComponentIntegration(stateManager = null) {
295252 * @returns {any } The requested state
296253 */
297254 getState ( path ) {
298- return simpleStateManager . getState ( path ) ;
255+ return stateManager . getState ( path ) ;
299256 }
300257
301258 /**
@@ -305,7 +262,7 @@ export function createWebComponentIntegration(stateManager = null) {
305262 * @returns {Object } The new state
306263 */
307264 setState ( update , options ) {
308- return simpleStateManager . setState ( update , options ) ;
265+ return stateManager . setState ( update , options ) ;
309266 }
310267
311268 /**
@@ -350,15 +307,15 @@ export function createWebComponentIntegration(stateManager = null) {
350307
351308 // Subscribe to state changes if not already subscribed
352309 if ( ! this . _stateUnsubscribe && this . _statePaths . length > 0 ) {
353- this . _stateUnsubscribe = simpleStateManager . subscribe (
310+ this . _stateUnsubscribe = stateManager . subscribe (
354311 this . _handleStateChange . bind ( this ) ,
355312 this . _statePaths
356313 ) ;
357314 }
358315
359316 // Initial state update
360317 if ( typeof config . mapStateToProps === 'function' ) {
361- const fullState = simpleStateManager . getState ( ) ;
318+ const fullState = stateManager . getState ( ) ;
362319 const props = config . mapStateToProps ( fullState , this ) ;
363320
364321 // Update component properties
@@ -408,22 +365,7 @@ export function createWebComponentIntegration(stateManager = null) {
408365 } ;
409366
410367 return ( BaseElement ) => {
411- // Handle case where BaseElement might be undefined or null
412- let ParentClass ;
413-
414- try {
415- // Ensure BaseElement is a valid constructor or use HTMLElement as fallback
416- if ( BaseElement && typeof BaseElement === 'function' ) {
417- ParentClass = BaseElement ;
418- } else {
419- ParentClass = HTMLElement ;
420- }
421- } catch ( error ) {
422- console . error ( '[state-manager] Error creating parent class:' , error ) ;
423- ParentClass = HTMLElement ;
424- }
425-
426- return class extends ParentClass {
368+ return class extends BaseElement {
427369 constructor ( ) {
428370 super ( ) ;
429371 this . _stateUnsubscribe = null ;
@@ -433,14 +375,14 @@ export function createWebComponentIntegration(stateManager = null) {
433375 super . connectedCallback ( ) ;
434376
435377 // Subscribe to state changes
436- this . _stateUnsubscribe = simpleStateManager . subscribe (
378+ this . _stateUnsubscribe = stateManager . subscribe (
437379 this . _handleStateChange . bind ( this ) ,
438380 config . statePaths
439381 ) ;
440382
441383 // Initial state update
442384 if ( typeof config . mapStateToProps === 'function' ) {
443- const state = simpleStateManager . getState ( ) ;
385+ const state = stateManager . getState ( ) ;
444386 const props = config . mapStateToProps ( state , this ) ;
445387
446388 // Update component properties
@@ -482,11 +424,11 @@ export function createWebComponentIntegration(stateManager = null) {
482424 }
483425
484426 getState ( path ) {
485- return simpleStateManager . getState ( path ) ;
427+ return stateManager . getState ( path ) ;
486428 }
487429
488430 setState ( update , options ) {
489- return simpleStateManager . setState ( update , options ) ;
431+ return stateManager . setState ( update , options ) ;
490432 }
491433 } ;
492434 } ;
@@ -505,7 +447,7 @@ export function createWebComponentIntegration(stateManager = null) {
505447 * @param {Object } stateManager - State manager instance
506448 * @returns {Function } State mixin factory function
507449 */
508- export function StateMixin ( stateManager = null ) {
450+ export function StateMixin ( stateManager ) {
509451 return ( options = { } ) => {
510452 const integration = createWebComponentIntegration ( stateManager ) ;
511453 return integration . createStateMixin ( options ) ;
@@ -517,10 +459,10 @@ export function StateMixin(stateManager = null) {
517459 * @param {string } tagName - Custom element tag name
518460 * @param {class } BaseComponent - Base component class
519461 * @param {Object } options - Configuration options
520- * @param {Object } stateManager - State manager instance (optional)
462+ * @param {Object } stateManager - State manager instance
521463 * @returns {class } Connected component class
522464 */
523- export function createConnectedComponent ( tagName , BaseComponent , options = { } , stateManager = null ) {
465+ export function createConnectedComponent ( tagName , BaseComponent , options = { } , stateManager ) {
524466 const integration = createWebComponentIntegration ( stateManager ) ;
525467 return integration . createConnectedComponent ( tagName , BaseComponent , options ) ;
526468}
0 commit comments