Giter Site home page Giter Site logo

Comments (6)

neildhar avatar neildhar commented on August 30, 2024

Hey @AndyBrown91, have you considered using an ordinary JavaScript function instead of a jsi::HostObject? You can populate your accessors as getters/setters on the function. Note that these getters or setters could be jsi::HostFunctions that update state on the native side associated with the object.

If you need to store data on the native side, you can attach a jsi::NativeState to any JS object (including functions), and access it from your HostFunctions. In general, keeping properties you want to use from JS directly in JS, instead of accessing them through HostObjects is preferable, since accessing JS properties is much more efficient, and reduces the risk of creating uncollectable cycles through jsi::Values.

from hermes.

AndyBrown91 avatar AndyBrown91 commented on August 30, 2024

Thanks so much for your reply @neildhar

I'm not able to see a way to link a jsi::HostFunction with those property semantics though. Am I missing something?
I felt like the HostObject was the only way to map a C++ getter to a whatever.myprop

The reason why I ask for this stuff is to ensure that it will match the semantics for your linked classes if you use a different JS engine

Maybes there is some magic JS stuff that I have missed for mapping property getters to functions within JS?

from hermes.

neildhar avatar neildhar commented on August 30, 2024

You can use Object.defineProperty to set an arbitrary function (including a HostFunction) as a getter. Loosely, Object.defineProperty(whatever, "myprop", {get: myHF, ...<other flags>}).

from hermes.

AndyBrown91 avatar AndyBrown91 commented on August 30, 2024

Was just in the process of editing the above, thanks for pointing that out. I'll absolutely give that a go
Really appreciate you helping me reframe the issue

from hermes.

mikehuebner avatar mikehuebner commented on August 30, 2024

Just chiming in on this, noticed that typeof function is returning object only within production builds.

from hermes.

neildhar avatar neildhar commented on August 30, 2024

@mikehuebner have you observed a bug with Hermes in typeof? Could you open a new issue with the details and a minimal repro?

from hermes.

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.