Coder Social home page Coder Social logo

Comments (4)

alazier avatar alazier commented on July 30, 2024

I'm not sure this will be possible to do, but at a minimum it would be nice if == worked for all object types even if === does not.

from realm-js.

appden avatar appden commented on July 30, 2024

I'm almost positive there is no way to override == behavior for object comparisons. Do objects inside a Realm have some kind of unique identifier so we could track live objects exposed into a JS context? When I built a JS-ObjC binding, I accomplished this thanks to each object's "unique identifier" being its pointer. 😄

from realm-js.

appden avatar appden commented on July 30, 2024

We discussed last week that this would be possible for objects that have a primary key, since we can use the value of the primary key to track live objects in the JS context. I prototyped this in PR #118, and it works, but doesn't yet support changing the primary key on an object.

I believe this is more than just a "nice to have" since we cannot override == and object hashing like we can in the ObjC and Swift bindings (I know ObjC uses -isEqual, not ==, but that fits with how Cocoa works). Those bindings only support equality for objects with primary keys as well, so I think that a valid enough precedent for the JS binding to work similarly rather than blocking this issue on some future object id support in core.

Adding this would not only benefit us from having a functional == for primary-keyed objects, but would also allow for them to be used with Array.prototype.indexOf (and friends) as well as with Maps and Sets.

from realm-js.

kneth avatar kneth commented on July 30, 2024

We are going to add some kind of unique id in the near future, so we should wait until it has been introduced in core/sync.

from realm-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.