refactor: option merging + extract helper functions
This commit is contained in:
@@ -2,6 +2,7 @@ import { observable, immutable, unwrap } from './index'
|
||||
import { OperationTypes } from './operations'
|
||||
import { track, trigger } from './autorun'
|
||||
import { LOCKED } from './lock'
|
||||
import { isObject } from '@vue/shared'
|
||||
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
|
||||
@@ -18,7 +19,7 @@ function createGetter(isImmutable: boolean) {
|
||||
return res
|
||||
}
|
||||
track(target, OperationTypes.GET, key)
|
||||
return res !== null && typeof res === 'object'
|
||||
return isObject(res)
|
||||
? isImmutable
|
||||
? // need to lazy access immutable and observable here to avoid
|
||||
// circular dependency
|
||||
|
||||
@@ -2,8 +2,8 @@ import { unwrap, observable, immutable } from './index'
|
||||
import { track, trigger } from './autorun'
|
||||
import { OperationTypes } from './operations'
|
||||
import { LOCKED } from './lock'
|
||||
import { isObject } from '@vue/shared'
|
||||
|
||||
const isObject = (value: any) => value !== null && typeof value === 'object'
|
||||
const toObservable = (value: any) =>
|
||||
isObject(value) ? observable(value) : value
|
||||
const toImmutable = (value: any) => (isObject(value) ? immutable(value) : value)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isObject, EMPTY_OBJ } from '@vue/shared'
|
||||
import { mutableHandlers, immutableHandlers } from './baseHandlers'
|
||||
|
||||
import {
|
||||
@@ -28,7 +29,6 @@ export { OperationTypes } from './operations'
|
||||
export { computed, ComputedGetter } from './computed'
|
||||
export { lock, unlock } from './lock'
|
||||
|
||||
const EMPTY_OBJ = {}
|
||||
const collectionTypes: Set<any> = new Set([Set, Map, WeakMap, WeakSet])
|
||||
const observableValueRE = /^\[object (?:Object|Array|Map|Set|WeakMap|WeakSet)\]$/
|
||||
|
||||
@@ -83,7 +83,7 @@ function createObservable(
|
||||
baseHandlers: ProxyHandler<any>,
|
||||
collectionHandlers: ProxyHandler<any>
|
||||
) {
|
||||
if (target === null || typeof target !== 'object') {
|
||||
if (!isObject(target)) {
|
||||
if (__DEV__) {
|
||||
console.warn(`value is not observable: ${String(target)}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user