COMMUNITY

[Solved] Global object dependency in coconut

Hi,

have question regarding coconut framework, maybe @back2dos or @kevinresol have some idea on this. I am trying to write coconut backend for framework where all views need access to root object in the constructor, sort of main object. What would be best way to solve such dependency ? In react there is context api where you can provide from the root some global dependencies.

Any ideas?

Thank you

There’s the @:implicit meta which is more or less equivalent to react context

Thank you @kevinresol will take a look

Yup, as Kevin said @:implicit would do the trick, although if it’s for backend framework specific stuff, it’s probably not the best way to go.

If this is based on coconut.diffing, then your implementation of cursor/applicator can probably take care of this in a simpler and more lightweight way.

@back2dos thank you will try to think how to initialise and pass that object through cursor, and will try to hide attribute from views

@back2dos finally got back to this, are there any example how to pass global dependency to cursor so it can be used as attribute, this framework what I use have global dependency for each visual element that need to be passed in constructor, idea was to remove it from attribute list and then manually add it inside backend

Mhhh, hard to tell. Is there any chance I could see the code you have so far? ^^

@back2dos sure will clean up a bit as just copied other backend as example, but in short
I have global object (WebglRenderingContext), thats is necessary for any view,

example new Node(context, props), would like to hide this context from user as it can / need to be created at init and then passed down for each view, ideally would like to have something like this

<Node position={[0, 0, 0]} /> and then that constructor context attribute could be populated from backend side. Not sure if its even possible but would like to find some solution.

Ok checked similar libs out there, most for them react based and they use context / hooks to share that webgl object

Somehow my post with current status got lost from here, so one more time :slight_smile:

Ah, cool. Will check it out over the weekend :wink:

@back2dos thank you

@back2dos thank you for your help works like charm now for the gl.

No encountered some error Transform is not suitable as a hxx tag, because it accepts no arguments

as I understand it comes from coconut lib, any reasons why there is such check?

got from use-case where wanted to add multiple component so needed a wrapper around

<Transform>
	<BoxMesh />
	<BoxMesh />
</Transform>

ok I think I got why error is thrown, need to add public attributes as right now only constructor attributes are added