Skip to content

Commit

Permalink
Merge pull request #126 from unyt-org/pointer-fixes
Browse files Browse the repository at this point in the history
Pointer Fixes
  • Loading branch information
jonasstrehle authored Jul 17, 2024
2 parents c11c4e5 + e7ed3ff commit bb6be81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3887,7 +3887,12 @@ export class Pointer<T = any> extends Ref<T> {
if (is_array && Number(prop)+1==obj.length) Runtime.runtime_actions.trimArray(obj)

return true
}
},
ownKeys: (target) => {
// assume that the whole object should be observed for transform
this.handleBeforeNonReferencableGet();
return Reflect.ownKeys(target);
},
});

// set right 'this' context for getters / setters
Expand Down
6 changes: 4 additions & 2 deletions types/native_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,17 @@ Type.std.Set.setJSInterface({
create_proxy: (value:Set<any>, pointer:Pointer) => {
// override methods
Object.defineProperty(value, "add", {value: el => {
return pointer.handleAdd(el);
if (value.has(el)) return false;
return pointer.handleAdd(el); // TODO: return the Set
}, writable:false, enumerable:false});

Object.defineProperty(value, "clear", {value: () => {
return pointer.handleClear();
}, writable:false, enumerable:false});

Object.defineProperty(value, "delete", {value: el => {
return pointer.handleRemove(el);
if (!value.has(el)) return false;
return pointer.handleRemove(el); // TODO: return the Set
}, writable:false, enumerable:false});

/**** override getters to trigger handleBeforeValueGet(): ****/
Expand Down

0 comments on commit bb6be81

Please sign in to comment.