Skip to content

Commit cfd3ccf

Browse files
committed
Unprettified README file.
1 parent 76fb116 commit cfd3ccf

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

README.md

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Metadata Reflection API
22

3-
- [Detailed proposal][metadata-spec]
3+
* [Detailed proposal][metadata-spec]
44

55
## Installation
66

@@ -10,23 +10,22 @@ npm install reflect-metadata
1010

1111
## Background
1212

13-
- Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax.
14-
- [Traceur][traceur] attaches annotations to a static property on the class.
15-
- Languages like C# (.NET), and Java support attributes or annotations that add metadata to types, along with a reflective API for reading metadata.
13+
* Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax.
14+
* [Traceur][traceur] attaches annotations to a static property on the class.
15+
* Languages like C# (.NET), and Java support attributes or annotations that add metadata to types, along with a reflective API for reading metadata.
1616

1717
## Goals
1818

19-
- A number of use cases (Composition/Dependency Injection, Runtime Type Assertions, Reflection/Mirroring, Testing) want the ability to add additional metadata to a class in a consistent manner.
20-
- A consistent approach is needed for various tools and libraries to be able to reason over metadata.
21-
- Metadata-producing decorators (nee. "Annotations") need to be generally composable with mutating decorators.
22-
- Metadata should be available not only on an object but also through a Proxy, with related traps.
23-
- Defining new metadata-producing decorators should not be arduous or over-complex for a developer.
24-
- Metadata should be consistent with other language and runtime features of ECMAScript.
19+
* A number of use cases (Composition/Dependency Injection, Runtime Type Assertions, Reflection/Mirroring, Testing) want the ability to add additional metadata to a class in a consistent manner.
20+
* A consistent approach is needed for various tools and libraries to be able to reason over metadata.
21+
* Metadata-producing decorators (nee. "Annotations") need to be generally composable with mutating decorators.
22+
* Metadata should be available not only on an object but also through a Proxy, with related traps.
23+
* Defining new metadata-producing decorators should not be arduous or over-complex for a developer.
24+
* Metadata should be consistent with other language and runtime features of ECMAScript.
2525

2626
## Syntax
2727

28-
- Declarative definition of metadata:
29-
28+
* Declarative definition of metadata:
3029
```JavaScript
3130
class C {
3231
@Reflect.metadata(metadataKey, metadataValue)
@@ -35,29 +34,27 @@ class C {
3534
}
3635
```
3736

38-
- Imperative definition of metadata:
39-
37+
* Imperative definition of metadata:
4038
```JavaScript
4139
Reflect.defineMetadata(metadataKey, metadataValue, C.prototype, "method");
4240
```
4341

44-
- Imperative introspection of metadata:
45-
42+
* Imperative introspection of metadata:
4643
```JavaScript
4744
let obj = new C();
4845
let metadataValue = Reflect.getMetadata(metadataKey, obj, "method");
4946
```
5047

5148
## Semantics
5249

53-
- Object has a new \[\[Metadata\]\] internal property that will contain a Map whose keys are property keys (or **undefined**) and whose values are Maps of metadata keys to metadata values.
54-
- Object will have a number of new internal methods for \[\[DefineOwnMetadata\]\], \[\[GetOwnMetadata\]\], \[\[HasOwnMetadata\]\], etc.
55-
- These internal methods can be overridden by a Proxy to support additional traps.
56-
- These internal methods will by default call a set of abstract operations to define and read metadata.
57-
- The Reflect object will expose the MOP operations to allow imperative access to metadata.
58-
- Metadata defined on class declaration _C_ is stored in _C_.\[\[Metadata\]\], with **undefined** as the key.
59-
- Metadata defined on static members of class declaration _C_ are stored in _C_.\[\[Metadata\]\], with the property key as the key.
60-
- Metadata defined on instance members of class declaration _C_ are stored in _C_.prototype.\[\[Metadata\]\], with the property key as the key.
50+
* Object has a new \[\[Metadata\]\] internal property that will contain a Map whose keys are property keys (or **undefined**) and whose values are Maps of metadata keys to metadata values.
51+
* Object will have a number of new internal methods for \[\[DefineOwnMetadata\]\], \[\[GetOwnMetadata\]\], \[\[HasOwnMetadata\]\], etc.
52+
* These internal methods can be overridden by a Proxy to support additional traps.
53+
* These internal methods will by default call a set of abstract operations to define and read metadata.
54+
* The Reflect object will expose the MOP operations to allow imperative access to metadata.
55+
* Metadata defined on class declaration *C* is stored in *C*.\[\[Metadata\]\], with **undefined** as the key.
56+
* Metadata defined on static members of class declaration *C* are stored in *C*.\[\[Metadata\]\], with the property key as the key.
57+
* Metadata defined on instance members of class declaration *C* are stored in *C*.prototype.\[\[Metadata\]\], with the property key as the key.
6158

6259
## API
6360

@@ -106,9 +103,8 @@ class C {
106103

107104
## Alternatives
108105

109-
- Use properties rather than a separate API.
110-
- Obvious downside is that this can be a lot of code:
111-
106+
* Use properties rather than a separate API.
107+
* Obvious downside is that this can be a lot of code:
112108
```JavaScript
113109
function ParamTypes(...types) {
114110
return (target, propertyKey) => {
@@ -138,8 +134,7 @@ function ParamTypes(...types) {
138134
```
139135

140136
## Notes
141-
142-
- Though it may seem counterintuitive, the methods on Reflect place the parameters for the metadata key and metadata value before the target or property key. This is due to the fact that the property key is the only optional parameter in the argument list. This also makes the methods easier to curry with Function#bind. This also helps reduce the overall footprint and complexity of a metadata-producing decorator that could target both a class or a property:
137+
* Though it may seem counterintuitive, the methods on Reflect place the parameters for the metadata key and metadata value before the target or property key. This is due to the fact that the property key is the only optional parameter in the argument list. This also makes the methods easier to curry with Function#bind. This also helps reduce the overall footprint and complexity of a metadata-producing decorator that could target both a class or a property:
143138

144139
```JavaScript
145140
function ParamTypes(...types) {
@@ -170,15 +165,15 @@ function ParamTypes(...types) {
170165
}
171166
```
172167

173-
- To enable experimental support for metadata decorators in your TypeScript project, you must add `"experimentalDecorators": true` to your tsconfig.json file.
174-
- To enable experimental support for auto-generated type metadata in your TypeScript project, you must add `"emitDecoratorMetadata": true` to your tsconfig.json file.
175-
- Please note that auto-generated type metadata may have issues with circular or forward references for types.
168+
* To enable experimental support for metadata decorators in your TypeScript project, you must add `"experimentalDecorators": true` to your tsconfig.json file.
169+
* To enable experimental support for auto-generated type metadata in your TypeScript project, you must add `"emitDecoratorMetadata": true` to your tsconfig.json file.
170+
* Please note that auto-generated type metadata may have issues with circular or forward references for types.
176171

177172
## Issues
178173

179-
- A poorly written mutating decorator for a class constructor could cause metadata to become lost if the prototype chain is not maintained. Though, not maintaining the prototype chain in a mutating decorator for a class constructor would have other negative side effects as well. @rbuckton
180-
- This is mitigated if the mutating decorator returns a class expression that extends from the target, or returns a proxy for the decorator. @rbuckton
181-
- Metadata for a method is attached to the class (or prototype) via the property key. It would not then be available if trying to read metadata on the function of the method (e.g. "tearing-off" the method from the class). @rbuckton
174+
* A poorly written mutating decorator for a class constructor could cause metadata to become lost if the prototype chain is not maintained. Though, not maintaining the prototype chain in a mutating decorator for a class constructor would have other negative side effects as well. @rbuckton
175+
* This is mitigated if the mutating decorator returns a class expression that extends from the target, or returns a proxy for the decorator. @rbuckton
176+
* Metadata for a method is attached to the class (or prototype) via the property key. It would not then be available if trying to read metadata on the function of the method (e.g. "tearing-off" the method from the class). @rbuckton
182177

183178
[metadata-spec]: https://rbuckton.github.io/reflect-metadata
184-
[traceur]: https://github.com/google/traceur-compiler
179+
[traceur]: https://github.com/google/traceur-compiler

0 commit comments

Comments
 (0)