| 1046 | * @returns |
| 1047 | */ |
| 1048 | const createGetters = (isReadonly, isShallow) => { |
| 1049 | return function get(target, key, receiver) { |
| 1050 | if (key === ReactiveFlags.IS_REACTIVE) { |
| 1051 | return !isReadonly; |
| 1052 | } |
| 1053 | if (key === ReactiveFlags.IS_READONLY) { |
| 1054 | return isReadonly; |
| 1055 | } |
| 1056 | if (key === ReactiveFlags.IS_SHALLOW) { |
| 1057 | return isShallow; |
| 1058 | } |
| 1059 | // 结果 |
| 1060 | const res = Reflect.get(target, key, receiver); |
| 1061 | if (!isReadonly) { |
| 1062 | // 收集依赖 |
| 1063 | track(target, key); |
| 1064 | } |
| 1065 | if (isShallow) { |
| 1066 | return res; |
| 1067 | } |
| 1068 | if (isRef(res)) { |
| 1069 | return res.value; |
| 1070 | } |
| 1071 | if (res && typeof res === 'object') { |
| 1072 | if (res instanceof Element) { |
| 1073 | return res; |
| 1074 | } |
| 1075 | return isReadonly ? readonly(res) : reactive(res); |
| 1076 | } |
| 1077 | return res; |
| 1078 | }; |
| 1079 | }; |
| 1080 | /** |
| 1081 | * @description setters |
| 1082 | * @param readonly |