mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
feat: expose set/del as named exports
This commit is contained in:
parent
45b932b6e5
commit
5673363eda
@ -225,8 +225,10 @@ export function defineReactive(
|
||||
* triggers change notification if the property doesn't
|
||||
* already exist.
|
||||
*/
|
||||
export function set<T>(array: T[], key: number, value: T): T
|
||||
export function set<T>(object: object, key: string | number, value: T): T
|
||||
export function set(
|
||||
target: Array<any> | Record<string, any>,
|
||||
target: any[] | Record<string, any>,
|
||||
key: any,
|
||||
val: any
|
||||
): any {
|
||||
@ -279,7 +281,9 @@ export function set(
|
||||
/**
|
||||
* Delete a property and trigger change if necessary.
|
||||
*/
|
||||
export function del(target: Array<any> | Object, key: any) {
|
||||
export function del<T>(array: T[], key: number): void
|
||||
export function del(object: object, key: string | number): void
|
||||
export function del(target: any[] | object, key: any) {
|
||||
if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
|
||||
warn(
|
||||
`Cannot delete reactive property on undefined, null, or primitive value: ${target}`
|
||||
|
@ -72,5 +72,6 @@ export { h } from './h'
|
||||
export { getCurrentInstance } from './currentInstance'
|
||||
export { useSlots, useAttrs } from './apiSetup'
|
||||
export { nextTick } from 'core/util/next-tick'
|
||||
export { set, del } from 'core/observer'
|
||||
|
||||
export * from './apiLifecycle'
|
||||
|
@ -11,7 +11,9 @@ import {
|
||||
shallowReactive,
|
||||
readonly,
|
||||
markRaw,
|
||||
shallowReadonly
|
||||
shallowReadonly,
|
||||
set,
|
||||
del
|
||||
} from '../../index'
|
||||
import { describe, expectType } from '../utils'
|
||||
|
||||
@ -371,3 +373,15 @@ describe('shallowReadonly ref unwrap', () => {
|
||||
expectType<Ref>(r.count.n)
|
||||
r.count.n.value = 123
|
||||
})
|
||||
|
||||
describe('set/del', () => {
|
||||
set({}, 1, 'hi')
|
||||
set([], 1, 'bye')
|
||||
del({}, 'foo')
|
||||
del([], 1)
|
||||
|
||||
// @ts-expect-error
|
||||
set({}, 1)
|
||||
// @ts-expect-error
|
||||
del([], 'fse', 123)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user