(
target: any,
options?: CreateObservableOptions
)
| 651 | } |
| 652 | |
| 653 | export function asObservableObject( |
| 654 | target: any, |
| 655 | options?: CreateObservableOptions |
| 656 | ): IIsObservableObject { |
| 657 | if (__DEV__ && options && isObservableObject(target)) { |
| 658 | die(`Options can't be provided for already observable objects.`) |
| 659 | } |
| 660 | |
| 661 | if (hasProp(target, $mobx)) { |
| 662 | if (__DEV__ && !(getAdministration(target) instanceof ObservableObjectAdministration)) { |
| 663 | die( |
| 664 | `Cannot convert '${getDebugName(target)}' into observable object:` + |
| 665 | `\nThe target is already observable of different type.` + |
| 666 | `\nExtending builtins is not supported.` |
| 667 | ) |
| 668 | } |
| 669 | return target |
| 670 | } |
| 671 | |
| 672 | if (__DEV__ && !Object.isExtensible(target)) { |
| 673 | die("Cannot make the designated object observable; it is not extensible") |
| 674 | } |
| 675 | |
| 676 | const name = |
| 677 | options?.name ?? |
| 678 | (__DEV__ |
| 679 | ? `${ |
| 680 | isPlainObject(target) ? "ObservableObject" : target.constructor.name |
| 681 | }@${getNextId()}` |
| 682 | : "ObservableObject") |
| 683 | |
| 684 | const adm = new ObservableObjectAdministration( |
| 685 | target, |
| 686 | new Map(), |
| 687 | String(name), |
| 688 | getAnnotationFromOptions(options) |
| 689 | ) |
| 690 | |
| 691 | addHiddenProp(target, $mobx, adm) |
| 692 | |
| 693 | return target |
| 694 | } |
| 695 | |
| 696 | const isObservableObjectAdministration = createInstanceofPredicate( |
| 697 | "ObservableObjectAdministration", |
no test coverage detected
searching dependent graphs…