Skip to content

Decide on design for (and implement?) TrackedObject constructor #318

@chriskrycho

Description

@chriskrycho

Note: we can't actually start on this yet because Framework still needs to figure out what the semantics should be for it!

The simplest idea, “match the built-in constructors exactly” can have some weird effects:

let original = { foo: true };
let viaObject = new Object(original);
let viaTrackedObject = new TrackedObject(original);

original.foo = false;
console.log(viaObject.foo); // `false`
console.log(viaTrackedObject); // ???

viaTrackedObject.foo = true;
console.log(original.foo); // ???
console.log(viaObject.foo); // ???
  • We cannot actually intercept the set on original.foo, at least with the existing Proxy-based implementation, so if we return the (proxied) original we end up with cases where the object is sometimes mutated in a non-tracked fashion and sometimes mutated in a tracked fashion
  • If we directly walk and install setters for all (own?) properties instead, that probably works but needs to be very carefully documented and very carefully implemented

Additionally, we cannot ever make new TrackedObject() return the desired type from a TypeScript point-of-view.


Related: #73.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions