resuxjs 0.2.22 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +65 -8
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +1671 -0
- package/dist/cli.js.map +1 -0
- package/dist/compiler/index.js +77 -40
- package/dist/compiler/index.js.map +1 -1
- package/dist/globals.d.ts +32 -24
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -1666
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.js +2 -0
- package/dist/node.js.map +1 -0
- package/dist/reactivity/computed.d.ts +7 -0
- package/dist/reactivity/computed.js +53 -0
- package/dist/reactivity/computed.js.map +1 -0
- package/dist/reactivity/effect.d.ts +17 -0
- package/dist/reactivity/effect.js +113 -0
- package/dist/reactivity/effect.js.map +1 -0
- package/dist/reactivity/index.d.ts +8 -0
- package/dist/reactivity/index.js +8 -0
- package/dist/reactivity/index.js.map +1 -0
- package/dist/reactivity/reactive.d.ts +5 -0
- package/dist/reactivity/reactive.js +95 -0
- package/dist/reactivity/reactive.js.map +1 -0
- package/dist/reactivity/readonly.d.ts +1 -0
- package/dist/reactivity/readonly.js +2 -0
- package/dist/reactivity/readonly.js.map +1 -0
- package/dist/reactivity/ref.d.ts +22 -0
- package/dist/reactivity/ref.js +85 -0
- package/dist/reactivity/ref.js.map +1 -0
- package/dist/reactivity/scheduler.d.ts +6 -0
- package/dist/reactivity/scheduler.js +38 -0
- package/dist/reactivity/scheduler.js.map +1 -0
- package/dist/reactivity/types.d.ts +30 -0
- package/dist/reactivity/types.js +2 -0
- package/dist/reactivity/types.js.map +1 -0
- package/dist/reactivity/utils.d.ts +14 -0
- package/dist/reactivity/utils.js +34 -0
- package/dist/reactivity/utils.js.map +1 -0
- package/dist/reactivity/watch.d.ts +5 -0
- package/dist/reactivity/watch.js +98 -0
- package/dist/reactivity/watch.js.map +1 -0
- package/dist/runtime/index.d.ts +17 -3
- package/dist/runtime/index.js +542 -34
- package/dist/runtime/index.js.map +1 -1
- package/package.json +38 -8
package/dist/runtime/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { getQuery as h3GetQuery, readBody as h3ReadBody, setHeader as h3SetHeader } from "h3";
|
|
2
|
+
import { computed, isReactive, isReadonly, isRef, nextTick, reactive, readonly, ref, toRef, toRefs, unref, watch, watchEffect } from "../reactivity/index.js";
|
|
3
|
+
export { ref, reactive, computed, watch, watchEffect, readonly, toRef, toRefs, unref, isRef, isReactive, isReadonly, nextTick };
|
|
2
4
|
export function defineComponent(definition) {
|
|
3
5
|
return definition;
|
|
4
6
|
}
|
|
@@ -254,15 +256,28 @@ function createServerSetupContext(route, props, stateRefs, asyncDataRefs, headEn
|
|
|
254
256
|
};
|
|
255
257
|
return {
|
|
256
258
|
props,
|
|
259
|
+
ref,
|
|
260
|
+
reactive,
|
|
261
|
+
computed,
|
|
262
|
+
watch,
|
|
263
|
+
watchEffect,
|
|
264
|
+
readonly,
|
|
265
|
+
toRef,
|
|
266
|
+
toRefs,
|
|
267
|
+
unref,
|
|
268
|
+
isRef,
|
|
269
|
+
isReactive,
|
|
270
|
+
isReadonly,
|
|
271
|
+
nextTick,
|
|
257
272
|
useState(key, factory) {
|
|
258
273
|
if (stateRefs[key]) {
|
|
259
274
|
return stateRefs[key];
|
|
260
275
|
}
|
|
261
276
|
const value = factory ? factory() : undefined;
|
|
262
277
|
assertJsonSerializable(value, `useState("${key}")`);
|
|
263
|
-
const
|
|
264
|
-
stateRefs[key] =
|
|
265
|
-
return
|
|
278
|
+
const stateRef = ref(value);
|
|
279
|
+
stateRefs[key] = stateRef;
|
|
280
|
+
return stateRef;
|
|
266
281
|
},
|
|
267
282
|
useAsyncData(key, handler) {
|
|
268
283
|
const existing = asyncDataRefs[key];
|
|
@@ -297,9 +312,7 @@ function createServerSetupContext(route, props, stateRefs, asyncDataRefs, headEn
|
|
|
297
312
|
},
|
|
298
313
|
apiURL,
|
|
299
314
|
async useFetch(url, init) {
|
|
300
|
-
return
|
|
301
|
-
value: await fetchJson(url, init)
|
|
302
|
-
};
|
|
315
|
+
return ref(await fetchJson(url, init));
|
|
303
316
|
},
|
|
304
317
|
$fetch(url, init) {
|
|
305
318
|
return fetchJson(url, init);
|
|
@@ -313,9 +326,9 @@ function createServerSetupContext(route, props, stateRefs, asyncDataRefs, headEn
|
|
|
313
326
|
};
|
|
314
327
|
}
|
|
315
328
|
function createPendingAsyncDataResource() {
|
|
316
|
-
const value =
|
|
317
|
-
const pending =
|
|
318
|
-
const error =
|
|
329
|
+
const value = ref(undefined);
|
|
330
|
+
const pending = ref(true);
|
|
331
|
+
const error = ref(null);
|
|
319
332
|
let completion = Promise.resolve();
|
|
320
333
|
const resource = {
|
|
321
334
|
data: value,
|
|
@@ -1044,10 +1057,456 @@ const routePayloadCache = new Map();
|
|
|
1044
1057
|
const mountedVueIslands = new Map();
|
|
1045
1058
|
const pendingAsyncDataControllers = globalThis.__RESUX_PENDING_ASYNC_DATA_CONTROLLERS__ ||= new Set();
|
|
1046
1059
|
let devImportRevision = 0;
|
|
1047
|
-
let routeTransitionToken = 0;
|
|
1048
|
-
let routeTransitionHideTimer = 0;
|
|
1049
|
-
|
|
1050
|
-
|
|
1060
|
+
let routeTransitionToken = 0;
|
|
1061
|
+
let routeTransitionHideTimer = 0;
|
|
1062
|
+
|
|
1063
|
+
const __rxFlags = {
|
|
1064
|
+
isReactive: "__v_isReactive",
|
|
1065
|
+
isReadonly: "__v_isReadonly",
|
|
1066
|
+
raw: "__v_raw",
|
|
1067
|
+
isRef: "__v_isRef"
|
|
1068
|
+
};
|
|
1069
|
+
const __rxTargetMap = new WeakMap();
|
|
1070
|
+
const __rxReactiveMap = new WeakMap();
|
|
1071
|
+
const __rxReadonlyMap = new WeakMap();
|
|
1072
|
+
let __rxActiveEffect;
|
|
1073
|
+
let __rxShouldTrack = true;
|
|
1074
|
+
const __rxTrackStack = [];
|
|
1075
|
+
const __rxQueue = new Set();
|
|
1076
|
+
let __rxFlushing = false;
|
|
1077
|
+
const __rxResolvedPromise = Promise.resolve();
|
|
1078
|
+
let __rxFlushPromise = null;
|
|
1079
|
+
|
|
1080
|
+
function __rxIsObject(value) {
|
|
1081
|
+
return value !== null && typeof value === "object";
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function __rxHasChanged(value, oldValue) {
|
|
1085
|
+
return !Object.is(value, oldValue);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
function __rxQueueJob(job) {
|
|
1089
|
+
__rxQueue.add(job);
|
|
1090
|
+
if (__rxFlushing) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
__rxFlushing = true;
|
|
1094
|
+
__rxFlushPromise = __rxResolvedPromise.then(() => {
|
|
1095
|
+
try {
|
|
1096
|
+
for (const queued of __rxQueue) {
|
|
1097
|
+
queued();
|
|
1098
|
+
}
|
|
1099
|
+
} finally {
|
|
1100
|
+
__rxQueue.clear();
|
|
1101
|
+
__rxFlushing = false;
|
|
1102
|
+
__rxFlushPromise = null;
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function nextTick(fn) {
|
|
1108
|
+
const promise = __rxFlushPromise || __rxResolvedPromise;
|
|
1109
|
+
return fn ? promise.then(fn) : promise;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
class __rxReactiveEffect {
|
|
1113
|
+
constructor(fn, scheduler, onStop) {
|
|
1114
|
+
this.fn = fn;
|
|
1115
|
+
this.scheduler = scheduler;
|
|
1116
|
+
this.onStop = onStop;
|
|
1117
|
+
this.active = true;
|
|
1118
|
+
this.deps = [];
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
run() {
|
|
1122
|
+
if (!this.active) {
|
|
1123
|
+
return this.fn();
|
|
1124
|
+
}
|
|
1125
|
+
const previous = __rxActiveEffect;
|
|
1126
|
+
__rxActiveEffect = this;
|
|
1127
|
+
__rxTrackStack.push(__rxShouldTrack);
|
|
1128
|
+
__rxShouldTrack = true;
|
|
1129
|
+
try {
|
|
1130
|
+
return this.fn();
|
|
1131
|
+
} finally {
|
|
1132
|
+
__rxShouldTrack = __rxTrackStack.pop() ?? true;
|
|
1133
|
+
__rxActiveEffect = previous;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
stop() {
|
|
1138
|
+
if (!this.active) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
for (const dep of this.deps) {
|
|
1142
|
+
dep.delete(this);
|
|
1143
|
+
}
|
|
1144
|
+
this.deps.length = 0;
|
|
1145
|
+
if (typeof this.onStop === "function") {
|
|
1146
|
+
this.onStop();
|
|
1147
|
+
}
|
|
1148
|
+
this.active = false;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
function effect(fn, options = {}) {
|
|
1153
|
+
const _effect = new __rxReactiveEffect(fn, options.scheduler, options.onStop);
|
|
1154
|
+
if (!options.lazy) {
|
|
1155
|
+
_effect.run();
|
|
1156
|
+
}
|
|
1157
|
+
const runner = _effect.run.bind(_effect);
|
|
1158
|
+
runner.effect = _effect;
|
|
1159
|
+
return runner;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
function __rxTrack(target, key) {
|
|
1163
|
+
if (!__rxShouldTrack || !__rxActiveEffect) {
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
let depsMap = __rxTargetMap.get(target);
|
|
1167
|
+
if (!depsMap) {
|
|
1168
|
+
depsMap = new Map();
|
|
1169
|
+
__rxTargetMap.set(target, depsMap);
|
|
1170
|
+
}
|
|
1171
|
+
let dep = depsMap.get(key);
|
|
1172
|
+
if (!dep) {
|
|
1173
|
+
dep = new Set();
|
|
1174
|
+
depsMap.set(key, dep);
|
|
1175
|
+
}
|
|
1176
|
+
if (dep.has(__rxActiveEffect)) {
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
dep.add(__rxActiveEffect);
|
|
1180
|
+
__rxActiveEffect.deps.push(dep);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function __rxTrigger(target, key) {
|
|
1184
|
+
const depsMap = __rxTargetMap.get(target);
|
|
1185
|
+
if (!depsMap) {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
const dep = depsMap.get(key);
|
|
1189
|
+
if (!dep) {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
for (const reactiveEffect of [...dep]) {
|
|
1193
|
+
if (reactiveEffect.scheduler) {
|
|
1194
|
+
reactiveEffect.scheduler();
|
|
1195
|
+
} else {
|
|
1196
|
+
reactiveEffect.run();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function reactive(target) {
|
|
1202
|
+
return __rxCreateReactiveObject(target, false, __rxReactiveMap, false);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
function readonly(target) {
|
|
1206
|
+
return __rxCreateReactiveObject(target, true, __rxReadonlyMap, false);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
function __rxCreateReactiveObject(target, isReadonlyValue, proxyMap, isShallow) {
|
|
1210
|
+
if (!__rxIsObject(target)) {
|
|
1211
|
+
return target;
|
|
1212
|
+
}
|
|
1213
|
+
const existing = proxyMap.get(target);
|
|
1214
|
+
if (existing) {
|
|
1215
|
+
return existing;
|
|
1216
|
+
}
|
|
1217
|
+
const proxy = new Proxy(target, {
|
|
1218
|
+
get(rawTarget, key, receiver) {
|
|
1219
|
+
if (key === __rxFlags.isReactive) {
|
|
1220
|
+
return !isReadonlyValue;
|
|
1221
|
+
}
|
|
1222
|
+
if (key === __rxFlags.isReadonly) {
|
|
1223
|
+
return isReadonlyValue;
|
|
1224
|
+
}
|
|
1225
|
+
if (key === __rxFlags.raw) {
|
|
1226
|
+
return rawTarget;
|
|
1227
|
+
}
|
|
1228
|
+
const value = Reflect.get(rawTarget, key, receiver);
|
|
1229
|
+
if (!isReadonlyValue) {
|
|
1230
|
+
__rxTrack(rawTarget, key);
|
|
1231
|
+
}
|
|
1232
|
+
if (isShallow || !__rxIsObject(value)) {
|
|
1233
|
+
return value;
|
|
1234
|
+
}
|
|
1235
|
+
return isReadonlyValue ? readonly(value) : reactive(value);
|
|
1236
|
+
},
|
|
1237
|
+
set(rawTarget, key, value, receiver) {
|
|
1238
|
+
if (isReadonlyValue) {
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
const oldValue = Reflect.get(rawTarget, key, receiver);
|
|
1242
|
+
const success = Reflect.set(rawTarget, key, value, receiver);
|
|
1243
|
+
if (success && __rxHasChanged(value, oldValue)) {
|
|
1244
|
+
__rxTrigger(rawTarget, key);
|
|
1245
|
+
}
|
|
1246
|
+
return success;
|
|
1247
|
+
},
|
|
1248
|
+
deleteProperty(rawTarget, key) {
|
|
1249
|
+
if (isReadonlyValue) {
|
|
1250
|
+
return true;
|
|
1251
|
+
}
|
|
1252
|
+
const hadKey = Reflect.has(rawTarget, key);
|
|
1253
|
+
const success = Reflect.deleteProperty(rawTarget, key);
|
|
1254
|
+
if (hadKey && success) {
|
|
1255
|
+
__rxTrigger(rawTarget, key);
|
|
1256
|
+
}
|
|
1257
|
+
return success;
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
proxyMap.set(target, proxy);
|
|
1261
|
+
return proxy;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function isReactive(value) {
|
|
1265
|
+
return Boolean(__rxIsObject(value) && value[__rxFlags.isReactive]);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function isReadonly(value) {
|
|
1269
|
+
return Boolean(__rxIsObject(value) && value[__rxFlags.isReadonly]);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
class __rxRefImpl {
|
|
1273
|
+
constructor(value) {
|
|
1274
|
+
this.__v_isRef = true;
|
|
1275
|
+
this._rawValue = value;
|
|
1276
|
+
this._value = __rxIsObject(value) ? reactive(value) : value;
|
|
1277
|
+
this.dep = new Set();
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
get value() {
|
|
1281
|
+
if (__rxShouldTrack && __rxActiveEffect) {
|
|
1282
|
+
if (!this.dep.has(__rxActiveEffect)) {
|
|
1283
|
+
this.dep.add(__rxActiveEffect);
|
|
1284
|
+
__rxActiveEffect.deps.push(this.dep);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
return this._value;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
set value(newValue) {
|
|
1291
|
+
if (!__rxHasChanged(newValue, this._rawValue)) {
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
this._rawValue = newValue;
|
|
1295
|
+
this._value = __rxIsObject(newValue) ? reactive(newValue) : newValue;
|
|
1296
|
+
for (const reactiveEffect of [...this.dep]) {
|
|
1297
|
+
if (reactiveEffect.scheduler) {
|
|
1298
|
+
reactiveEffect.scheduler();
|
|
1299
|
+
} else {
|
|
1300
|
+
reactiveEffect.run();
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
function ref(value) {
|
|
1307
|
+
return isRef(value) ? value : new __rxRefImpl(value);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function isRef(value) {
|
|
1311
|
+
return Boolean(value && typeof value === "object" && value[__rxFlags.isRef] === true);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
function unref(value) {
|
|
1315
|
+
return isRef(value) ? value.value : value;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
class __rxObjectRef {
|
|
1319
|
+
constructor(object, key, defaultValue) {
|
|
1320
|
+
this.__v_isRef = true;
|
|
1321
|
+
this.object = object;
|
|
1322
|
+
this.key = key;
|
|
1323
|
+
this.defaultValue = defaultValue;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
get value() {
|
|
1327
|
+
const value = this.object[this.key];
|
|
1328
|
+
return value === undefined ? this.defaultValue : value;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
set value(newValue) {
|
|
1332
|
+
this.object[this.key] = newValue;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function toRef(object, key, defaultValue) {
|
|
1337
|
+
const value = object[key];
|
|
1338
|
+
return isRef(value) ? value : new __rxObjectRef(object, key, defaultValue);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
function toRefs(object) {
|
|
1342
|
+
const output = {};
|
|
1343
|
+
for (const key of Object.keys(object)) {
|
|
1344
|
+
output[key] = toRef(object, key);
|
|
1345
|
+
}
|
|
1346
|
+
return output;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
function computed(getterOrOptions) {
|
|
1350
|
+
const getter = typeof getterOrOptions === "function"
|
|
1351
|
+
? getterOrOptions
|
|
1352
|
+
: getterOrOptions.get;
|
|
1353
|
+
const setter = typeof getterOrOptions === "function"
|
|
1354
|
+
? undefined
|
|
1355
|
+
: getterOrOptions.set;
|
|
1356
|
+
const dep = new Set();
|
|
1357
|
+
let dirty = true;
|
|
1358
|
+
let value;
|
|
1359
|
+
const runner = effect(getter, {
|
|
1360
|
+
lazy: true,
|
|
1361
|
+
scheduler: () => {
|
|
1362
|
+
if (!dirty) {
|
|
1363
|
+
dirty = true;
|
|
1364
|
+
for (const reactiveEffect of [...dep]) {
|
|
1365
|
+
if (reactiveEffect.scheduler) {
|
|
1366
|
+
reactiveEffect.scheduler();
|
|
1367
|
+
} else {
|
|
1368
|
+
reactiveEffect.run();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
return {
|
|
1376
|
+
__v_isRef: true,
|
|
1377
|
+
__v_isReadonly: true,
|
|
1378
|
+
get value() {
|
|
1379
|
+
if (__rxShouldTrack && __rxActiveEffect && !dep.has(__rxActiveEffect)) {
|
|
1380
|
+
dep.add(__rxActiveEffect);
|
|
1381
|
+
__rxActiveEffect.deps.push(dep);
|
|
1382
|
+
}
|
|
1383
|
+
if (dirty) {
|
|
1384
|
+
dirty = false;
|
|
1385
|
+
value = runner();
|
|
1386
|
+
}
|
|
1387
|
+
return value;
|
|
1388
|
+
},
|
|
1389
|
+
set value(newValue) {
|
|
1390
|
+
if (setter) {
|
|
1391
|
+
setter(newValue);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const __rxInitialWatchValue = Symbol("initial-watch-value");
|
|
1398
|
+
|
|
1399
|
+
function watch(source, callback, options = {}) {
|
|
1400
|
+
return __rxDoWatch(source, callback, options);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function watchEffect(effectFn, options = {}) {
|
|
1404
|
+
return __rxDoWatch(effectFn, null, options);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
function __rxDoWatch(source, callback, options) {
|
|
1408
|
+
const deep = options.deep === true;
|
|
1409
|
+
const immediate = options.immediate === true;
|
|
1410
|
+
const flush = options.flush ?? "post";
|
|
1411
|
+
let cleanup;
|
|
1412
|
+
const onCleanup = (fn) => {
|
|
1413
|
+
cleanup = fn;
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1416
|
+
let getter;
|
|
1417
|
+
if (callback === null) {
|
|
1418
|
+
getter = () => {
|
|
1419
|
+
if (cleanup) {
|
|
1420
|
+
cleanup();
|
|
1421
|
+
cleanup = undefined;
|
|
1422
|
+
}
|
|
1423
|
+
source(onCleanup);
|
|
1424
|
+
};
|
|
1425
|
+
} else {
|
|
1426
|
+
getter = () => __rxResolveWatchSource(source);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
if (deep) {
|
|
1430
|
+
const baseGetter = getter;
|
|
1431
|
+
getter = () => __rxTraverse(baseGetter());
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
let oldValue = __rxInitialWatchValue;
|
|
1435
|
+
|
|
1436
|
+
const job = () => {
|
|
1437
|
+
if (callback === null) {
|
|
1438
|
+
runner();
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
const newValue = runner();
|
|
1442
|
+
if (deep || oldValue === __rxInitialWatchValue || __rxHasChanged(newValue, oldValue)) {
|
|
1443
|
+
if (cleanup) {
|
|
1444
|
+
cleanup();
|
|
1445
|
+
cleanup = undefined;
|
|
1446
|
+
}
|
|
1447
|
+
callback(newValue, oldValue === __rxInitialWatchValue ? undefined : oldValue, onCleanup);
|
|
1448
|
+
oldValue = newValue;
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
const scheduler = flush === "sync"
|
|
1453
|
+
? job
|
|
1454
|
+
: () => __rxQueueJob(job);
|
|
1455
|
+
|
|
1456
|
+
const runner = effect(getter, {
|
|
1457
|
+
scheduler,
|
|
1458
|
+
lazy: callback !== null
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
if (callback) {
|
|
1462
|
+
if (immediate) {
|
|
1463
|
+
job();
|
|
1464
|
+
} else {
|
|
1465
|
+
oldValue = runner();
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
return () => {
|
|
1470
|
+
if (cleanup) {
|
|
1471
|
+
cleanup();
|
|
1472
|
+
cleanup = undefined;
|
|
1473
|
+
}
|
|
1474
|
+
runner.effect.stop();
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function __rxResolveWatchSource(source) {
|
|
1479
|
+
if (Array.isArray(source)) {
|
|
1480
|
+
return source.map((entry) => __rxResolveWatchEntry(entry));
|
|
1481
|
+
}
|
|
1482
|
+
return __rxResolveWatchEntry(source);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function __rxResolveWatchEntry(source) {
|
|
1486
|
+
if (isRef(source)) {
|
|
1487
|
+
return source.value;
|
|
1488
|
+
}
|
|
1489
|
+
if (isReactive(source)) {
|
|
1490
|
+
return source;
|
|
1491
|
+
}
|
|
1492
|
+
if (typeof source === "function") {
|
|
1493
|
+
return source();
|
|
1494
|
+
}
|
|
1495
|
+
return source;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
function __rxTraverse(value, seen = new Set()) {
|
|
1499
|
+
if (!__rxIsObject(value) || seen.has(value)) {
|
|
1500
|
+
return value;
|
|
1501
|
+
}
|
|
1502
|
+
seen.add(value);
|
|
1503
|
+
for (const key of Object.keys(value)) {
|
|
1504
|
+
__rxTraverse(value[key], seen);
|
|
1505
|
+
}
|
|
1506
|
+
return value;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
export function createClientComponent(definition) {
|
|
1051
1510
|
return {
|
|
1052
1511
|
async createScope(serializedScope, route) {
|
|
1053
1512
|
const stateRefs = {};
|
|
@@ -1055,15 +1514,28 @@ export function createClientComponent(definition) {
|
|
|
1055
1514
|
const pendingCompletions = [];
|
|
1056
1515
|
const mountedCallbacks = [];
|
|
1057
1516
|
const props = serializedScope.props ?? {};
|
|
1058
|
-
const setupContext = {
|
|
1059
|
-
props,
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1517
|
+
const setupContext = {
|
|
1518
|
+
props,
|
|
1519
|
+
ref,
|
|
1520
|
+
reactive,
|
|
1521
|
+
computed,
|
|
1522
|
+
watch,
|
|
1523
|
+
watchEffect,
|
|
1524
|
+
readonly,
|
|
1525
|
+
toRef,
|
|
1526
|
+
toRefs,
|
|
1527
|
+
unref,
|
|
1528
|
+
isRef,
|
|
1529
|
+
isReactive,
|
|
1530
|
+
isReadonly,
|
|
1531
|
+
nextTick,
|
|
1532
|
+
useState(key, factory) {
|
|
1533
|
+
if (!stateRefs[key]) {
|
|
1534
|
+
const hasValue = serializedScope.state && Object.prototype.hasOwnProperty.call(serializedScope.state, key);
|
|
1535
|
+
stateRefs[key] = ref(hasValue ? serializedScope.state[key] : factory?.());
|
|
1536
|
+
}
|
|
1537
|
+
return stateRefs[key];
|
|
1538
|
+
},
|
|
1067
1539
|
useAsyncData(key, handler) {
|
|
1068
1540
|
if (!asyncDataRefs[key]) {
|
|
1069
1541
|
const snapshot = serializedScope.asyncData ? serializedScope.asyncData[key] : undefined;
|
|
@@ -1102,10 +1574,10 @@ export function createClientComponent(definition) {
|
|
|
1102
1574
|
return createClientRouter();
|
|
1103
1575
|
},
|
|
1104
1576
|
useHead() {
|
|
1105
|
-
// Head updates are server-rendered
|
|
1577
|
+
// Head updates are server-rendered by Resux.
|
|
1106
1578
|
},
|
|
1107
1579
|
useSeoMeta() {
|
|
1108
|
-
// SEO meta updates are server-rendered
|
|
1580
|
+
// SEO meta updates are server-rendered by Resux.
|
|
1109
1581
|
},
|
|
1110
1582
|
useRuntimeConfig() {
|
|
1111
1583
|
return globalThis.__RESUX__?.config ?? { public: {} };
|
|
@@ -1123,7 +1595,7 @@ export function createClientComponent(definition) {
|
|
|
1123
1595
|
return url;
|
|
1124
1596
|
},
|
|
1125
1597
|
async useFetch(url, init) {
|
|
1126
|
-
return
|
|
1598
|
+
return ref(await setupContext.$fetch(url, init));
|
|
1127
1599
|
},
|
|
1128
1600
|
async $fetch(url, init) {
|
|
1129
1601
|
const response = await fetch(url, init);
|
|
@@ -1204,13 +1676,13 @@ function installResux() {
|
|
|
1204
1676
|
}
|
|
1205
1677
|
|
|
1206
1678
|
function createAsyncDataResource(value, pending = false, error = null) {
|
|
1207
|
-
const data =
|
|
1679
|
+
const data = ref(value);
|
|
1208
1680
|
let completion = Promise.resolve();
|
|
1209
1681
|
const resource = {
|
|
1210
1682
|
data,
|
|
1211
1683
|
value: data,
|
|
1212
|
-
pending:
|
|
1213
|
-
error:
|
|
1684
|
+
pending: ref(pending),
|
|
1685
|
+
error: ref(error),
|
|
1214
1686
|
then(onfulfilled, onrejected) {
|
|
1215
1687
|
return completion.then(() => {
|
|
1216
1688
|
const resolved = {
|
|
@@ -2083,12 +2555,30 @@ function serializeProps(props) {
|
|
|
2083
2555
|
return output;
|
|
2084
2556
|
}
|
|
2085
2557
|
|
|
2086
|
-
function stringifyValue(value) {
|
|
2087
|
-
if (value === null || value === undefined) {
|
|
2088
|
-
return "";
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2558
|
+
function stringifyValue(value) {
|
|
2559
|
+
if (value === null || value === undefined) {
|
|
2560
|
+
return "";
|
|
2561
|
+
}
|
|
2562
|
+
if (typeof value === "string") {
|
|
2563
|
+
return value;
|
|
2564
|
+
}
|
|
2565
|
+
if (Array.isArray(value) || isPlainDisplayObject(value)) {
|
|
2566
|
+
try {
|
|
2567
|
+
return JSON.stringify(value, null, 2);
|
|
2568
|
+
} catch {
|
|
2569
|
+
return String(value);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
return String(value);
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
function isPlainDisplayObject(value) {
|
|
2576
|
+
if (!value || typeof value !== "object") {
|
|
2577
|
+
return false;
|
|
2578
|
+
}
|
|
2579
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2580
|
+
return prototype === Object.prototype || prototype === null;
|
|
2581
|
+
}
|
|
2092
2582
|
|
|
2093
2583
|
function stringifyAttributeValue(name, value) {
|
|
2094
2584
|
if (name === "class") {
|
|
@@ -2320,8 +2810,26 @@ function stringifyValue(value) {
|
|
|
2320
2810
|
if (value === null || value === undefined) {
|
|
2321
2811
|
return "";
|
|
2322
2812
|
}
|
|
2813
|
+
if (typeof value === "string") {
|
|
2814
|
+
return value;
|
|
2815
|
+
}
|
|
2816
|
+
if (Array.isArray(value) || isPlainDisplayObject(value)) {
|
|
2817
|
+
try {
|
|
2818
|
+
return JSON.stringify(value, null, 2);
|
|
2819
|
+
}
|
|
2820
|
+
catch {
|
|
2821
|
+
return String(value);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2323
2824
|
return String(value);
|
|
2324
2825
|
}
|
|
2826
|
+
function isPlainDisplayObject(value) {
|
|
2827
|
+
if (!value || typeof value !== "object") {
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2831
|
+
return prototype === Object.prototype || prototype === null;
|
|
2832
|
+
}
|
|
2325
2833
|
function stringifyAttributeValue(name, value) {
|
|
2326
2834
|
if (name === "class") {
|
|
2327
2835
|
return stringifyClassValue(value);
|