|
1 | 1 | import { reactive } from '@vue/reactivity'
|
2 |
| -import { isObject } from '@vue/shared' |
3 | 2 | import { Context } from '../walk'
|
4 | 3 |
|
5 |
| -export const createScopedContext = (ctx: Context, data: object): Context => { |
6 |
| - if (isObject(data)) { |
7 |
| - const parentScope = ctx.scope |
8 |
| - const mergedScope = Object.create(parentScope) |
9 |
| - Object.defineProperties(mergedScope, Object.getOwnPropertyDescriptors(data)) |
10 |
| - const proxy = new Proxy(mergedScope, { |
11 |
| - set(target, key, val, receiver) { |
12 |
| - // when setting a property that doesn't exist on current scope, |
13 |
| - // do not create it on the current scope and fallback to parent scope. |
14 |
| - if (receiver === reactiveProxy && !target.hasOwnProperty(key)) { |
15 |
| - return Reflect.set(parentScope, key, val) |
16 |
| - } |
17 |
| - return Reflect.set(target, key, val, receiver) |
| 4 | +export const createScopedContext = (ctx: Context, data = {}): Context => { |
| 5 | + const parentScope = ctx.scope |
| 6 | + const mergedScope = Object.create(parentScope) |
| 7 | + Object.defineProperties(mergedScope, Object.getOwnPropertyDescriptors(data)) |
| 8 | + mergedScope.$refs = Object.create(parentScope.$refs) |
| 9 | + const proxy = new Proxy(mergedScope, { |
| 10 | + set(target, key, val, receiver) { |
| 11 | + // when setting a property that doesn't exist on current scope, |
| 12 | + // do not create it on the current scope and fallback to parent scope. |
| 13 | + if (receiver === reactiveProxy && !target.hasOwnProperty(key)) { |
| 14 | + return Reflect.set(parentScope, key, val) |
18 | 15 | }
|
19 |
| - }) |
20 |
| - const reactiveProxy = reactive(proxy) |
21 |
| - return { |
22 |
| - ...ctx, |
23 |
| - scope: reactiveProxy |
| 16 | + return Reflect.set(target, key, val, receiver) |
24 | 17 | }
|
| 18 | + }) |
| 19 | + const reactiveProxy = reactive(proxy) |
| 20 | + return { |
| 21 | + ...ctx, |
| 22 | + scope: reactiveProxy |
25 | 23 | }
|
26 |
| - return ctx |
27 | 24 | }
|
0 commit comments