Skip to content

Commit

Permalink
refactor(array): update
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Jan 13, 2025
1 parent 2cac9ec commit 0967533
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
24 changes: 9 additions & 15 deletions src/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,20 @@ const proxyHandler: ProxyHandler<ProxyDraft> = {
target.type === DraftType.Array &&
proxyArrayMethods.includes(key as string)
) {
const handleItem = (item: any) => {
if (!isDraftable(item)) return item;
ensureShallowCopy(target);
const draft = createDraft({
original: item,
parentDraft: target,
key: undefined,
finalities: target.finalities,
options: target.options,
});
// TODO: support for custom shallow copy function
return draft;
};
return function (this: any, ...args: any[]) {
let returnValue: any;
arrayHandling = true;
try {
returnValue = value.apply(this, args);
if (typeof returnValue === 'object') {
returnValue = handleItem(returnValue);
if (isDraftable(returnValue)) {
returnValue = createDraft({
original: returnValue,
parentDraft: target,
key: undefined,
finalities: target.finalities,
options: target.options,
});
// TODO: support for custom shallow copy function;
}
return returnValue;
} finally {
Expand Down
Loading

0 comments on commit 0967533

Please sign in to comment.