# \[Solved\] Global object dependency in coconut

**URL:** <https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853>\
**Category:** Haxe\
**Tags:** coconut\
**Created:** [January 20, 2021, 8:08pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853 "2021-01-20T20:08:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [January 20, 2021, 8:08pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/1 "2021-01-20T20:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)\
**Post date:** [January 21, 2021, 12:33am UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/2 "2021-01-21T00:33:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [January 21, 2021, 4:45pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/3 "2021-01-21T16:45:47Z")

</div>

Thank you @kevinresol will take a look

---

<div class="post-metadata">

**Author:** ![back2dos](https://community.haxe.org/user_avatar/community.haxe.org/back2dos/32/30_2.png) [@back2dos](https://community.haxe.org/u/back2dos)\
**Post date:** [January 21, 2021, 5:24pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/4 "2021-01-21T17:24:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [January 22, 2021, 8:18am UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/5 "2021-01-22T08:18:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [June 1, 2021, 7:14pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/6 "2021-06-01T19:14:36Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![back2dos](https://community.haxe.org/user_avatar/community.haxe.org/back2dos/32/30_2.png) [@back2dos](https://community.haxe.org/u/back2dos)\
**Post date:** [June 2, 2021, 5:22am UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/7 "2021-06-02T05:22:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [June 2, 2021, 4:43pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/8 "2021-06-02T16:43:49Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [June 2, 2021, 6:11pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/9 "2021-06-02T18:11:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [June 16, 2021, 2:48pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/10 "2021-06-16T14:48:28Z")

</div>

Somehow my post with current status got lost from here, so one more [time](https://github.com/hansagames/coconut.ogl) 🙂

---

<div class="post-metadata">

**Author:** ![back2dos](https://community.haxe.org/user_avatar/community.haxe.org/back2dos/32/30_2.png) [@back2dos](https://community.haxe.org/u/back2dos)\
**Post date:** [June 17, 2021, 7:25am UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/11 "2021-06-17T07:25:28Z")

</div>

Ah, cool. Will check it out over the weekend 😉

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [June 28, 2021, 12:50pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/12 "2021-06-28T12:50:42Z")

</div>

@back2dos thank you

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [July 7, 2021, 6:32pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/13 "2021-07-07T18:32:09Z")

</div>

@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

```haxe
<Transform>
	<BoxMesh />
	<BoxMesh />
</Transform>

```

---

<div class="post-metadata">

**Author:** ![Hersir](https://community.haxe.org/user_avatar/community.haxe.org/hersir/32/151_2.png) [@Hersir](https://community.haxe.org/u/Hersir)\
**Post date:** [July 7, 2021, 6:42pm UTC](https://community.haxe.org/t/solved-global-object-dependency-in-coconut/2853/14 "2021-07-07T18:42:03Z")

</div>

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