(v, keyOrScope)
| 456 | } |
| 457 | } |
| 458 | function observable(v, keyOrScope) { |
| 459 | if (typeof arguments[1] === "string") |
| 460 | return observableDecorator.apply(null, arguments) |
| 461 | invariant( |
| 462 | arguments.length === 1 || arguments.length === 2, |
| 463 | "observable expects one or two arguments" |
| 464 | ) |
| 465 | if (isObservable(v)) return v |
| 466 | var _a = getValueModeFromValue(v, ValueMode.Recursive), |
| 467 | mode = _a[0], |
| 468 | value = _a[1] |
| 469 | var sourceType = |
| 470 | mode === ValueMode.Reference |
| 471 | ? ValueType.Reference |
| 472 | : getTypeOfValue(value) |
| 473 | switch (sourceType) { |
| 474 | case ValueType.Array: |
| 475 | case ValueType.PlainObject: |
| 476 | return makeChildObservable(value, mode) |
| 477 | case ValueType.Reference: |
| 478 | case ValueType.ComplexObject: |
| 479 | observableIsDeprecated() |
| 480 | return new ObservableValue(value, mode) |
| 481 | case ValueType.ComplexFunction: |
| 482 | observableIsDeprecated() |
| 483 | throw new Error( |
| 484 | "[mobx.observable] To be able to make a function reactive it should not have arguments. If you need an observable reference to a function, use `observable(asReference(f))`" |
| 485 | ) |
| 486 | case ValueType.ViewFunction: |
| 487 | observableIsDeprecated() |
| 488 | return new ComputedValue( |
| 489 | value, |
| 490 | keyOrScope, |
| 491 | mode === ValueMode.Structure, |
| 492 | value.name || "ComputedValue" |
| 493 | ) |
| 494 | } |
| 495 | invariant(false, "Illegal State") |
| 496 | } |
| 497 | exports.observable = observable |
| 498 | function observableIsDeprecated() { |
| 499 | deprecated( |
searching dependent graphs…