Hyperhtml: Component.for(data) makes it hard to use data

Created on 4 Apr 2018  路  3Comments  路  Source: WebReflection/hyperHTML

While answering this StackOverflow post I've realized that Component.for(item) makes the usage of item itself impossible if not through a redundant Component.for(item).update(item) as pattern suggested when Component.for was introduced.

It would be probably very handy/awesome to be able to get back the context/object used to create the component, so that internally one could retrieve data via this.owner.id, as example.

TODO

  • avoid any memory leak through cross referenced components/contexts
  • think about an accessor name that makes sense (i.e. owner is misleading)
  • write documentation about Component.for 'cause it's fully missing everywhere
enhancement

Most helpful comment

@WebReflection thanks a lot for including this. I was banging my head for hours on how to pass a redux store from one component to another. Than I found this issue. Than I noticed that I was still using hyperhtml:2.6.0 where the context wasn't passed to the newly created Component when using .for(). I just updated to the latest version and now it works flawlessly.

You are doing incredible work here. I feel that you anticipated my problem before I even had it 馃槀

All 3 comments

Addressing the TODOs since it was straight forward to improve the pattern:

  • let the developer decide what to do with the item
  • let the developer decide the name for whatever item it receives (state, owner, data, item)
  • added at least inline comments as documentation. It needs proper follow up in viperhtml.js.org

Updated viperHTML too.

@WebReflection thanks a lot for including this. I was banging my head for hours on how to pass a redux store from one component to another. Than I found this issue. Than I noticed that I was still using hyperhtml:2.6.0 where the context wasn't passed to the newly created Component when using .for(). I just updated to the latest version and now it works flawlessly.

You are doing incredible work here. I feel that you anticipated my problem before I even had it 馃槀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atirip picture atirip  路  6Comments

diodac picture diodac  路  3Comments

dfleury picture dfleury  路  7Comments

bschlenk picture bschlenk  路  3Comments

jaschaio picture jaschaio  路  3Comments