q9
This commit is contained in:
43
node_modules/alien-signals/cjs/unstable/computedArray.js
generated
vendored
Normal file
43
node_modules/alien-signals/cjs/unstable/computedArray.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.computedArray = computedArray;
|
||||
const index_js_1 = require("../index.js");
|
||||
function computedArray(arr, getGetter) {
|
||||
const length = (0, index_js_1.computed)(() => arr.get().length);
|
||||
const keys = (0, index_js_1.computed)(() => {
|
||||
const keys = [];
|
||||
for (let i = 0; i < length.get(); i++) {
|
||||
keys.push(String(i));
|
||||
}
|
||||
return keys;
|
||||
});
|
||||
const items = (0, index_js_1.computed)((array) => {
|
||||
array ??= [];
|
||||
while (array.length < length.get()) {
|
||||
const index = array.length;
|
||||
const item = (0, index_js_1.computed)(() => arr.get()[index]);
|
||||
array.push((0, index_js_1.computed)(getGetter(item, index)));
|
||||
}
|
||||
if (array.length > length.get()) {
|
||||
array.length = length.get();
|
||||
}
|
||||
return array;
|
||||
});
|
||||
return new Proxy({}, {
|
||||
get(_, p, receiver) {
|
||||
if (p === 'length') {
|
||||
return length.get();
|
||||
}
|
||||
if (typeof p === 'string' && !isNaN(Number(p))) {
|
||||
return items.get()[Number(p)]?.get();
|
||||
}
|
||||
return Reflect.get(items.get(), p, receiver);
|
||||
},
|
||||
has(_, p) {
|
||||
return Reflect.has(items.get(), p);
|
||||
},
|
||||
ownKeys() {
|
||||
return keys.get();
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user