MCPcopy
hub / github.com/mobxjs/mobx / storeAnnotation

Function storeAnnotation

packages/mobx/src/api/decorators.ts:29–51  ·  view source on GitHub ↗
(prototype: any, key: PropertyKey, annotation: Annotation)

Source from the content-addressed store, hash-verified

27 * so it can be inspected later by `makeObservable` called from constructor
28 */
29export function storeAnnotation(prototype: any, key: PropertyKey, annotation: Annotation) {
30 if (!hasProp(prototype, storedAnnotationsSymbol)) {
31 addHiddenProp(prototype, storedAnnotationsSymbol, {
32 // Inherit annotations
33 ...prototype[storedAnnotationsSymbol]
34 })
35 }
36 // @override must override something
37 if (__DEV__ && isOverride(annotation) && !hasProp(prototype[storedAnnotationsSymbol], key)) {
38 const fieldName = `${prototype.constructor.name}.prototype.${key.toString()}`
39 die(
40 `'${fieldName}' is decorated with 'override', ` +
41 `but no such decorated member was found on prototype.`
42 )
43 }
44 // Cannot re-decorate
45 assertNotDecorated(prototype, annotation, key)
46
47 // Ignore override
48 if (!isOverride(annotation)) {
49 prototype[storedAnnotationsSymbol][key] = annotation
50 }
51}
52
53function assertNotDecorated(prototype: object, annotation: Annotation, key: PropertyKey) {
54 if (__DEV__ && !isOverride(annotation) && hasProp(prototype[storedAnnotationsSymbol], key)) {

Callers 4

decoratorFunction · 0.85
flow.tsFile · 0.85
computed.tsFile · 0.85
createObservableFunction · 0.85

Calls 6

hasPropFunction · 0.85
addHiddenPropFunction · 0.85
isOverrideFunction · 0.85
dieFunction · 0.85
assertNotDecoratedFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…