@context-action/core 0.0.1 → 0.0.2

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/dist/index.cjs CHANGED
@@ -24,8 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  }) : target, mod));
25
25
 
26
26
  //#endregion
27
- const react = __toESM(require("react"));
28
- const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
29
27
 
30
28
  //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js
31
29
  var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
@@ -85,7 +83,7 @@ var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project
85
83
  } });
86
84
 
87
85
  //#endregion
88
- //#region src/core/ActionRegister.ts
86
+ //#region src/ActionRegister.ts
89
87
  var import_defineProperty = __toESM(require_defineProperty(), 1);
90
88
  var ActionRegister = class {
91
89
  constructor() {
@@ -158,7 +156,7 @@ var ActionRegister = class {
158
156
  };
159
157
 
160
158
  //#endregion
161
- //#region src/core/types.ts
159
+ //#region src/types.ts
162
160
  function createAction(type, payload) {
163
161
  return {
164
162
  type,
@@ -169,57 +167,7 @@ function isAction(action, type) {
169
167
  return action?.type === type;
170
168
  }
171
169
 
172
- //#endregion
173
- //#region src/react/ActionContext.tsx
174
- /**
175
- * ActionRegister를 Context로 공유할 수 있는 헬퍼 함수
176
- * @returns Provider, hooks를 포함한 객체
177
- */
178
- function createActionContext() {
179
- const ActionContext = (0, react.createContext)(null);
180
- const Provider = ({ children }) => {
181
- const actionRegisterRef = (0, react.useRef)(new ActionRegister());
182
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionContext.Provider, {
183
- value: { actionRegisterRef },
184
- children
185
- });
186
- };
187
- const useActionContext = () => {
188
- const context = (0, react.useContext)(ActionContext);
189
- if (!context) throw new Error("useActionContext must be used within Provider");
190
- return context;
191
- };
192
- const useAction = () => {
193
- const { actionRegisterRef } = useActionContext();
194
- return actionRegisterRef.current;
195
- };
196
- const useActionHandler = (action, handler, config) => {
197
- const actionRegister = useAction();
198
- const componentId = (0, react.useId)();
199
- (0, react.useEffect)(() => {
200
- const unregister = actionRegister.register(action, handler, {
201
- ...config,
202
- id: config?.id || componentId
203
- });
204
- return unregister;
205
- }, [
206
- action,
207
- handler,
208
- config,
209
- componentId,
210
- actionRegister
211
- ]);
212
- };
213
- return {
214
- Provider,
215
- useActionContext,
216
- useAction,
217
- useActionHandler
218
- };
219
- }
220
-
221
170
  //#endregion
222
171
  exports.ActionRegister = ActionRegister;
223
172
  exports.createAction = createAction;
224
- exports.createActionContext = createActionContext;
225
173
  exports.isAction = isAction;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,4 @@
1
- import React, { ReactNode } from "react";
2
-
3
- //#region src/core/ActionRegister.d.ts
1
+ //#region src/ActionRegister.d.ts
4
2
  type PipelineController<T = any> = {
5
3
  next: () => void;
6
4
  abort: (reason?: string) => void;
@@ -24,7 +22,7 @@ declare class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {
24
22
  }
25
23
  //# sourceMappingURL=ActionRegister.d.ts.map
26
24
  //#endregion
27
- //#region src/core/types.d.ts
25
+ //#region src/types.d.ts
28
26
  interface BaseActionPayloadMap {}
29
27
  type ActionType<T extends Record<string, any>> = keyof T;
30
28
  type ActionPayload<T extends Record<string, any>, K extends keyof T> = T[K];
@@ -38,32 +36,7 @@ declare function isAction<T extends Record<string, any>, K extends keyof T>(acti
38
36
  payload: T[K];
39
37
  };
40
38
  //# sourceMappingURL=types.d.ts.map
41
- //#endregion
42
- //#region src/react/ActionContext.d.ts
43
- /**
44
- * Context type for ActionRegister
45
- */
46
- interface ActionContextType<T extends ActionPayloadMap = ActionPayloadMap> {
47
- actionRegisterRef: React.RefObject<ActionRegister<T>>;
48
- }
49
- /**
50
- * Return type for createActionContext
51
- */
52
- interface ActionContextReturn<T extends ActionPayloadMap = ActionPayloadMap> {
53
- Provider: React.FC<{
54
- children: ReactNode;
55
- }>;
56
- useActionContext: () => ActionContextType<T>;
57
- useAction: () => ActionRegister<T>;
58
- useActionHandler: <K extends keyof T>(action: K, handler: ActionHandler<T[K]>, config?: HandlerConfig) => void;
59
- }
60
- /**
61
- * ActionRegister를 Context로 공유할 수 있는 헬퍼 함수
62
- * @returns Provider, hooks를 포함한 객체
63
- */
64
- declare function createActionContext<T extends ActionPayloadMap = ActionPayloadMap>(): ActionContextReturn<T>;
65
- //# sourceMappingURL=ActionContext.d.ts.map
66
39
 
67
40
  //#endregion
68
- export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, createActionContext, isAction };
41
+ export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, isAction };
69
42
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/core/ActionRegister.ts","../src/core/types.ts","../src/react/ActionContext.tsx"],"sourcesContent":[],"mappings":";;;KACY;;;EAAA,aAAA,EAAA,CAAA,QAAkB,EAAA,CAAA,OAAA,EAGQ,CAHR,EAAA,GAGc,CAHd,EAAA,GAAA,IAAA;CAAA;AAGQ,KAG1B,aAH0B,CAAA,IAAA,GAAA,CAAA,GAAA,CAAA,OAAA,EAI3B,CAJ2B,EAAA,UAAA,EAKxB,kBALwB,CAKL,CALK,CAAA,EAAA,GAAA,IAAA,GAM1B,OAN0B,CAAA,IAAA,CAAA;AAAM,KAQhC,aAAA,GARgC;EAAC,QAAA,CAAA,EAAA,MAAA;EAGjC,EAAA,CAAA,EAAA,MAAA;EAAa,QAAA,CAAA,EAAA,OAAA;CAAA;AAEQ,UAUhB,gBAAA,CA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AwCZ,CAxCY,CAAA,CAAA,EAyCtB,OAzCsB,CAAA,IAAA,CAAA;EAAC,QAChB,YAAA;;;;;UClCK,oBAAA,EDAjB;AAA8B,KCKlB,UDLkB,CAAA,UCKG,MDLH,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,GAAA,MCKgC,CDLhC;AAGQ,KCG1B,aDH0B,CAAA,UCI1B,MDJ0B,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MCKpB,CDLoB,CAAA,GCMlC,CDNkC,CCMhC,CDNgC,CAAA;AAAM,KCShC,gBDTgC,CAAA,UCSL,MDTK,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,GAAA,QAAC,MCU/B,CDV+B,IAAA,CAAA,OAAA,ECUhB,CDVgB,CCUd,CDVc,CAAA,EAAA,GAAA,IAAA,GCUA,ODVA,CAAA,IAAA,CAAA,EAG7C;AAAyB,iBCWT,YDXS,CAAA,UCWc,MDXd,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MCWmD,CDXnD,CAAA,CAAA,IAAA,ECYjB,CDZiB,EAAA,OAAA,ECad,CDbc,CCaZ,CDbY,CAAA,CAAA,EAAA;EAAA,IACd,ECaA,CDbA;EAAC,OACqB,ECYV,CDZU,CCYR,CDZQ,CAAA;CAAC;AACtB,iBCgBI,QDhBJ,CAAA,UCgBuB,MDhBvB,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MCgB4D,CDhB5D,CAAA,CAAA,MAAA,EAAA,GAAA,EAAA,IAAA,ECkBJ,CDlBI,CAAA,EAAA,MAAA,IAAA;EAAO,IAAA,ECmBE,CDnBF;EAEP,OAAA,ECiBqB,CDjBrB,CCiBuB,CDjBvB,CAAA;AAOZ,CAAA;AAMA"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import React, { ReactNode } from "react";
2
-
3
- //#region src/core/ActionRegister.d.ts
1
+ //#region src/ActionRegister.d.ts
4
2
  type PipelineController<T = any> = {
5
3
  next: () => void;
6
4
  abort: (reason?: string) => void;
@@ -24,7 +22,7 @@ declare class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {
24
22
  }
25
23
  //# sourceMappingURL=ActionRegister.d.ts.map
26
24
  //#endregion
27
- //#region src/core/types.d.ts
25
+ //#region src/types.d.ts
28
26
  interface BaseActionPayloadMap {}
29
27
  type ActionType<T extends Record<string, any>> = keyof T;
30
28
  type ActionPayload<T extends Record<string, any>, K extends keyof T> = T[K];
@@ -38,32 +36,7 @@ declare function isAction<T extends Record<string, any>, K extends keyof T>(acti
38
36
  payload: T[K];
39
37
  };
40
38
  //# sourceMappingURL=types.d.ts.map
41
- //#endregion
42
- //#region src/react/ActionContext.d.ts
43
- /**
44
- * Context type for ActionRegister
45
- */
46
- interface ActionContextType<T extends ActionPayloadMap = ActionPayloadMap> {
47
- actionRegisterRef: React.RefObject<ActionRegister<T>>;
48
- }
49
- /**
50
- * Return type for createActionContext
51
- */
52
- interface ActionContextReturn<T extends ActionPayloadMap = ActionPayloadMap> {
53
- Provider: React.FC<{
54
- children: ReactNode;
55
- }>;
56
- useActionContext: () => ActionContextType<T>;
57
- useAction: () => ActionRegister<T>;
58
- useActionHandler: <K extends keyof T>(action: K, handler: ActionHandler<T[K]>, config?: HandlerConfig) => void;
59
- }
60
- /**
61
- * ActionRegister를 Context로 공유할 수 있는 헬퍼 함수
62
- * @returns Provider, hooks를 포함한 객체
63
- */
64
- declare function createActionContext<T extends ActionPayloadMap = ActionPayloadMap>(): ActionContextReturn<T>;
65
- //# sourceMappingURL=ActionContext.d.ts.map
66
39
 
67
40
  //#endregion
68
- export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, createActionContext, isAction };
41
+ export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, isAction };
69
42
  //# sourceMappingURL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,CDZiB,EAAA,OAAA,ECad,CDbc,CCaZ,CDbY,CAAA,CAAA,EAAA;EAAA,IACd,ECaA,CDbA;EAAC,OACqB,ECYV,CDZU,CCYR,CDZQ,CAAA;CAAC;AACtB,iBCgBI,QDhBJ,CAAA,UCgBuB,MDhBvB,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MCgB4D,CDhB5D,CAAA,CAAA,MAAA,EAAA,GAAA,EAAA,IAAA,ECkBJ,CDlBI,CAAA,EAAA,MAAA,IAAA;EAAO,IAAA,ECmBE,CDnBF;EAEP,OAAA,ECiBqB,CDjBrB,CCiBuB,CDjBvB,CAAA;AAOZ,CAAA;AAMA"}
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- import React, { createContext, useContext, useEffect, useId, useRef } from "react";
2
- import { jsx } from "react/jsx-runtime";
3
-
4
1
  //#region rolldown:runtime
5
2
  var __create = Object.create;
6
3
  var __defProp = Object.defineProperty;
@@ -85,7 +82,7 @@ var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project
85
82
  } });
86
83
 
87
84
  //#endregion
88
- //#region src/core/ActionRegister.ts
85
+ //#region src/ActionRegister.ts
89
86
  var import_defineProperty = __toESM(require_defineProperty(), 1);
90
87
  var ActionRegister = class {
91
88
  constructor() {
@@ -158,7 +155,7 @@ var ActionRegister = class {
158
155
  };
159
156
 
160
157
  //#endregion
161
- //#region src/core/types.ts
158
+ //#region src/types.ts
162
159
  function createAction(type, payload) {
163
160
  return {
164
161
  type,
@@ -170,54 +167,5 @@ function isAction(action, type) {
170
167
  }
171
168
 
172
169
  //#endregion
173
- //#region src/react/ActionContext.tsx
174
- /**
175
- * ActionRegister를 Context로 공유할 수 있는 헬퍼 함수
176
- * @returns Provider, hooks를 포함한 객체
177
- */
178
- function createActionContext() {
179
- const ActionContext = createContext(null);
180
- const Provider = ({ children }) => {
181
- const actionRegisterRef = useRef(new ActionRegister());
182
- return /* @__PURE__ */ jsx(ActionContext.Provider, {
183
- value: { actionRegisterRef },
184
- children
185
- });
186
- };
187
- const useActionContext = () => {
188
- const context = useContext(ActionContext);
189
- if (!context) throw new Error("useActionContext must be used within Provider");
190
- return context;
191
- };
192
- const useAction = () => {
193
- const { actionRegisterRef } = useActionContext();
194
- return actionRegisterRef.current;
195
- };
196
- const useActionHandler = (action, handler, config) => {
197
- const actionRegister = useAction();
198
- const componentId = useId();
199
- useEffect(() => {
200
- const unregister = actionRegister.register(action, handler, {
201
- ...config,
202
- id: config?.id || componentId
203
- });
204
- return unregister;
205
- }, [
206
- action,
207
- handler,
208
- config,
209
- componentId,
210
- actionRegister
211
- ]);
212
- };
213
- return {
214
- Provider,
215
- useActionContext,
216
- useAction,
217
- useActionHandler
218
- };
219
- }
220
-
221
- //#endregion
222
- export { ActionRegister, createAction, createActionContext, isAction };
170
+ export { ActionRegister, createAction, isAction };
223
171
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_typeof","o","_typeof","toPrimitive","toPropertyKey","_defineProperty","action: K","handler: ActionHandler<T[K]>","config: HandlerConfig","name: string","setter: Function","payload?: T[K]","controller: PipelineController<T[K]>","type: K","payload: T[K]","action: any","action: K","handler: ActionHandler<T[K]>","config?: HandlerConfig"],"sources":["../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js","../src/core/ActionRegister.ts","../src/core/types.ts","../src/react/ActionContext.tsx"],"sourcesContent":["function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return module.exports = _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports, _typeof(o);\n}\nmodule.exports = _typeof, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nmodule.exports = toPrimitive, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nvar toPrimitive = require(\"./toPrimitive.js\");\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nmodule.exports = toPropertyKey, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var toPropertyKey = require(\"./toPropertyKey.js\");\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","// 타입 정의\nexport type PipelineController<T = any> = {\n next: () => void;\n abort: (reason?: string) => void;\n modifyPayload: (modifier: (payload: T) => T) => void;\n};\n\nexport type ActionHandler<T = any> = (\n payload: T,\n controller: PipelineController<T>\n) => void | Promise<void>;\n\nexport type HandlerConfig = {\n priority?: number;\n id?: string;\n blocking?: boolean;\n};\n\n// 선언적 타입 정의를 위한 인터페이스\nexport interface ActionPayloadMap {\n // 확장 가능한 구조\n // 'actionName': PayloadType;\n}\n\n// Action Register 클래스\nexport class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {\n private pipelines = new Map<keyof T, Map<string, {\n handler: ActionHandler<any>;\n config: HandlerConfig;\n }>>();\n \n private atomSetters = new Map<string, Function>();\n\n // 파이프라인에 핸들러 등록\n register<K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config: HandlerConfig = {}\n ): () => void {\n if (!this.pipelines.has(action)) {\n this.pipelines.set(action, new Map());\n }\n \n const pipeline = this.pipelines.get(action)!;\n const handlerId = config.id || `handler_${Date.now()}_${Math.random()}`;\n \n // 중복 등록 방지\n if (pipeline.has(handlerId)) {\n console.warn(`Handler with id ${handlerId} already exists`);\n return () => {};\n }\n \n pipeline.set(handlerId, { handler, config });\n \n // 우선순위로 정렬\n this.sortPipeline(action);\n \n // unregister 함수 반환\n return () => {\n pipeline.delete(handlerId);\n };\n }\n\n // Atom setter 등록\n registerAtomSetter(name: string, setter: Function) {\n this.atomSetters.set(name, setter);\n }\n\n // 파이프라인 실행 - void 타입을 위한 오버로드\n async dispatch<K extends keyof T>(\n action: T[K] extends void ? K : never\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload: T[K]\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload?: T[K]\n ): Promise<void> {\n const pipeline = this.pipelines.get(action);\n \n if (!pipeline || pipeline.size === 0) {\n console.warn(`No handlers registered for action: ${String(action)}`);\n return;\n }\n \n let modifiedPayload = payload as T[K];\n const handlers = Array.from(pipeline.values());\n \n for (const { handler, config } of handlers) {\n let shouldContinue = true;\n \n const controller: PipelineController<T[K]> = {\n next: () => { shouldContinue = true; },\n abort: (reason) => {\n shouldContinue = false;\n console.log(`Pipeline aborted: ${reason}`);\n },\n modifyPayload: (modifier) => {\n modifiedPayload = modifier(modifiedPayload);\n }\n };\n \n try {\n if (config.blocking) {\n await handler(modifiedPayload, controller);\n } else {\n handler(modifiedPayload, controller);\n }\n \n if (!shouldContinue) break;\n } catch (error) {\n console.error(`Error in pipeline handler:`, error);\n if (config.blocking) throw error;\n }\n }\n }\n\n private sortPipeline<K extends keyof T>(action: K) {\n const pipeline = this.pipelines.get(action);\n if (!pipeline) return;\n \n const sorted = Array.from(pipeline.entries())\n .sort(([, a], [, b]) => {\n const priorityA = a.config.priority ?? 0;\n const priorityB = b.config.priority ?? 0;\n return priorityB - priorityA; // 높은 우선순위가 먼저\n });\n \n pipeline.clear();\n sorted.forEach(([id, data]) => pipeline.set(id, data));\n }\n}","// 기본 액션 타입 정의\nexport interface BaseActionPayloadMap {\n // 기본 액션들은 여기에 정의\n}\n\n// 액션 타입 추출 헬퍼\nexport type ActionType<T extends Record<string, any>> = keyof T;\nexport type ActionPayload<\n T extends Record<string, any>,\n K extends keyof T\n> = T[K];\n\n// 액션 핸들러 타입\nexport type ActionHandlerMap<T extends Record<string, any>> = {\n [K in keyof T]?: (payload: T[K]) => void | Promise<void>;\n};\n\n// 액션 생성 헬퍼\nexport function createAction<T extends Record<string, any>, K extends keyof T>(\n type: K,\n payload: T[K]\n): { type: K; payload: T[K] } {\n return { type, payload };\n}\n\n// 타입 가드\nexport function isAction<T extends Record<string, any>, K extends keyof T>(\n action: any,\n type: K\n): action is { type: K; payload: T[K] } {\n return action?.type === type;\n}","import React, { createContext, ReactNode, useContext, useRef, useEffect, useId } from 'react';\nimport { ActionPayloadMap, ActionRegister, ActionHandler, HandlerConfig } from '../core';\n\n/**\n * Context type for ActionRegister\n */\nexport interface ActionContextType<T extends ActionPayloadMap = ActionPayloadMap> {\n actionRegisterRef: React.RefObject<ActionRegister<T>>;\n}\n\n/**\n * Return type for createActionContext\n */\nexport interface ActionContextReturn<T extends ActionPayloadMap = ActionPayloadMap> {\n Provider: React.FC<{ children: ReactNode }>;\n useActionContext: () => ActionContextType<T>;\n useAction: () => ActionRegister<T>;\n useActionHandler: <K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config?: HandlerConfig\n ) => void;\n}\n\n/**\n * ActionRegister를 Context로 공유할 수 있는 헬퍼 함수\n * @returns Provider, hooks를 포함한 객체\n */\nexport function createActionContext<T extends ActionPayloadMap = ActionPayloadMap>(): ActionContextReturn<T> {\n\n const ActionContext = createContext<ActionContextType<T> | null>(null);\n\n // Provider 컴포넌트\n const Provider = ({ children }: { children: ReactNode }) => {\n const actionRegisterRef = useRef(new ActionRegister<T>());\n return (\n <ActionContext.Provider value={{ actionRegisterRef }}>\n {children}\n </ActionContext.Provider>\n );\n };\n\n // Context 접근 hook\n const useActionContext = () => {\n const context = useContext(ActionContext);\n if (!context) {\n throw new Error('useActionContext must be used within Provider');\n }\n return context;\n };\n\n // ActionRegister 인스턴스 반환 hook\n const useAction = () => {\n const { actionRegisterRef } = useActionContext();\n return actionRegisterRef.current!;\n };\n\n // Action Handler 등록 hook\n const useActionHandler = <K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config?: HandlerConfig\n ) => {\n const actionRegister = useAction();\n const componentId = useId();\n \n useEffect(() => {\n const unregister = actionRegister.register(\n action,\n handler,\n { ...config, id: config?.id || componentId }\n );\n \n return unregister;\n }, [action, handler, config, componentId, actionRegister]);\n };\n\n return {\n Provider,\n useActionContext,\n useAction,\n useActionHandler,\n };\n}\n"],"x_google_ignoreList":[0,1,2,3],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAA,SAASA,UAAQ,GAAG;AAClB;AAEA,SAAO,OAAO,UAAUA,YAAU,cAAc,OAAO,UAAU,YAAY,OAAO,OAAO,WAAW,SAAUC,KAAG;AACjH,UAAO,OAAOA;EACf,IAAG,SAAUA,KAAG;AACf,UAAOA,OAAK,cAAc,OAAO,UAAUA,IAAE,gBAAgB,UAAUA,QAAM,OAAO,YAAY,WAAW,OAAOA;EACnH,GAAE,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO,SAASD,UAAQ,EAAE;CAC5F;CACD,OAAO,UAAUA,WAAS,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCT/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;EACA;CACD;AACF"}
1
+ {"version":3,"file":"index.js","names":["_typeof","o","_typeof","toPrimitive","toPropertyKey","_defineProperty","action: K","handler: ActionHandler<T[K]>","config: HandlerConfig","name: string","setter: Function","payload?: T[K]","controller: PipelineController<T[K]>","type: K","payload: T[K]","action: any"],"sources":["../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js","../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":["function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return module.exports = _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports, _typeof(o);\n}\nmodule.exports = _typeof, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nmodule.exports = toPrimitive, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nvar toPrimitive = require(\"./toPrimitive.js\");\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nmodule.exports = toPropertyKey, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var toPropertyKey = require(\"./toPropertyKey.js\");\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","// 타입 정의\nexport type PipelineController<T = any> = {\n next: () => void;\n abort: (reason?: string) => void;\n modifyPayload: (modifier: (payload: T) => T) => void;\n};\n\nexport type ActionHandler<T = any> = (\n payload: T,\n controller: PipelineController<T>\n) => void | Promise<void>;\n\nexport type HandlerConfig = {\n priority?: number;\n id?: string;\n blocking?: boolean;\n};\n\n// 선언적 타입 정의를 위한 인터페이스\nexport interface ActionPayloadMap {\n // 확장 가능한 구조\n // 'actionName': PayloadType;\n}\n\n// Action Register 클래스\nexport class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {\n private pipelines = new Map<keyof T, Map<string, {\n handler: ActionHandler<any>;\n config: HandlerConfig;\n }>>();\n \n private atomSetters = new Map<string, Function>();\n\n // 파이프라인에 핸들러 등록\n register<K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config: HandlerConfig = {}\n ): () => void {\n if (!this.pipelines.has(action)) {\n this.pipelines.set(action, new Map());\n }\n \n const pipeline = this.pipelines.get(action)!;\n const handlerId = config.id || `handler_${Date.now()}_${Math.random()}`;\n \n // 중복 등록 방지\n if (pipeline.has(handlerId)) {\n console.warn(`Handler with id ${handlerId} already exists`);\n return () => {};\n }\n \n pipeline.set(handlerId, { handler, config });\n \n // 우선순위로 정렬\n this.sortPipeline(action);\n \n // unregister 함수 반환\n return () => {\n pipeline.delete(handlerId);\n };\n }\n\n // Atom setter 등록\n registerAtomSetter(name: string, setter: Function) {\n this.atomSetters.set(name, setter);\n }\n\n // 파이프라인 실행 - void 타입을 위한 오버로드\n async dispatch<K extends keyof T>(\n action: T[K] extends void ? K : never\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload: T[K]\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload?: T[K]\n ): Promise<void> {\n const pipeline = this.pipelines.get(action);\n \n if (!pipeline || pipeline.size === 0) {\n console.warn(`No handlers registered for action: ${String(action)}`);\n return;\n }\n \n let modifiedPayload = payload as T[K];\n const handlers = Array.from(pipeline.values());\n \n for (const { handler, config } of handlers) {\n let shouldContinue = true;\n \n const controller: PipelineController<T[K]> = {\n next: () => { shouldContinue = true; },\n abort: (reason) => {\n shouldContinue = false;\n console.log(`Pipeline aborted: ${reason}`);\n },\n modifyPayload: (modifier) => {\n modifiedPayload = modifier(modifiedPayload);\n }\n };\n \n try {\n if (config.blocking) {\n await handler(modifiedPayload, controller);\n } else {\n handler(modifiedPayload, controller);\n }\n \n if (!shouldContinue) break;\n } catch (error) {\n console.error(`Error in pipeline handler:`, error);\n if (config.blocking) throw error;\n }\n }\n }\n\n private sortPipeline<K extends keyof T>(action: K) {\n const pipeline = this.pipelines.get(action);\n if (!pipeline) return;\n \n const sorted = Array.from(pipeline.entries())\n .sort(([, a], [, b]) => {\n const priorityA = a.config.priority ?? 0;\n const priorityB = b.config.priority ?? 0;\n return priorityB - priorityA; // 높은 우선순위가 먼저\n });\n \n pipeline.clear();\n sorted.forEach(([id, data]) => pipeline.set(id, data));\n }\n}","// 기본 액션 타입 정의\nexport interface BaseActionPayloadMap {\n // 기본 액션들은 여기에 정의\n}\n\n// 액션 타입 추출 헬퍼\nexport type ActionType<T extends Record<string, any>> = keyof T;\nexport type ActionPayload<\n T extends Record<string, any>,\n K extends keyof T\n> = T[K];\n\n// 액션 핸들러 타입\nexport type ActionHandlerMap<T extends Record<string, any>> = {\n [K in keyof T]?: (payload: T[K]) => void | Promise<void>;\n};\n\n// 액션 생성 헬퍼\nexport function createAction<T extends Record<string, any>, K extends keyof T>(\n type: K,\n payload: T[K]\n): { type: K; payload: T[K] } {\n return { type, payload };\n}\n\n// 타입 가드\nexport function isAction<T extends Record<string, any>, K extends keyof T>(\n action: any,\n type: K\n): action is { type: K; payload: T[K] } {\n return action?.type === type;\n}"],"x_google_ignoreList":[0,1,2,3],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAA,SAASA,UAAQ,GAAG;AAClB;AAEA,SAAO,OAAO,UAAUA,YAAU,cAAc,OAAO,UAAU,YAAY,OAAO,OAAO,WAAW,SAAUC,KAAG;AACjH,UAAO,OAAOA;EACf,IAAG,SAAUA,KAAG;AACf,UAAOA,OAAK,cAAc,OAAO,UAAUA,IAAE,gBAAgB,UAAUA,QAAM,OAAO,YAAY,WAAW,OAAOA;EACnH,GAAE,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO,SAASD,UAAQ,EAAE;CAC5F;CACD,OAAO,UAAUA,WAAS,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCT/F,IAAIE,6BAAiC;CACrC,SAASC,cAAY,GAAG,GAAG;AACzB,MAAI,YAAYD,UAAQ,EAAE,IAAI,CAAC,EAAG,QAAO;EACzC,IAAI,IAAI,EAAE,OAAO;AACjB,MAAI,KAAK,MAAM,GAAG;GAChB,IAAI,IAAI,EAAE,KAAK,GAAG,KAAK,UAAU;AACjC,OAAI,YAAYA,UAAQ,EAAE,CAAE,QAAO;AACnC,SAAM,IAAI,UAAU;EACrB;AACD,UAAQ,aAAa,IAAI,SAAS,QAAQ,EAAE;CAC7C;CACD,OAAO,UAAUC,eAAa,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCXnG,IAAI,2BAAiC;CACrC,IAAI;CACJ,SAASC,gBAAc,GAAG;EACxB,IAAI,IAAI,YAAY,GAAG,SAAS;AAChC,SAAO,YAAY,QAAQ,EAAE,GAAG,IAAI,IAAI;CACzC;CACD,OAAO,UAAUA,iBAAe,OAAO,QAAQ,aAAa,M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": "module",
5
- "description": "A TypeScript library for type-safe action pipeline management with React integration",
5
+ "description": "Type-safe action pipeline management library for JavaScript/TypeScript",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -24,53 +24,31 @@
24
24
  "README.ko.md",
25
25
  "LICENSE"
26
26
  ],
27
- "scripts": {
28
- "build": "tsdown",
29
- "build:watch": "tsdown --watch",
30
- "test": "jest",
31
- "test:watch": "jest --watch",
32
- "lint": "eslint src --ext .ts,.tsx",
33
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
34
- "type-check": "tsc --noEmit",
35
- "clean": "rimraf dist",
36
- "prepublishOnly": "pnpm run build"
37
- },
38
27
  "keywords": [
39
28
  "typescript",
40
- "react",
29
+ "javascript",
41
30
  "action",
42
31
  "pipeline",
43
32
  "state-management",
44
- "context",
45
- "hooks"
33
+ "event-system"
46
34
  ],
47
35
  "author": "mineclover",
48
36
  "license": "Apache-2.0",
49
37
  "repository": {
50
38
  "type": "git",
51
39
  "url": "git+https://github.com/mineclover/context-action.git",
52
- "directory": "packages/context-action"
40
+ "directory": "packages/core"
53
41
  },
54
42
  "bugs": {
55
43
  "url": "https://github.com/mineclover/context-action/issues"
56
44
  },
57
45
  "homepage": "https://github.com/mineclover/context-action#readme",
58
- "peerDependencies": {
59
- "react": ">=16.8.0"
60
- },
61
- "peerDependenciesMeta": {
62
- "react": {
63
- "optional": true
64
- }
65
- },
66
46
  "devDependencies": {
67
47
  "@types/jest": "^29.5.0",
68
- "@types/react": "^18.2.0",
69
48
  "@typescript-eslint/eslint-plugin": "^6.0.0",
70
49
  "@typescript-eslint/parser": "^6.0.0",
71
50
  "eslint": "^8.0.0",
72
51
  "jest": "^29.0.0",
73
- "react": "^18.2.0",
74
52
  "rimraf": "^5.0.0",
75
53
  "ts-jest": "^29.0.0",
76
54
  "tsdown": "^0.13.0",
@@ -79,5 +57,15 @@
79
57
  },
80
58
  "engines": {
81
59
  "node": ">=18.0.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsdown",
63
+ "build:watch": "tsdown --watch",
64
+ "test": "jest",
65
+ "test:watch": "jest --watch",
66
+ "lint": "eslint src --ext .ts",
67
+ "lint:fix": "eslint src --ext .ts --fix",
68
+ "type-check": "tsc --noEmit",
69
+ "clean": "rimraf dist"
82
70
  }
83
- }
71
+ }
package/LICENSE DELETED
@@ -1,187 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity granting the License.
13
-
14
- "Legal Entity" shall mean the union of the acting entity and all
15
- other entities that control, are controlled by, or are under common
16
- control with that entity. For the purposes of this definition,
17
- "control" means (i) the power, direct or indirect, to cause the
18
- direction or management of such entity, whether by contract or
19
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
- outstanding shares, or (iii) beneficial ownership of such entity.
21
-
22
- "You" (or "Your") shall mean an individual or Legal Entity
23
- exercising permissions granted by this License.
24
-
25
- "Source" shall mean the preferred form for making modifications,
26
- including but not limited to software source code, documentation
27
- source, and configuration files.
28
-
29
- "Object" shall mean any form resulting from mechanical
30
- transformation or translation of a Source form, including but
31
- not limited to compiled object code, generated documentation,
32
- and conversions to other media types.
33
-
34
- "Work" shall mean the work of authorship, whether in Source or
35
- Object form, made available under the License, as indicated by a
36
- copyright notice that is included in or attached to the work
37
- (which shall not include communications that are marked or
38
- otherwise designated in writing by the copyright owner as
39
- "Not a Work").
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based upon (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and derivative works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control
58
- systems, and issue tracking systems that are managed by, or on behalf
59
- of, the Licensor for the purpose of discussing and improving the Work,
60
- but excluding communication that is marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to use, reproduce, modify, distribute, prepare
71
- Derivative Works of, and perform and display the Work and such
72
- Derivative Works in all media and formats now known or hereafter
73
- developed.
74
-
75
- 3. Grant of Patent License. Subject to the terms and conditions of
76
- this License, each Contributor hereby grants to You a perpetual,
77
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
- (except as stated in this section) patent license to make, have made,
79
- use, offer to sell, sell, import, and otherwise transfer the Work,
80
- where such license applies only to those patent claims licensable
81
- by such Contributor that are necessarily infringed by their
82
- Contribution(s) alone or by combination of their Contribution(s)
83
- with the Work to which such Contribution(s) was submitted. If You
84
- institute patent litigation against any entity (including a
85
- cross-claim or counterclaim in a lawsuit) alleging that the Work
86
- or a Contribution incorporated within the Work constitutes direct
87
- or contributory patent infringement, then any patent licenses
88
- granted to You under this License for that Work shall terminate
89
- as of the date such litigation is filed.
90
-
91
- 4. Redistribution. You may reproduce and distribute copies of the
92
- Work or Derivative Works thereof in any medium, with or without
93
- modifications, and in Source or Object form, provided that You
94
- meet the following conditions:
95
-
96
- (a) You must give any other recipients of the Work or
97
- Derivative Works a copy of this License; and
98
-
99
- (b) You must cause any modified files to carry prominent notices
100
- stating that You changed the files; and
101
-
102
- (c) You must retain, in the Source form of any Derivative Works
103
- that You distribute, all copyright, trademark, patent,
104
- attribution and other notices from the Source form of the Work,
105
- excluding those notices that do not pertain to any part of
106
- the Derivative Works; and
107
-
108
- (d) If the Work includes a "NOTICE" text file as part of its
109
- distribution, then any Derivative Works that You distribute must
110
- include a readable copy of the attribution notices contained
111
- within such NOTICE file, excluding those notices that do not
112
- pertain to any part of the Derivative Works, in at least one
113
- of the following places: within a NOTICE text file distributed
114
- as part of the Derivative Works; within the Source form or
115
- documentation, if provided along with the Derivative Works; or,
116
- within a display generated by the Derivative Works, if and
117
- wherever such third-party notices normally appear. The contents
118
- of the NOTICE file are for informational purposes only and
119
- do not modify the License. You may add Your own attribution
120
- notices within Derivative Works that You distribute, alongside
121
- or as an addendum to the NOTICE text from the Work, provided
122
- that such additional attribution notices cannot be construed
123
- as modifying the License.
124
-
125
- You may add Your own copyright notice as an addendum to the copyright
126
- notice on the Work.
127
-
128
- 5. Submission of Contributions. Unless You explicitly state otherwise,
129
- any Contribution intentionally submitted for inclusion in the Work
130
- by You to the Licensor shall be under the terms and conditions of
131
- this License, without any additional terms or conditions.
132
- Notwithstanding the above, nothing herein shall supersede or modify
133
- the terms of any separate license agreement you may have executed
134
- with Licensor regarding such Contributions.
135
-
136
- 6. Trademarks. This License does not grant permission to use the trade
137
- names, trademarks, service marks, or product names of the Licensor,
138
- except as required for reasonable and customary use in describing the
139
- origin of the Work and reproducing the content of the NOTICE file.
140
-
141
- 7. Disclaimer of Warranty. Unless required by applicable law or
142
- agreed to in writing, Licensor provides the Work (and each
143
- Contributor provides its Contributions) on an "AS IS" BASIS,
144
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
145
- implied, including, without limitation, any warranties or conditions
146
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
147
- PARTICULAR PURPOSE. You are solely responsible for determining the
148
- appropriateness of using or redistributing the Work and assume any
149
- risks associated with Your exercise of permissions under this License.
150
-
151
- 8. Limitation of Liability. In no event and under no legal theory,
152
- whether in tort (including negligence), contract, or otherwise,
153
- unless required by applicable law (such as deliberate and grossly
154
- negligent acts) or agreed to in writing, shall any Contributor be
155
- liable to You for damages, including any direct, indirect, special,
156
- incidental, or consequential damages of any character arising as a
157
- result of this License or out of the use or inability to use the
158
- Work (including but not limited to damages for loss of goodwill,
159
- work stoppage, computer failure or malfunction, or any and all
160
- other commercial damages or losses), even if such Contributor
161
- has been advised of the possibility of such damages.
162
-
163
- 9. Accepting Warranty or Support. You may choose to offer, and to
164
- charge a fee for, warranty, support, indemnity or other liability
165
- obligations and/or rights consistent with this License. However, in
166
- accepting such obligations, You may act only on Your own behalf and on
167
- Your sole responsibility, not on behalf of any other Contributor, and
168
- only if You agree to indemnify, defend, and hold each Contributor
169
- harmless for any liability incurred by, or claims asserted against,
170
- such Contributor by reason of your accepting any such warranty or
171
- support.
172
-
173
- END OF TERMS AND CONDITIONS
174
-
175
- Copyright 2025 mineclover
176
-
177
- Licensed under the Apache License, Version 2.0 (the "License");
178
- you may not use this file except in compliance with the License.
179
- You may obtain a copy of the License at
180
-
181
- http://www.apache.org/licenses/LICENSE-2.0
182
-
183
- Unless required by applicable law or agreed to in writing, software
184
- distributed under the License is distributed on an "AS IS" BASIS,
185
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
- See the License for the specific language governing permissions and
187
- limitations under the License.
package/README.ko.md DELETED
@@ -1,328 +0,0 @@
1
- # @context-action/core
2
-
3
- React 통합을 지원하는 타입 안전한 액션 파이프라인 관리 TypeScript 라이브러리입니다.
4
-
5
- ## 주요 기능
6
-
7
- - 🔒 **타입 안전성**: 엄격한 타입 검사를 지원하는 완전한 TypeScript 지원
8
- - ⚡ **파이프라인 시스템**: 우선순위 제어를 통한 다중 핸들러 체이닝
9
- - 🎯 **Context 통합**: React Context와의 원활한 통합
10
- - 🔄 **비동기 지원**: 동기 및 비동기 작업 모두 처리
11
- - 🛡️ **에러 처리**: 내장된 에러 처리 및 중단 메커니즘
12
- - 📦 **경량화**: 제로 의존성으로 최소 번들 크기
13
-
14
- ## 설치
15
-
16
- ```bash
17
- npm install @context-action/core
18
- # 또는
19
- yarn add @context-action/core
20
- # 또는
21
- pnpm add @context-action/core
22
- ```
23
-
24
- ## 빠른 시작
25
-
26
- ### 1. 액션 타입 정의
27
-
28
- ```typescript
29
- import { ActionPayloadMap } from '@context-action/core';
30
-
31
- interface AppActions extends ActionPayloadMap {
32
- increment: void;
33
- decrement: void;
34
- setCount: number;
35
- reset: void;
36
- }
37
- ```
38
-
39
- ### 2. 액션 컨텍스트 생성
40
-
41
- ```typescript
42
- import { createActionContext } from '@context-action/core';
43
-
44
- const { Provider, useAction, useActionHandler } = createActionContext<AppActions>();
45
- ```
46
-
47
- ### 3. React 컴포넌트에서 사용
48
-
49
- ```typescript
50
- function Counter() {
51
- const [count, setCount] = useState(0);
52
- const action = useAction();
53
-
54
- // 액션 핸들러 등록
55
- useActionHandler('increment', () => {
56
- setCount(prev => prev + 1);
57
- }, { priority: 1 });
58
-
59
- useActionHandler('setCount', (payload) => {
60
- setCount(payload);
61
- });
62
-
63
- return (
64
- <div>
65
- <p>카운트: {count}</p>
66
- <button onClick={() => action.dispatch('increment')}>+1</button>
67
- <button onClick={() => action.dispatch('setCount', 10)}>10으로 설정</button>
68
- </div>
69
- );
70
- }
71
-
72
- function App() {
73
- return (
74
- <Provider>
75
- <Counter />
76
- </Provider>
77
- );
78
- }
79
- ```
80
-
81
- ## API 참조
82
-
83
- ### `createActionContext<T>()`
84
-
85
- 지정된 액션 타입 맵으로 새로운 액션 컨텍스트를 생성합니다.
86
-
87
- **반환값:**
88
- - `Provider`: React 컨텍스트 프로바이더 컴포넌트
89
- - `useAction()`: 액션 디스패처를 가져오는 훅
90
- - `useActionHandler()`: 액션 핸들러를 등록하는 훅
91
- - `useActionContext()`: 원시 컨텍스트에 접근하는 훅
92
-
93
- ### `ActionRegister<T>`
94
-
95
- 액션 파이프라인을 관리하는 핵심 클래스입니다.
96
-
97
- #### 메서드
98
-
99
- - `register(action, handler, config?)`: 액션 핸들러 등록
100
- - `dispatch(action, payload?)`: 파이프라인을 통해 액션 디스패치
101
-
102
- #### 핸들러 설정
103
-
104
- ```typescript
105
- interface HandlerConfig {
106
- priority?: number; // 우선순위가 높은 핸들러가 먼저 실행 (기본값: 0)
107
- id?: string; // 핸들러의 고유 식별자
108
- blocking?: boolean; // 비동기 핸들러를 기다릴지 여부 (기본값: false)
109
- }
110
- ```
111
-
112
- #### 파이프라인 컨트롤러
113
-
114
- 각 핸들러는 컨트롤러 객체를 받습니다:
115
-
116
- ```typescript
117
- interface PipelineController<T> {
118
- next(): void; // 다음 핸들러로 진행
119
- abort(reason?: string): void; // 파이프라인 중단
120
- modifyPayload(modifier: (payload: T) => T): void; // 후속 핸들러를 위한 페이로드 수정
121
- }
122
- ```
123
-
124
- ## 고급 사용법
125
-
126
- ### 우선순위 기반 실행
127
-
128
- ```typescript
129
- useActionHandler('saveData', () => {
130
- console.log('검증');
131
- }, { priority: 10 }); // 첫 번째 실행
132
-
133
- useActionHandler('saveData', () => {
134
- console.log('데이터베이스에 저장');
135
- }, { priority: 5 }); // 두 번째 실행
136
-
137
- useActionHandler('saveData', () => {
138
- console.log('UI 업데이트');
139
- }, { priority: 1 }); // 마지막 실행
140
- ```
141
-
142
- ### 비동기 핸들러
143
-
144
- ```typescript
145
- useActionHandler('fetchData', async (payload, controller) => {
146
- try {
147
- const data = await api.fetch(payload.url);
148
- controller.modifyPayload(prev => ({ ...prev, data }));
149
- } catch (error) {
150
- controller.abort('데이터 가져오기 실패');
151
- }
152
- }, { blocking: true }); // 이 핸들러가 완료될 때까지 대기
153
- ```
154
-
155
- ### 에러 처리
156
-
157
- ```typescript
158
- useActionHandler('riskyOperation', (payload, controller) => {
159
- if (!payload.isValid) {
160
- controller.abort('유효하지 않은 페이로드');
161
- return;
162
- }
163
- // 처리 계속...
164
- controller.next();
165
- });
166
- ```
167
-
168
- ## 실제 사용 예제
169
-
170
- ### 알림 시스템
171
-
172
- ```typescript
173
- interface NotificationActions extends ActionPayloadMap {
174
- showSuccess: { message: string };
175
- showError: { message: string };
176
- hideNotification: void;
177
- }
178
-
179
- const { Provider, useAction, useActionHandler } = createActionContext<NotificationActions>();
180
-
181
- function NotificationProvider({ children }: { children: ReactNode }) {
182
- const [notification, setNotification] = useState<{
183
- message: string;
184
- type: 'success' | 'error';
185
- } | null>(null);
186
-
187
- useActionHandler('showSuccess', ({ message }) => {
188
- setNotification({ message, type: 'success' });
189
- });
190
-
191
- useActionHandler('showError', ({ message }) => {
192
- setNotification({ message, type: 'error' });
193
- });
194
-
195
- useActionHandler('hideNotification', () => {
196
- setNotification(null);
197
- });
198
-
199
- return (
200
- <Provider>
201
- {children}
202
- {notification && (
203
- <div className={`notification ${notification.type}`}>
204
- {notification.message}
205
- <button onClick={() => useAction().dispatch('hideNotification')}>
206
- ×
207
- </button>
208
- </div>
209
- )}
210
- </Provider>
211
- );
212
- }
213
- ```
214
-
215
- ### 사용자 관리 시스템
216
-
217
- ```typescript
218
- interface UserActions extends ActionPayloadMap {
219
- loginUser: { email: string; password: string };
220
- logoutUser: void;
221
- updateProfile: { name: string; avatar?: File };
222
- }
223
-
224
- function UserManager() {
225
- const [user, setUser] = useState<User | null>(null);
226
- const [loading, setLoading] = useState(false);
227
- const action = useAction();
228
-
229
- // 로그인 검증
230
- useActionHandler('loginUser', ({ email, password }, controller) => {
231
- if (!email || !password) {
232
- controller.abort('이메일과 비밀번호를 입력해주세요');
233
- return;
234
- }
235
- }, { priority: 10 });
236
-
237
- // 로그인 API 호출
238
- useActionHandler('loginUser', async ({ email, password }, controller) => {
239
- setLoading(true);
240
- try {
241
- const userData = await authAPI.login(email, password);
242
- controller.modifyPayload(prev => ({ ...prev, userData }));
243
- } catch (error) {
244
- controller.abort('로그인 실패');
245
- } finally {
246
- setLoading(false);
247
- }
248
- }, { priority: 5, blocking: true });
249
-
250
- // 사용자 상태 업데이트
251
- useActionHandler('loginUser', (payload: any) => {
252
- setUser(payload.userData);
253
- localStorage.setItem('user', JSON.stringify(payload.userData));
254
- }, { priority: 1 });
255
-
256
- // 로그아웃
257
- useActionHandler('logoutUser', () => {
258
- setUser(null);
259
- localStorage.removeItem('user');
260
- });
261
-
262
- return (
263
- <div>
264
- {user ? (
265
- <div>
266
- <p>환영합니다, {user.name}님!</p>
267
- <button onClick={() => action.dispatch('logoutUser')}>
268
- 로그아웃
269
- </button>
270
- </div>
271
- ) : (
272
- <LoginForm onLogin={(email, password) =>
273
- action.dispatch('loginUser', { email, password })
274
- } />
275
- )}
276
- </div>
277
- );
278
- }
279
- ```
280
-
281
- ## TypeScript 지원
282
-
283
- 이 라이브러리는 TypeScript로 작성되었으며 완전한 타입 안전성을 제공합니다:
284
-
285
- ```typescript
286
- // ✅ 타입 안전한 액션 디스패치
287
- action.dispatch('setCount', 42); // 정상
288
- action.dispatch('setCount', 'invalid'); // ❌ 타입 에러
289
-
290
- // ✅ 타입 안전한 핸들러 등록
291
- useActionHandler('setCount', (count: number) => {
292
- // count는 자동으로 number 타입으로 추론됩니다
293
- });
294
- ```
295
-
296
- ## 성능 고려사항
297
-
298
- - **경량화**: 라이브러리는 매우 작으며 제로 의존성을 가집니다
299
- - **메모화**: 불필요한 리렌더링을 방지하기 위해 적절한 메모화를 사용하세요
300
- - **핸들러 등록**: 가능한 한 컴포넌트 외부에서 핸들러를 정의하세요
301
-
302
- ```typescript
303
- // ✅ 좋은 예
304
- const handleIncrement = useCallback(() => {
305
- setCount(prev => prev + 1);
306
- }, []);
307
-
308
- useActionHandler('increment', handleIncrement);
309
-
310
- // ❌ 피해야 할 예 (매번 새로운 함수 생성)
311
- useActionHandler('increment', () => {
312
- setCount(prev => prev + 1);
313
- });
314
- ```
315
-
316
- ## 기여하기
317
-
318
- 기여를 환영합니다! Pull Request를 자유롭게 제출해 주세요.
319
-
320
- ## 라이선스
321
-
322
- Apache-2.0 © [mineclover](https://github.com/mineclover)
323
-
324
- ## 관련 링크
325
-
326
- - [English README](./README.md) - 영문 버전
327
- - [GitHub Repository](https://github.com/mineclover/context-action) - 소스 코드
328
- - [Issues](https://github.com/mineclover/context-action/issues) - 버그 리포트 및 기능 요청
package/README.md DELETED
@@ -1,195 +0,0 @@
1
- # @context-action/core
2
-
3
- A TypeScript library for type-safe action pipeline management with React integration.
4
-
5
- ## Features
6
-
7
- - 🔒 **Type-safe**: Full TypeScript support with strict type checking
8
- - ⚡ **Pipeline System**: Chain multiple handlers with priority control
9
- - 🎯 **Context Integration**: Seamless React Context integration
10
- - 🔄 **Async Support**: Handle both sync and async operations
11
- - 🛡️ **Error Handling**: Built-in error handling and abort mechanisms
12
- - 📦 **Lightweight**: Minimal bundle size with zero dependencies
13
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install @context-action/core
18
- # or
19
- yarn add @context-action/core
20
- # or
21
- pnpm add @context-action/core
22
- ```
23
-
24
- ## Quick Start
25
-
26
- ### 1. Define your action types
27
-
28
- ```typescript
29
- import { ActionPayloadMap } from '@context-action/core';
30
-
31
- interface AppActions extends ActionPayloadMap {
32
- increment: void;
33
- decrement: void;
34
- setCount: number;
35
- reset: void;
36
- }
37
- ```
38
-
39
- ### 2. Create action context
40
-
41
- ```typescript
42
- import { createActionContext } from '@context-action/core';
43
-
44
- const { Provider, useAction, useActionHandler } = createActionContext<AppActions>();
45
- ```
46
-
47
- ### 3. Use in your React components
48
-
49
- ```typescript
50
- function Counter() {
51
- const [count, setCount] = useState(0);
52
- const action = useAction();
53
-
54
- // Register action handlers
55
- useActionHandler('increment', () => {
56
- setCount(prev => prev + 1);
57
- }, { priority: 1 });
58
-
59
- useActionHandler('setCount', (payload) => {
60
- setCount(payload);
61
- });
62
-
63
- return (
64
- <div>
65
- <p>Count: {count}</p>
66
- <button onClick={() => action.dispatch('increment')}>+1</button>
67
- <button onClick={() => action.dispatch('setCount', 10)}>Set to 10</button>
68
- </div>
69
- );
70
- }
71
-
72
- function App() {
73
- return (
74
- <Provider>
75
- <Counter />
76
- </Provider>
77
- );
78
- }
79
- ```
80
-
81
- ## API Reference
82
-
83
- ### `createActionContext<T>()`
84
-
85
- Creates a new action context with the specified action type map.
86
-
87
- **Returns:**
88
- - `Provider`: React context provider component
89
- - `useAction()`: Hook to get the action dispatcher
90
- - `useActionHandler()`: Hook to register action handlers
91
- - `useActionContext()`: Hook to access the raw context
92
-
93
- ### `ActionRegister<T>`
94
-
95
- Core class for managing action pipelines.
96
-
97
- #### Methods
98
-
99
- - `register(action, handler, config?)`: Register an action handler
100
- - `dispatch(action, payload?)`: Dispatch an action through the pipeline
101
-
102
- #### Handler Configuration
103
-
104
- ```typescript
105
- interface HandlerConfig {
106
- priority?: number; // Higher priority handlers run first (default: 0)
107
- id?: string; // Unique identifier for the handler
108
- blocking?: boolean; // Whether to wait for async handlers (default: false)
109
- }
110
- ```
111
-
112
- #### Pipeline Controller
113
-
114
- Each handler receives a controller object:
115
-
116
- ```typescript
117
- interface PipelineController<T> {
118
- next(): void; // Continue to next handler
119
- abort(reason?: string): void; // Abort the pipeline
120
- modifyPayload(modifier: (payload: T) => T): void; // Modify payload for subsequent handlers
121
- }
122
- ```
123
-
124
- ## Advanced Usage
125
-
126
- ### Priority-based Execution
127
-
128
- ```typescript
129
- useActionHandler('saveData', () => {
130
- console.log('Validation');
131
- }, { priority: 10 }); // Runs first
132
-
133
- useActionHandler('saveData', () => {
134
- console.log('Save to database');
135
- }, { priority: 5 }); // Runs second
136
-
137
- useActionHandler('saveData', () => {
138
- console.log('Update UI');
139
- }, { priority: 1 }); // Runs last
140
- ```
141
-
142
- ### Async Handlers
143
-
144
- ```typescript
145
- useActionHandler('fetchData', async (payload, controller) => {
146
- try {
147
- const data = await api.fetch(payload.url);
148
- controller.modifyPayload(prev => ({ ...prev, data }));
149
- } catch (error) {
150
- controller.abort('Failed to fetch data');
151
- }
152
- }, { blocking: true }); // Wait for this handler to complete
153
- ```
154
-
155
- ### Error Handling
156
-
157
- ```typescript
158
- useActionHandler('riskyOperation', (payload, controller) => {
159
- if (!payload.isValid) {
160
- controller.abort('Invalid payload');
161
- return;
162
- }
163
- // Continue processing...
164
- controller.next();
165
- });
166
- ```
167
-
168
- ## TypeScript Support
169
-
170
- This library is written in TypeScript and provides full type safety:
171
-
172
- ```typescript
173
- // ✅ Type-safe action dispatching
174
- action.dispatch('setCount', 42); // OK
175
- action.dispatch('setCount', 'invalid'); // ❌ Type error
176
-
177
- // ✅ Type-safe handler registration
178
- useActionHandler('setCount', (count: number) => {
179
- // count is automatically typed as number
180
- });
181
- ```
182
-
183
- ## Contributing
184
-
185
- Contributions are welcome! Please feel free to submit a Pull Request.
186
-
187
- ## License
188
-
189
- Apache-2.0 © [mineclover](https://github.com/mineclover)
190
-
191
- ## Links
192
-
193
- - [한국어 README](./README.ko.md) - Korean version
194
- - [GitHub Repository](https://github.com/mineclover/context-action) - Source code
195
- - [Issues](https://github.com/mineclover/context-action/issues) - Bug reports and feature requests