@abraham/reflection 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

版本状态构建状态依赖状态npm bundle size (minified + gzip)Coverage Status

Reflection

reflect-metadata 的轻量级 ES 模块实现TypeScript 的实验性装饰器支持

Why?

这个库的主要原因是提供一个可以作为模块包含在内的更小的实现。

  • ES module
  • reflection can be loaded with <script type="module" src="..."></script>
  • Size (uncompressed)
  • reflect-metadata is ~50K
  • core-js/es7/reflect is ~80K
  • @abraham/reflection is ~3K

了解如何通过切换到这个来从生产 Angular 应用中减少 20K

Install

npm install @abraham/reflection

Usage

import '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);

您还可以导入 Reflection

import { Reflection as Reflect } from '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);

API

Reflection 目前并未涵盖 reflect-metadata 的完整 API 表面。 可以使用以下方法:

Reflect.decorate(...);
Reflect.defineMetadata(...);
Reflect.getMetadata(...);
Reflect.hasMetadata(...);
Reflect.getOwnMetadata(...);
Reflect.hasOwnMetadata(...);
Reflect.metadata(...);

Version StatusBuild StatusDependency Statusnpm bundle size (minified + gzip)Coverage Status

Reflection

Lightweight ES Module implementation of reflect-metadata to work with TypeScript's experimental decorator support.

Why?

The main reason for this library is to provide a much smaller implementation that can be included as a module.

  • ES module
  • reflection can be loaded with <script type="module" src="..."></script>
  • Size (uncompressed)
  • reflect-metadata is ~50K
  • core-js/es7/reflect is ~80K
  • @abraham/reflection is ~3K

Read about how to drop 20K from your production Angular app by switching to this.

Install

npm install @abraham/reflection

Usage

import '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);

You can also import Reflection:

import { Reflection as Reflect } from '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);

API

Reflection does not currently cover the complete API surface of reflect-metadata. The following methods are available:

Reflect.decorate(...);
Reflect.defineMetadata(...);
Reflect.getMetadata(...);
Reflect.hasMetadata(...);
Reflect.getOwnMetadata(...);
Reflect.hasOwnMetadata(...);
Reflect.metadata(...);
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文