Skip to content
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

Idea for window/document listeners, and possibly context/state #408

Open
ashaffer opened this issue Feb 19, 2016 · 0 comments
Open

Idea for window/document listeners, and possibly context/state #408

ashaffer opened this issue Feb 19, 2016 · 0 comments

Comments

@ashaffer
Copy link

I was thinking about binding listeners to window/document/body, which right now kind of sucks. You have to wire that up outside of your component system, track the handler yourself, remove it when you're destroyed, etc. It's a hassle, and as far as I can tell, there's no reason we can't just re-use the normal declarative syntax for these as well, by leveraging special components, e.g.:

import {Body} from 'deku'

function Dropdown () {
  return (
    <Body onClick={close}>
      <div>{children}</div>
    </Body>
  )
}

Similarly with other types of events. popstate, resize, etc. I've implemented these ideas in vdux like this for an idea of how this could work. This cleans up code that needs to do these things enormously, and maybe most importantly decouples them from effect management systems, which makes components more portable and reusable. Not to mention that it just generally limits the number of abstractions to be learned and considered.

I think you can also use this pattern for other types of effectful things, like context/state (similarly to react-redux's Provide component).

Thoughts?

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

No branches or pull requests

1 participant