1k-coding-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOneKey Coding Patterns and Best Practices
OneKey 编码模式与最佳实践
Quick Reference
快速参考
| Topic | Guide | Key Points |
|---|---|---|
| Promise handling | promise-handling.md | Always await or use |
| React components | react-components.md | Named imports, functional components, no FC type |
| Restricted patterns | restricted-patterns.md | Forbidden: |
| 主题 | 指南 | 核心要点 |
|---|---|---|
| Promise处理 | promise-handling.md | 始终使用await或 |
| React组件 | react-components.md | 具名导入、函数式组件,禁止使用FC类型 |
| 受限模式 | restricted-patterns.md | 禁止: |
Critical Rules Summary
核心规则摘要
Promise Handling
Promise处理
typescript
// ❌ FORBIDDEN - floating promise
apiCall();
// ✅ CORRECT
await apiCall();
// or
void apiCall(); // intentionally not awaitedtypescript
// ❌ 禁止 - 游离Promise
apiCall();
// ✅ 正确
await apiCall();
// 或
void apiCall(); // 有意不使用awaitReact 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
相关技能
- - Date and time formatting
/1k-date-formatting - - Internationalization and translations
/1k-i18n - - Error handling patterns
/1k-error-handling - - Platform-specific code
/1k-cross-platform - - Linting and code quality
/1k-code-quality - - Performance optimization
/1k-performance - - Jotai atom patterns
/1k-state-management - - Project structure and import rules
/1k-architecture - - Lint fixes, pre-commit tasks
/1k-code-quality
- - 日期与时间格式化
/1k-date-formatting - - 国际化与翻译
/1k-i18n - - 错误处理模式
/1k-error-handling - - 平台专属代码
/1k-cross-platform - - 代码检查与代码质量
/1k-code-quality - - 性能优化
/1k-performance - - Jotai原子模式
/1k-state-management - - 项目结构与导入规则
/1k-architecture - - 代码检查修复、提交前任务
/1k-code-quality