@dooboostore/simple-web-component 1.0.40 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -14,6 +14,7 @@ export interface SwcAppRouteChangeSubscriberMetadata {
14
14
  export interface SwcAppRouteChangeOptions {
15
15
  path?: RoutePathType;
16
16
  filter?: (router: Router, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
17
+ order?: number;
17
18
  }
18
19
 
19
20
  function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
@@ -38,14 +39,15 @@ export function subscribeSwcAppRouteChangeWhileConnected(target: Object, propert
38
39
  // 오버로드 시그니처 - 함수 호출 (괄호 있음)
39
40
  export function subscribeSwcAppRouteChangeWhileConnected(): MethodDecorator;
40
41
  export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: RoutePathType): MethodDecorator;
42
+ export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: RoutePathType, config: Omit<SwcAppRouteChangeOptions, 'path'>): MethodDecorator;
41
43
  export function subscribeSwcAppRouteChangeWhileConnected(options: SwcAppRouteChangeOptions): MethodDecorator;
42
44
 
43
45
  // 실제 구현 (이중 모드)
44
- export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
46
+ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any, propertyKeyOrConfig?: any, descriptor?: PropertyDescriptor): any {
45
47
  // 직접 데코레이터로 사용된 경우 (괄호 없음): @subscribeSwcAppRouteChangeWhileConnected
46
48
  // propertyKey가 string | symbol이고 descriptor가 있으면 직접 사용
47
- if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
48
- return createSubscribeSwcAppRouteChangeWhileConnected({})(targetOrOptions, propertyKey, descriptor);
49
+ if (propertyKeyOrConfig && (typeof propertyKeyOrConfig === 'string' || typeof propertyKeyOrConfig === 'symbol')) {
50
+ return createSubscribeSwcAppRouteChangeWhileConnected({})(targetOrOptions, propertyKeyOrConfig, descriptor);
49
51
  }
50
52
 
51
53
  // 함수로 호출된 경우 (괄호 있음): @subscribeSwcAppRouteChangeWhileConnected() / @subscribeSwcAppRouteChangeWhileConnected('/path')
@@ -53,12 +55,20 @@ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any,
53
55
 
54
56
  if (Array.isArray(targetOrOptions)) {
55
57
  // 배열: @subscribeSwcAppRouteChangeWhileConnected(['/path1', '/path2'])
58
+ // 또는: @subscribeSwcAppRouteChangeWhileConnected(['/path1', '/path2'], { order: 1 })
56
59
  options.path = targetOrOptions;
60
+ if (propertyKeyOrConfig && typeof propertyKeyOrConfig === 'object') {
61
+ options = { ...options, ...propertyKeyOrConfig };
62
+ }
57
63
  } else if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'function') {
58
64
  // 문자열 또는 함수: @subscribeSwcAppRouteChangeWhileConnected('/path')
65
+ // 또는: @subscribeSwcAppRouteChangeWhileConnected('/path', { order: 1 })
59
66
  options.path = targetOrOptions;
67
+ if (propertyKeyOrConfig && typeof propertyKeyOrConfig === 'object') {
68
+ options = { ...options, ...propertyKeyOrConfig };
69
+ }
60
70
  } else if (targetOrOptions && typeof targetOrOptions === 'object') {
61
- // 객체: @subscribeSwcAppRouteChangeWhileConnected({ path: '/path', filter: ... })
71
+ // 객체: @subscribeSwcAppRouteChangeWhileConnected({ path: '/path', filter: ..., order: 1 })
62
72
  options = targetOrOptions;
63
73
  }
64
74
 
@@ -83,7 +83,16 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
83
83
  const routeChangeSubscribers = getSubscribeSwcAppRouteChangeWhileConnectedMetadata(instance);
84
84
  if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {
85
85
  console.log('[SWC-MIXIN] Route change subscribers found')
86
- const ps = routeChangeSubscribers.map(async metadata => {
86
+
87
+ // Sort by order (default 0 if not specified)
88
+ const sortedSubscribers = [...routeChangeSubscribers].sort((a, b) => {
89
+ const orderA = a.options?.order ?? 0;
90
+ const orderB = b.options?.order ?? 0;
91
+ return orderA - orderB;
92
+ });
93
+
94
+ // Execute subscribers in order, stop if one returns a value
95
+ for (const metadata of sortedSubscribers) {
87
96
  const methodName = metadata.propertyKey;
88
97
  let pathPattern = metadata.options?.path as any;
89
98
  const filter = metadata.options?.filter;
@@ -116,10 +125,13 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
116
125
  const filterPassed = !filter || filter(this.router!, {helper:hostSet, currentThis:instance});
117
126
 
118
127
  if (pathMatched && filterPassed && instance[methodName]) {
119
- await instance[methodName]({...re, pathData: pathData});
128
+ const result = await instance[methodName]({...re, pathData: pathData});
129
+ // If handler returns a value, stop propagation to next handlers
130
+ if (result !== undefined && result !== null) {
131
+ break;
132
+ }
120
133
  }
121
- });
122
- await Promise.allSettled(ps);
134
+ }
123
135
  }
124
136
  } finally {
125
137
  if (this.config?.ssr) {