From 83e6ff6d96f8693476cc5375f85a33cf72a1b92a Mon Sep 17 00:00:00 2001 From: Lincoln Minto Date: Tue, 7 Jan 2025 09:53:54 -0300 Subject: [PATCH] Refactor: Simplify mask data processing using Object.values and flat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💻 变更类型 | Change Type feat 🔀 变更说明 | Description of Change This PR refactors the code handling mask data processing by simplifying the logic and improving scalability and type safety. Code Enhancements: Refactored the mask processing logic in app/masks/index.ts: Replaced manual destructuring of cn, tw, and en keys with Object.values to dynamically handle all mask data. Used .flat() to simplify merging mask arrays into a single collection. Added explicit type casting (as BuiltinMask) for improved type safety. Benefits: Improved Maintainability: By eliminating hardcoded destructuring, the code can adapt automatically to new mask keys without modification. Enhanced Readability: The use of Object.values and flat provides a cleaner, more concise approach. Scalability: The updated implementation supports dynamic mask additions without breaking functionality. 📝 补充信息 | Additional Information This change ensures the mask processing code is robust and easier to extend in future updates. Release Notes: New Features: Simplified mask data processing using dynamic Object.values and .flat() methods. Enhanced type safety with explicit type casting (as BuiltinMask). --- app/masks/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/masks/index.ts b/app/masks/index.ts index bff5c9bbe0a..22a725e4780 100644 --- a/app/masks/index.ts +++ b/app/masks/index.ts @@ -30,9 +30,8 @@ if (typeof window != "undefined") { return { cn: [], tw: [], en: [] }; }) .then((masks) => { - const { cn = [], tw = [], en = [] } = masks; - return [...cn, ...tw, ...en].map((m) => { - BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m)); + return Object.values(masks).flat().map((m) => { + BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m as BuiltinMask)); }); }); }