Skip to content

Component.for(data) makes it hard to use data #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WebReflection opened this issue Apr 4, 2018 · 3 comments
Closed

Component.for(data) makes it hard to use data #216

WebReflection opened this issue Apr 4, 2018 · 3 comments

Comments

@WebReflection
Copy link
Owner

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
WebReflection pushed a commit that referenced this issue Apr 4, 2018
In order to improve the situation described in #216
the `Component.for(item)` now passes the `item` along
when the new component is created (only the first time).

This makes users able to define their components
in ways compatible with both patterns so that
`new Component(data)` and `Component.for(data)`
would pass data around when/if necessary,
leaving to developers the choice on how/if store
such data internally or not.
@WebReflection
Copy link
Owner Author

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

WebReflection pushed a commit that referenced this issue Apr 4, 2018
In order to improve the situation described in #216
the `Component.for(item)` now passes the `item` along
when the new component is created (only the first time).

This makes users able to define their components
in ways compatible with both patterns so that
`new Component(data)` and `Component.for(data)`
would pass data around when/if necessary,
leaving to developers the choice on how/if store
such data internally or not.
WebReflection pushed a commit that referenced this issue Apr 4, 2018
In order to improve the situation described in #216
the `Component.for(item)` now passes the `item` along
when the new component is created (only the first time).

This makes users able to define their components
in ways compatible with both patterns so that
`new Component(data)` and `Component.for(data)`
would pass data around when/if necessary,
leaving to developers the choice on how/if store
such data internally or not.
WebReflection pushed a commit that referenced this issue Apr 4, 2018
In order to improve the situation described in #216
the `Component.for(item)` now passes the `item` along
when the new component is created (only the first time).

This makes users able to define their components
in ways compatible with both patterns so that
`new Component(data)` and `Component.for(data)`
would pass data around when/if necessary,
leaving to developers the choice on how/if store
such data internally or not.
WebReflection pushed a commit that referenced this issue Apr 4, 2018
In order to improve the situation described in #216
the `Component.for(item)` now passes the `item` along
when the new component is created (only the first time).

This makes users able to define their components
in ways compatible with both patterns so that
`new Component(data)` and `Component.for(data)`
would pass data around when/if necessary,
leaving to developers the choice on how/if store
such data internally or not.
@WebReflection
Copy link
Owner Author

Updated viperHTML too.

@jaschaio
Copy link

jaschaio commented May 30, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants