mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Simplify initialization of editable attributes for clarity
Instead of cramming all the steps for correct deep cloning, I split the implementation into 4 distinct steps: - define they keys to exclude - filtering the keys - reduce filtered keys into an object - returning a writable deep clone
This commit is contained in:
+23
-19
@@ -22,25 +22,29 @@
|
||||
const documentId = $page.params.document;
|
||||
const editing = true;
|
||||
|
||||
const work = writable(
|
||||
deepClone(
|
||||
Object.keys($doc)
|
||||
.filter((key) => {
|
||||
return ![
|
||||
'$id',
|
||||
'$collection',
|
||||
'$collectionId',
|
||||
'$databaseId',
|
||||
'$createdAt',
|
||||
'$updatedAt'
|
||||
].includes(key);
|
||||
})
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = $doc[key];
|
||||
return obj;
|
||||
}, {}) as Models.Document
|
||||
)
|
||||
);
|
||||
function initWork() {
|
||||
const prohibitedKeys = [
|
||||
'$id',
|
||||
'$collection',
|
||||
'$collectionId',
|
||||
'$databaseId',
|
||||
'$createdAt',
|
||||
'$updatedAt'
|
||||
];
|
||||
|
||||
const filteredKeys = Object.keys($doc).filter((key) => {
|
||||
return !prohibitedKeys.includes(key);
|
||||
});
|
||||
|
||||
const result = filteredKeys.reduce((obj, key) => {
|
||||
obj[key] = $doc[key];
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return writable(deepClone(result as Models.Document));
|
||||
}
|
||||
|
||||
const work = initWork();
|
||||
|
||||
async function updateData() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user