1 | import {
|
2 | die,
|
3 | Annotation,
|
4 | hasProp,
|
5 | createDecoratorAnnotation,
|
6 | ObservableObjectAdministration,
|
7 | MakeResult
|
8 | } from "../internal"
|
9 |
|
10 | const OVERRIDE = "override"
|
11 |
|
12 | export const override: Annotation & PropertyDecorator = createDecoratorAnnotation({
|
13 | annotationType_: OVERRIDE,
|
14 | make_,
|
15 | extend_
|
16 | })
|
17 |
|
18 | export function isOverride(annotation: Annotation): boolean {
|
19 | return annotation.annotationType_ === OVERRIDE
|
20 | }
|
21 |
|
22 | function make_(adm: ObservableObjectAdministration, key): MakeResult {
|
23 |
|
24 | if (__DEV__ && adm.isPlainObject_) {
|
25 | die(
|
26 | `Cannot apply '${this.annotationType_}' to '${adm.name_}.${key.toString()}':` +
|
27 | `\n'${this.annotationType_}' cannot be used on plain objects.`
|
28 | )
|
29 | }
|
30 |
|
31 | if (__DEV__ && !hasProp(adm.appliedAnnotations_!, key)) {
|
32 | die(
|
33 | `'${adm.name_}.${key.toString()}' is annotated with '${this.annotationType_}', ` +
|
34 | `but no such annotated member was found on prototype.`
|
35 | )
|
36 | }
|
37 | return MakeResult.Cancel
|
38 | }
|
39 |
|
40 | function extend_(adm, key, descriptor, proxyTrap): boolean {
|
41 | die(`'${this.annotationType_}' can only be used with 'makeObservable'`)
|
42 | }
|