Comments (3)
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.
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.
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)
- TurboModule for android is always null HOT 9
- Fabric for android causes import error in MainComponentsRegistry.cpp
- Converting TurboModule file to kotlin throws error HOT 3
- Codegen issue while trying to create a fabric component HOT 2
- How to generate codegen for multiple spec files in android? HOT 3
- Codegen header file for iOS has to be manually added to iOS project lead to CI/CD errors HOT 2
- How to do codegen for iOS if we have both TurboModules and Fabric in our project? HOT 5
- How to do event handling for android and iOS in react native's new architecture for fabric components? HOT 2
- Is there a way to use `CodegenTypes` in ts files ? HOT 1
- turbomodule migration not using codegen-ed code? HOT 2
- include could not find load file: ImportHermesc.cmake HOT 2
- Can't pass gradle build on Windows HOT 3
- Getting high ms IOS simulator HOT 1
- Unable to build for android HOT 1
- Tried to follow iOS steps, app just crashes on start HOT 3
- fatal error: 'answersolver.h' file not found HOT 7
- clang++: error: linker command failed with exit code 1 (use -v to see invocation) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rnnewarchitectureapp.