Giter Site home page Giter Site logo

Comments (3)

cipolleschi avatar cipolleschi commented on May 21, 2024

Hi @asfernandes. I don't think that you should do that. Those object are meant to be data object, which only contains data. If you need to provide behaviors, then you should implement that in your Native Module.

To better understand what you are trying to achieve, why the object should have behaviour attached? What's the use case?

from rnnewarchitectureapp.

asfernandes avatar asfernandes commented on May 21, 2024

Why these objects are meant to be data objects?

I solved my problem declaring a function in the spec that returns Object.

In native code this is a jsi::HostObject with methods handled in the object's native get method.

Then I had to force a cast from Object to some interface declared in another TypeScript file.

I cannot understand why it can't be declared correctly in the TypeScript' spec file.

from rnnewarchitectureapp.

cipolleschi avatar cipolleschi commented on May 21, 2024

I cannot understand why it can't be declared correctly in the TypeScript' spec file.

You can declare it correctly in the TypeSpec file. You may have object with behavior, in TypeScript. However, the spec files are used to generate objects in the Native platform code, and we can't generate the behavior.
It would imply that Codegen should be able to read the method body and to translate it in platform code, which is not easy and probably not even worth while.

Your approach works, but you have to give up type safety: in fact you had to cast your object to what you needed. That's is doable but a bit risky, as casting is usually not advisable.

Does it make sense?

What could be done is to have only the interface declared and codegen'd in platform code, but then we would have to create a mechanism to implement the behavior without the risk that codegen override those files.
As you can see, the problem is more complex than what it seems at first sight.

from rnnewarchitectureapp.

Related Issues (18)

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.