1k-coding-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OneKey Coding Patterns and Best Practices

OneKey 编码模式与最佳实践

Quick Reference

快速参考

TopicGuideKey Points
Promise handlingpromise-handling.mdAlways await or use
void
, never floating promises
React componentsreact-components.mdNamed imports, functional components, no FC type
Restricted patternsrestricted-patterns.mdForbidden:
toLocaleLowerCase
, direct hd-core import
主题指南核心要点
Promise处理promise-handling.md始终使用await或
void
,禁止出现游离Promise
React组件react-components.md具名导入、函数式组件,禁止使用FC类型
受限模式restricted-patterns.md禁止:
toLocaleLowerCase
、直接导入hd-core

Critical Rules Summary

核心规则摘要

Promise Handling

Promise处理

typescript
// ❌ FORBIDDEN - floating promise
apiCall();

// ✅ CORRECT
await apiCall();
// or
void apiCall(); // intentionally not awaited
typescript
// ❌ 禁止 - 游离Promise
apiCall();

// ✅ 正确
await apiCall();
// 或
void apiCall(); // 有意不使用await

React Components

React组件

typescript
// ❌ FORBIDDEN
import React, { FC } from 'react';
const MyComponent: FC<Props> = () => {};

// ✅ CORRECT
import { useState, useCallback } from 'react';
function MyComponent({ prop }: { prop: string }) {}
typescript
// ❌ 禁止
import React, { FC } from 'react';
const MyComponent: FC<Props> = () => {};

// ✅ 正确
import { useState, useCallback } from 'react';
function MyComponent({ prop }: { prop: string }) {}

Restricted Patterns

受限模式

typescript
// ❌ FORBIDDEN
string.toLocaleLowerCase()
import { x } from '@onekeyfe/hd-core';
import { localDbInstance } from '...';

// ✅ CORRECT
string.toLowerCase()
const { x } = await CoreSDKLoader();
import { localDb } from '...';
typescript
// ❌ 禁止
string.toLocaleLowerCase()
import { x } from '@onekeyfe/hd-core';
import { localDbInstance } from '...';

// ✅ 正确
string.toLowerCase()
const { x } = await CoreSDKLoader();
import { localDb } from '...';

Related Skills

相关技能

  • /1k-date-formatting
    - Date and time formatting
  • /1k-i18n
    - Internationalization and translations
  • /1k-error-handling
    - Error handling patterns
  • /1k-cross-platform
    - Platform-specific code
  • /1k-code-quality
    - Linting and code quality
  • /1k-performance
    - Performance optimization
  • /1k-state-management
    - Jotai atom patterns
  • /1k-architecture
    - Project structure and import rules
  • /1k-code-quality
    - Lint fixes, pre-commit tasks
  • /1k-date-formatting
    - 日期与时间格式化
  • /1k-i18n
    - 国际化与翻译
  • /1k-error-handling
    - 错误处理模式
  • /1k-cross-platform
    - 平台专属代码
  • /1k-code-quality
    - 代码检查与代码质量
  • /1k-performance
    - 性能优化
  • /1k-state-management
    - Jotai原子模式
  • /1k-architecture
    - 项目结构与导入规则
  • /1k-code-quality
    - 代码检查修复、提交前任务